feat: support Excalidraw tabs in ColorTab

This commit is contained in:
rordaz 2026-06-23 13:48:12 -05:00
parent 186a5f285f
commit 1e7d2428bb
4 changed files with 72 additions and 5 deletions

45
RELEASE_NOTES.md Normal file
View file

@ -0,0 +1,45 @@
# Release Notes
## [1.1.1] - 2026-06-22
### 🐛 Fixes
- **Tab Closing on Duplicate Prevention** Fixed bug where Prevent Tab Duplication was closing sidebar views and local graphs
- Sidebar panels (Outline, File Properties, Backlinks) no longer affected
- Local graph, graph, and other auxiliary views now properly excluded
- Only actual document tabs (markdown/file views) are now colored and managed
---
## [1.1.0] - 2026-06-19
### ✨ Features
- **Prevent Tab Duplication** New settings toggle to prevent opening duplicate tabs of the same file
- When enabled, opening an already-open file will focus on the existing tab instead of creating a duplicate
- Particularly useful for maintaining clean workspace organization alongside colored tabs
### 🐛 Fixes
- **Settings UI Fallback** Added robust fallback renderer for older Obsidian versions
- Ensures settings page renders correctly across all Obsidian versions ≥ 1.13.0
- Fixes blank settings page issue on environments that don't consume the new settings API
### 📚 Documentation
- Updated README with "Prevent Tab Duplication" setting description
---
## [1.0.4] - 2026-06-15
### ✨ Features
- Initial stable release with core Color Tab functionality
### 📋 Previous Changes (1.0.0 1.0.3)
- Tab coloring with customizable color palette
- Auto-pin colored tabs support
- Popout window support
- Settings UI with live preview

28
main.ts
View file

@ -48,6 +48,15 @@ export default class ColorTabPlugin extends Plugin {
"file-menu",
(menu, _file, source, leaf) => {
if (source !== "tab-header" || !leaf) return;
console.log("[ColorTab DEBUG]", {
source,
filePath: this.getFilePath(leaf),
viewType: leaf.getViewState().type,
isColorable: this.isColorableLeaf(leaf),
root: leaf.getRoot(),
wsLeftSplit: (this.app.workspace as unknown as { leftSplit: unknown }).leftSplit,
wsRightSplit: (this.app.workspace as unknown as { rightSplit: unknown }).rightSplit,
});
this.addColorMenuItems(menu, leaf);
}
)
@ -243,8 +252,11 @@ export default class ColorTabPlugin extends Plugin {
private handleDuplicateTabs() {
const filePathMap = new Map<string, WorkspaceLeaf[]>();
// Build a map of file paths to their corresponding leaves
// Build a map of file paths to their corresponding document leaves only.
// Sidebar views (Outline, File Properties, Backlinks, etc.) can be
// file-aware, but are not file document tabs and must never be closed.
this.app.workspace.iterateAllLeaves((leaf) => {
if (!this.isColorableLeaf(leaf)) return;
const path = this.getFilePath(leaf);
if (path) {
if (!filePathMap.has(path)) {
@ -275,9 +287,15 @@ export default class ColorTabPlugin extends Plugin {
// ── Helpers ───────────────────────────────────────────────────────────────
private getFilePath(leaf: WorkspaceLeaf): string | null {
const file = (leaf.view as unknown as { file?: { path: string } })
// Try to get file from view first (most common), then from leaf directly
const fileFromView = (leaf.view as unknown as { file?: { path: string } })
?.file;
return file?.path ?? null;
if (fileFromView?.path) return fileFromView.path;
// Fallback for view types like excalidraw that may store file directly on leaf
const fileFromLeaf = (leaf as unknown as { file?: { path: string } })
?.file;
return fileFromLeaf?.path ?? null;
}
private isColorableLeaf(leaf: WorkspaceLeaf): boolean {
@ -291,6 +309,10 @@ export default class ColorTabPlugin extends Plugin {
rightSplit: unknown;
};
if (root === ws.leftSplit || root === ws.rightSplit) return false;
// Only color markdown/file/excalidraw document tabs, not auxiliary views
// (local graph, graph, properties, etc.)
const viewType = leaf.getViewState().type;
if (viewType !== "markdown" && viewType !== "file" && viewType !== "excalidraw") return false;
return true;
}

View file

@ -1,7 +1,7 @@
{
"id": "color-tab",
"name": "Color Tab",
"version": "1.1.0",
"version": "1.1.1",
"minAppVersion": "1.13.0",
"description": "Colorize open tabs to visually distinguish notes at a glance, using a right-click context menu.",
"author": "Rafael Ordaz",

View file

@ -1,6 +1,6 @@
{
"name": "color-tab",
"version": "1.1.0",
"version": "1.1.1",
"description": "Obsidian plugin to colorize open tabs",
"main": "main.js",
"scripts": {