Skip to content

Commit 2be82aa

Browse files
jsonifyclaude
andauthored
Fix: Add double-click support for persistent note tabs (#127)
* Fix: Add double-click support for persistent note tabs - Implements double-click detection (300ms threshold) in tree view - Single-click: Opens notes in preview mode (italicized tabs) - Double-click: Opens notes in persistent mode (normal tabs) - Matches standard VS Code file explorer behavior Fixes issue where double-clicking notes had no effect and all notes opened in preview mode only. * Refactor: Improve double-click detection with IIFE closure Code review improvements: - Encapsulate state variables (lastClickedFile, lastClickTime) in IIFE closure - Change 'let' to 'const' for openNote disposable to prevent reassignment - Improves maintainability by avoiding scope pollution - Keeps state tightly coupled with command handler This refactoring maintains the same functionality while improving code quality. --------- Co-authored-by: Claude <[email protected]>
1 parent e8398fa commit 2be82aa

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/extension.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,11 +827,31 @@ export function activate(context: vscode.ExtensionContext) {
827827
}
828828
});
829829

830-
// Command to open note from tree
831-
let openNote = vscode.commands.registerCommand('noted.openNote', async (filePath: string) => {
832-
const document = await vscode.workspace.openTextDocument(filePath);
833-
await vscode.window.showTextDocument(document, { preserveFocus: true });
834-
});
830+
// Command to open note from tree, with double-click detection
831+
const openNote = vscode.commands.registerCommand('noted.openNote', (() => {
832+
let lastClickedFile: string | null = null;
833+
let lastClickTime: number = 0;
834+
const DOUBLE_CLICK_THRESHOLD = 300; // milliseconds
835+
836+
return async (filePath: string) => {
837+
const now = Date.now();
838+
const timeSinceLastClick = now - lastClickTime;
839+
const isDoubleClick = lastClickedFile === filePath && timeSinceLastClick < DOUBLE_CLICK_THRESHOLD;
840+
841+
// Update tracking variables for the next click
842+
lastClickedFile = filePath;
843+
lastClickTime = now;
844+
845+
const document = await vscode.workspace.openTextDocument(filePath);
846+
847+
// Open in persistent mode (non-preview) if double-clicked, otherwise open in preview mode
848+
if (isDoubleClick) {
849+
await vscode.window.showTextDocument(document, { preview: false, preserveFocus: false });
850+
} else {
851+
await vscode.window.showTextDocument(document, { preview: true, preserveFocus: true });
852+
}
853+
};
854+
})());
835855

836856
// Command to create a note from a link (used in hover preview for broken links)
837857
let createNoteFromLink = vscode.commands.registerCommand('noted.createNoteFromLink', async (linkText: string) => {

0 commit comments

Comments
 (0)