Skip to content

Commit

Permalink
Merge pull request #78 from hdykokd/issue-68
Browse files Browse the repository at this point in the history
feat: support native tab icons
  • Loading branch information
hdykokd authored Apr 17, 2024
2 parents 76b6a1f + 649a824 commit a58612c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/components/Tabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@
tabIcon.removeClass('_hidden');
}
if (!settings.customizeTabIcon) {
// @ts-expect-error
const _leaf = plugin.app.workspace.getLeafById(leaf.id)
const iconEl = _leaf.tabHeaderInnerIconEl.firstChild.cloneNode(true)
if (!iconEl) return;
if (iconEl) {
tabIcon.setChildrenInPlace([iconEl])
return
}
}
const matchedConfig = getMatchedTabIconConfig(
tabIconRules,
getDirname(leaf),
Expand Down
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default class VerticalTabsView extends Plugin {
}

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
const currentSettings = await this.loadData();
this.settings = Object.assign({}, DEFAULT_SETTINGS, currentSettings);

// migrate
if (
Expand All @@ -36,6 +37,11 @@ export default class VerticalTabsView extends Plugin {
delete this.settings.tabIconConfigs;
this.saveSettings(this.settings);
}

// backward compatibility
if (!('customizeTabIcon' in currentSettings) && currentSettings.tabIconRules.length > 0) {
this.settings.customizeTabIcon = true;
}
}

async saveSettings(settings: VerticalTabsViewSettings) {
Expand Down
10 changes: 9 additions & 1 deletion src/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface VerticalTabsViewSettings {
showPinnedIcon: boolean;
showPinIconIfNotPinned: boolean;
showTabIcon: boolean;
customizeTabIcon: boolean;
defaultTabIcon: string;
tabIconRules: TabIconRule[];
// deprecated
Expand All @@ -24,6 +25,7 @@ export const DEFAULT_SETTINGS: VerticalTabsViewSettings = {
showPinnedIcon: true,
showPinIconIfNotPinned: true,
showTabIcon: true,
customizeTabIcon: false,
defaultTabIcon: 'file',
tabIconRules: [],
};
Expand Down Expand Up @@ -82,8 +84,14 @@ export class VerticalTabsViewSettingTab extends PluginSettingTab {
this.display();
});

createToggle(containerEl, 'Customize tab icon', '', this.settings.customizeTabIcon, (value) => {
this.settings.customizeTabIcon = value;
this.save();
this.display();
});

// tab icon per condition
if (this.settings.showTabIcon) {
if (this.settings.customizeTabIcon) {
// default icon
const { previewIconWrapper, previewIcon, previewIconText } = this.createPreviewIcon(this.settings.defaultTabIcon);

Expand Down

0 comments on commit a58612c

Please sign in to comment.