Skip to content

Commit 1129708

Browse files
Copilotmikebarkmin
andcommitted
Fix show source command to work with custom editors
- Check workspace.textDocuments for open .learningmap files when no active text editor - Fall back to visible text editors if available - Properly handle the case when custom editor is active (no activeTextEditor) - Improved error message clarity Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
1 parent 26ba86a commit 1129708

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

platforms/vscode/src/extension.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,31 @@ export function activate(context: vscode.ExtensionContext) {
7676
// Register command to show source
7777
context.subscriptions.push(
7878
vscode.commands.registerCommand('learningmap.showSource', async () => {
79-
const activeEditor = vscode.window.activeTextEditor;
80-
if (!activeEditor) {
81-
vscode.window.showErrorMessage('No active learningmap file');
79+
// Try to get the active text editor first
80+
let uri = vscode.window.activeTextEditor?.document.uri;
81+
82+
// If no active text editor, check visible text editors
83+
if (!uri && vscode.window.visibleTextEditors.length > 0) {
84+
uri = vscode.window.visibleTextEditors[0].document.uri;
85+
}
86+
87+
// If still no URI, try to find an open learningmap document
88+
if (!uri) {
89+
const learningmapDocs = vscode.workspace.textDocuments.filter(
90+
doc => doc.uri.path.endsWith('.learningmap')
91+
);
92+
if (learningmapDocs.length > 0) {
93+
uri = learningmapDocs[0].uri;
94+
}
95+
}
96+
97+
// If we still don't have a URI, show an error
98+
if (!uri) {
99+
vscode.window.showErrorMessage('No learningmap file is currently open');
82100
return;
83101
}
84-
85-
const uri = activeEditor.document.uri;
102+
103+
// Verify it's a learningmap file
86104
if (!uri.path.endsWith('.learningmap')) {
87105
vscode.window.showErrorMessage('Active file is not a learningmap file');
88106
return;

0 commit comments

Comments
 (0)