Skip to content

Commit

Permalink
Merge pull request #2 from nicosomb/add-width-setting
Browse files Browse the repository at this point in the history
Add a new setting to define tab width
  • Loading branch information
nicosomb authored Jul 15, 2024
2 parents 77d4008 + 02655b8 commit 4650a4b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
20 changes: 20 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { App, Plugin, PluginSettingTab, Setting } from 'obsidian';

interface ShrinkPinnedTabsSettings {
hideTitle: boolean;
tabWidth: number;
}

const DEFAULT_SETTINGS: ShrinkPinnedTabsSettings = {
hideTitle: false,
tabWidth: 60,
}

export default class ShrinkPinnedTabs extends Plugin {
Expand All @@ -32,6 +34,7 @@ export default class ShrinkPinnedTabs extends Plugin {

onunload() {
console.log('Unloading Shrink pinned tabs plugin');
this.updateStyle()
}

async loadSettings() {
Expand All @@ -46,13 +49,15 @@ export default class ShrinkPinnedTabs extends Plugin {

// update the styles (at the start, or as the result of a settings change)
updateStyle = () => {
console.log('Update style');
const tabs = document.querySelectorAll('.workspace-tab-header:has(.mod-pinned)');
if (tabs != null) {
for (var i = 0; i < tabs.length; i++) {
const title = (tabs[i].querySelectorAll('.workspace-tab-header-inner-title'));
if (title != null) {
title[0].toggleClass('mod-pinned-hide', this.settings.hideTitle);
}
tabs[i].style.width = this.settings.tabWidth + 'px';

Check failure on line 60 in main.ts

View workflow job for this annotation

GitHub Actions / build

Property 'style' does not exist on type 'Element'.
}
}
}
Expand Down Expand Up @@ -81,5 +86,20 @@ class ShrinkPinnedTabsSettingTab extends PluginSettingTab {
this.plugin.refresh();
})
);

new Setting(containerEl)
.setName('Width tab')
.setDesc('Defines the width tab when shrinked')
.addSlider((text) =>
text
.setLimits(0, 160, 10)
.setValue(this.plugin.settings.tabWidth)
.setDynamicTooltip()
.onChange((value) => {
this.plugin.settings.tabWidth = value;
this.plugin.saveData(this.plugin.settings);
this.plugin.refresh();
})
);
}
}
5 changes: 0 additions & 5 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
.workspace-tab-header:has(.mod-pinned) {
/* shrink if pinned */
max-width: 80px !important;
}

/* class to hide tab title */
.mod-pinned-hide {
display: none;
Expand Down

0 comments on commit 4650a4b

Please sign in to comment.