Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support native tab icons #78

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading