|
13 | 13 | * |
14 | 14 | */ |
15 | 15 |
|
16 | | - |
17 | 16 | import * as vscode from "vscode"; |
18 | 17 | import debounce from "lodash.debounce"; |
19 | 18 |
|
@@ -41,41 +40,31 @@ export function activateContextKeySetter( |
41 | 40 | context.subscriptions |
42 | 41 | ); |
43 | 42 |
|
44 | | - // set context keys when visible text editors change |
45 | | - vscode.window.onDidChangeVisibleTextEditors( |
46 | | - (_editors) => { |
47 | | - triggerUpdateContextKeys(engine); |
| 43 | + // set context keys when active text editor changes |
| 44 | + vscode.window.onDidChangeActiveTextEditor( |
| 45 | + (editor) => { |
| 46 | + if (editor) { |
| 47 | + setContextKeys(editor, engine); |
| 48 | + } |
48 | 49 | }, |
49 | 50 | null, |
50 | 51 | context.subscriptions |
51 | 52 | ); |
52 | 53 |
|
53 | | - // set context keys on changes to the document (if its visible) |
| 54 | + // set context keys on changes to the document (if it's active) |
54 | 55 | vscode.workspace.onDidChangeTextDocument( |
55 | 56 | (event) => { |
56 | | - const visibleEditor = vscode.window.visibleTextEditors.find(editor => { |
57 | | - return editor.document.uri.toString() === event.document.uri.toString(); |
58 | | - }); |
59 | | - if (visibleEditor) { |
| 57 | + const activeEditor = vscode.window.activeTextEditor; |
| 58 | + if (activeEditor) { |
60 | 59 | debounce( |
61 | | - () => setContextKeys(visibleEditor, engine), |
| 60 | + () => setContextKeys(activeEditor, engine), |
62 | 61 | debounceOnDidChangeDocumentMs |
63 | 62 | )(); |
64 | 63 | } |
65 | 64 | }, |
66 | 65 | null, |
67 | 66 | context.subscriptions |
68 | 67 | ); |
69 | | - |
70 | | - // set context keys at activation time |
71 | | - triggerUpdateContextKeys(engine); |
72 | | - |
73 | | -} |
74 | | - |
75 | | -function triggerUpdateContextKeys(engine: MarkdownEngine) { |
76 | | - for (const editor of vscode.window.visibleTextEditors) { |
77 | | - setContextKeys(editor, engine); |
78 | | - } |
79 | 68 | } |
80 | 69 |
|
81 | 70 | function setContextKeys(editor: vscode.TextEditor, engine: MarkdownEngine) { |
|
0 commit comments