Skip to content

Commit 94bb126

Browse files
committed
Tune status bar length
1 parent 657123e commit 94bb126

File tree

3 files changed

+64
-9
lines changed

3 files changed

+64
-9
lines changed

src/main.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,22 +1034,51 @@ export default class Main extends Plugin {
10341034
}
10351035
}
10361036

1037+
/**
1038+
* Truncates a filename to the specified maximum length,
1039+
* adding an ellipsis if truncated
1040+
* @param filename The filename to truncate
1041+
* @param maxLength Maximum length before truncation
1042+
* @returns Truncated filename
1043+
*/
1044+
truncateFilename(filename: string, maxLength: number): string {
1045+
if (filename.length <= maxLength) {
1046+
return filename;
1047+
}
1048+
1049+
// Truncate and add ellipsis
1050+
return filename.slice(0, maxLength) + '…';
1051+
}
1052+
10371053
updateStatusBar() {
10381054
if (!this.statusBarItem) return;
10391055

10401056
// Empty the element but don't remove the event listener
10411057
this.statusBarItem.empty();
10421058

10431059
if (this.selectedCanvas) {
1060+
const truncatedName = this.truncateFilename(
1061+
this.selectedCanvas.basename,
1062+
this.settings.statusBarMaxFilenameLength
1063+
);
1064+
10441065
this.statusBarItem.setText(
1045-
`Canvas: ${this.selectedCanvas.basename}`,
1066+
`Canvas: ${truncatedName}`,
10461067
);
10471068
this.statusBarItem.addClass("has-canvas-selected");
10481069
this.statusBarItem.removeClass("no-canvas-selected");
1070+
1071+
// Add tooltip with the full filename if truncated
1072+
if (truncatedName !== this.selectedCanvas.basename) {
1073+
this.statusBarItem.setAttribute("aria-label", this.selectedCanvas.basename);
1074+
} else {
1075+
this.statusBarItem.removeAttribute("aria-label");
1076+
}
10491077
} else {
10501078
this.statusBarItem.setText("No Canvas selected");
10511079
this.statusBarItem.addClass("no-canvas-selected");
10521080
this.statusBarItem.removeClass("has-canvas-selected");
1081+
this.statusBarItem.removeAttribute("aria-label");
10531082
}
10541083
}
10551084

src/settings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export interface SendToCanvasSettings {
1212
appendTextToOpenTasks: boolean;
1313
openTaskAppendText: string;
1414

15+
// Status bar customization
16+
statusBarMaxFilenameLength: number; // Maximum number of characters to display for Canvas filenames in status bar
17+
1518
// Node size settings
1619
linkNodeWidth: number;
1720
linkNodeHeight: number;
@@ -33,6 +36,9 @@ export const DEFAULT_SETTINGS: SendToCanvasSettings = {
3336
appendTextToOpenTasks: false,
3437
openTaskAppendText: "[l:: #Canvas ]",
3538

39+
// Default status bar customization
40+
statusBarMaxFilenameLength: 20, // Default to 20 characters before truncation
41+
3642
// Default node sizes
3743
linkNodeWidth: 400,
3844
linkNodeHeight: 100,

src/settingsTab.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class SettingsTab extends PluginSettingTab {
1414
const { containerEl } = this;
1515
containerEl.empty();
1616

17-
// General settings
17+
// General
1818
new Setting(containerEl)
1919
.setName("Remember last Canvas")
2020
.setDesc(
@@ -31,7 +31,7 @@ export class SettingsTab extends PluginSettingTab {
3131
}),
3232
);
3333

34-
// Open task settings
34+
// Open task
3535
new Setting(containerEl)
3636
.setName("Open task")
3737
.setDesc(
@@ -70,7 +70,7 @@ export class SettingsTab extends PluginSettingTab {
7070
);
7171
}
7272

73-
// Block ID settings
73+
// Block ID
7474
new Setting(containerEl)
7575
.setName("Block ID")
7676
.setDesc(
@@ -112,7 +112,7 @@ export class SettingsTab extends PluginSettingTab {
112112
);
113113
}
114114

115-
// Link timestamp settings
115+
// Link timestamp
116116
new Setting(containerEl)
117117
.setName("Link timestamp")
118118
.setDesc(
@@ -155,15 +155,15 @@ export class SettingsTab extends PluginSettingTab {
155155
});
156156
}
157157

158-
// Canvas node size settings
158+
// Canvas node size
159159
new Setting(containerEl)
160160
.setName("Canvas node size")
161161
.setDesc(
162162
"Customize the dimensions of nodes created in Canvas files. Default sizes are 400×100 for links, 400×200 for content, and 400×400 for note content.",
163163
)
164164
.setHeading();
165165

166-
// Link and block link node size settings
166+
// Link and block link node size
167167
new Setting(containerEl)
168168
.setName("Link nodes (note links and block links)")
169169
.setDesc("Configure size settings for note links and block links");
@@ -198,7 +198,7 @@ export class SettingsTab extends PluginSettingTab {
198198
}),
199199
);
200200

201-
// Content node size settings (block embeds and plain text)
201+
// Content node size (block embeds and plain text)
202202
new Setting(containerEl)
203203
.setName("Content nodes (block embeds and plain text)")
204204
.setDesc("Configure size settings for block embeds and plain text");
@@ -233,7 +233,7 @@ export class SettingsTab extends PluginSettingTab {
233233
}),
234234
);
235235

236-
// File node size settings (note content)
236+
// File node size (note content)
237237
new Setting(containerEl)
238238
.setName("File nodes (note content)")
239239
.setDesc("Configure size settings for note content");
@@ -267,5 +267,25 @@ export class SettingsTab extends PluginSettingTab {
267267
}
268268
}),
269269
);
270+
271+
// Status bar
272+
new Setting(containerEl)
273+
.setName("Status bar")
274+
.setDesc("Customize the status bar display")
275+
.setHeading();
276+
277+
new Setting(containerEl)
278+
.setName("Maximum Canvas filename length")
279+
.setDesc("Maximum number of characters to display for Canvas filenames in the status bar. Longer filenames will be truncated with an ellipsis.")
280+
.addSlider(slider => slider
281+
.setLimits(5, 50, 5)
282+
.setValue(this.plugin.settings.statusBarMaxFilenameLength)
283+
.setDynamicTooltip()
284+
.onChange(async (value) => {
285+
this.plugin.settings.statusBarMaxFilenameLength = value;
286+
await this.plugin.saveSettings();
287+
this.plugin.updateStatusBar(); // Update immediately to show effect
288+
})
289+
);
270290
}
271291
}

0 commit comments

Comments
 (0)