mirror of
https://github.com/rordaz/ColorTab.git
synced 2026-07-22 07:48:53 +00:00
feat: enhance color tab functionality with colorable leaf checks and auto pinning logic
This commit is contained in:
parent
ca945f266d
commit
c8efb5ff3f
1 changed files with 22 additions and 1 deletions
23
main.ts
23
main.ts
|
|
@ -34,7 +34,7 @@ const DEFAULT_SETTINGS: ColorTabSettings = {
|
|||
};
|
||||
|
||||
export default class ColorTabPlugin extends Plugin {
|
||||
settings: ColorTabSettings;
|
||||
settings!: ColorTabSettings;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
|
|
@ -71,6 +71,8 @@ export default class ColorTabPlugin extends Plugin {
|
|||
// ── Context menu ──────────────────────────────────────────────────────────
|
||||
|
||||
private addColorMenuItems(menu: Menu, leaf: WorkspaceLeaf) {
|
||||
if (!this.isColorableLeaf(leaf)) return;
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
this.settings.colors.forEach(({ name, color }) => {
|
||||
|
|
@ -102,6 +104,8 @@ export default class ColorTabPlugin extends Plugin {
|
|||
// ── Color application ─────────────────────────────────────────────────────
|
||||
|
||||
setTabColor(leaf: WorkspaceLeaf, color: string) {
|
||||
if (!this.isColorableLeaf(leaf)) return;
|
||||
|
||||
const path = this.getFilePath(leaf);
|
||||
if (path) {
|
||||
this.settings.fileColors[path] = color;
|
||||
|
|
@ -114,6 +118,8 @@ export default class ColorTabPlugin extends Plugin {
|
|||
}
|
||||
|
||||
removeTabColor(leaf: WorkspaceLeaf) {
|
||||
if (!this.isColorableLeaf(leaf)) return;
|
||||
|
||||
const path = this.getFilePath(leaf);
|
||||
if (path) {
|
||||
delete this.settings.fileColors[path];
|
||||
|
|
@ -160,11 +166,22 @@ export default class ColorTabPlugin extends Plugin {
|
|||
applyAllColors() {
|
||||
this.app.workspace.iterateAllLeaves((leaf) => {
|
||||
const path = this.getFilePath(leaf);
|
||||
const tabHeader = (
|
||||
leaf as unknown as { tabHeaderEl?: HTMLElement }
|
||||
).tabHeaderEl;
|
||||
const wasAccidentallyColoredNonFileLeaf =
|
||||
!path && !!tabHeader?.classList.contains("color-tab-colored");
|
||||
const color = path ? (this.settings.fileColors[path] ?? null) : null;
|
||||
this.applyColorToLeaf(leaf, color);
|
||||
if (this.settings.autoPinColoredTabs && color) {
|
||||
leaf.setPinned(true);
|
||||
}
|
||||
if (
|
||||
this.settings.autoPinColoredTabs &&
|
||||
wasAccidentallyColoredNonFileLeaf
|
||||
) {
|
||||
leaf.setPinned(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -176,6 +193,10 @@ export default class ColorTabPlugin extends Plugin {
|
|||
return file?.path ?? null;
|
||||
}
|
||||
|
||||
private isColorableLeaf(leaf: WorkspaceLeaf): boolean {
|
||||
return this.getFilePath(leaf) !== null;
|
||||
}
|
||||
|
||||
// ── Settings persistence ──────────────────────────────────────────────────
|
||||
|
||||
async loadSettings() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue