Skip to content

Commit 3f76715

Browse files
committed
Don't perform editor Select All command if the editor isn't focused (e.g. the Settings modal is open).
Fix Editor/Editor Cache teardown/cleanup.
1 parent 15df9e5 commit 3f76715

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/components/Editor.vue

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
syntaxTreeDebugContent: null,
2323
editor: null,
2424
onWindowClose: null,
25+
onUndo: null,
26+
onRedo: null,
27+
onDeleteBlock: null,
28+
onSelectAll: null,
2529
}
2630
},
2731
@@ -39,29 +43,36 @@
3943
}
4044
window.heynote.mainProcess.on(WINDOW_CLOSE_EVENT, this.onWindowClose)
4145
42-
window.heynote.mainProcess.on(UNDO_EVENT, () => {
46+
this.onUndo = () => {
4347
if (this.editor) {
4448
toRaw(this.editor).undo()
4549
}
46-
})
50+
}
51+
window.heynote.mainProcess.on(UNDO_EVENT, this.onUndo)
4752
48-
window.heynote.mainProcess.on(REDO_EVENT, () => {
53+
this.onRedo = () => {
4954
if (this.editor) {
5055
toRaw(this.editor).redo()
5156
}
52-
})
57+
}
58+
window.heynote.mainProcess.on(REDO_EVENT, this.onRedo)
5359
54-
window.heynote.mainProcess.on(DELETE_BLOCK_EVENT, () => {
60+
this.onDeleteBlock = () => {
5561
if (this.editor) {
5662
toRaw(this.editor).deleteActiveBlock()
5763
}
58-
})
64+
}
65+
window.heynote.mainProcess.on(DELETE_BLOCK_EVENT, this.onDeleteBlock)
5966
60-
window.heynote.mainProcess.on(SELECT_ALL_EVENT, () => {
67+
this.onSelectAll = () => {
6168
if (this.editor) {
62-
toRaw(this.editor).selectAll()
69+
// make sure the editor is focused
70+
if (this.$refs.editor.contains(document.activeElement)) {
71+
toRaw(this.editor).selectAll()
72+
}
6373
}
64-
})
74+
}
75+
window.heynote.mainProcess.on(SELECT_ALL_EVENT, this.onSelectAll)
6576
6677
// if debugSyntaxTree prop is set, display syntax tree for debugging
6778
if (this.debugSyntaxTree) {
@@ -85,10 +96,10 @@
8596
8697
beforeUnmount() {
8798
window.heynote.mainProcess.off(WINDOW_CLOSE_EVENT, this.onWindowClose)
88-
window.heynote.mainProcess.off(UNDO_EVENT)
89-
window.heynote.mainProcess.off(REDO_EVENT)
90-
window.heynote.mainProcess.off(DELETE_BLOCK_EVENT)
91-
window.heynote.mainProcess.off(SELECT_ALL_EVENT)
99+
window.heynote.mainProcess.off(UNDO_EVENT, this.onUndo)
100+
window.heynote.mainProcess.off(REDO_EVENT, this.onRedo)
101+
window.heynote.mainProcess.off(DELETE_BLOCK_EVENT, this.onDeleteBlock)
102+
window.heynote.mainProcess.off(SELECT_ALL_EVENT, this.onSelectAll)
92103
this.editorCacheStore.tearDown();
93104
},
94105

src/stores/editor-cache.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ export const useEditorCacheStore = defineStore("editorCache", {
164164
}
165165

166166
window.document.removeEventListener("currenciesLoaded", this.onCurrenciesLoaded)
167+
168+
this.editorCache.lru = []
169+
this.editorCache.cache = {}
167170
},
168171

169172
moveCurrentBlockToOtherEditor(targetPath) {

0 commit comments

Comments
 (0)