|
22 | 22 | syntaxTreeDebugContent: null, |
23 | 23 | editor: null, |
24 | 24 | onWindowClose: null, |
| 25 | + onUndo: null, |
| 26 | + onRedo: null, |
| 27 | + onDeleteBlock: null, |
| 28 | + onSelectAll: null, |
25 | 29 | } |
26 | 30 | }, |
27 | 31 |
|
|
39 | 43 | } |
40 | 44 | window.heynote.mainProcess.on(WINDOW_CLOSE_EVENT, this.onWindowClose) |
41 | 45 |
|
42 | | - window.heynote.mainProcess.on(UNDO_EVENT, () => { |
| 46 | + this.onUndo = () => { |
43 | 47 | if (this.editor) { |
44 | 48 | toRaw(this.editor).undo() |
45 | 49 | } |
46 | | - }) |
| 50 | + } |
| 51 | + window.heynote.mainProcess.on(UNDO_EVENT, this.onUndo) |
47 | 52 |
|
48 | | - window.heynote.mainProcess.on(REDO_EVENT, () => { |
| 53 | + this.onRedo = () => { |
49 | 54 | if (this.editor) { |
50 | 55 | toRaw(this.editor).redo() |
51 | 56 | } |
52 | | - }) |
| 57 | + } |
| 58 | + window.heynote.mainProcess.on(REDO_EVENT, this.onRedo) |
53 | 59 | |
54 | | - window.heynote.mainProcess.on(DELETE_BLOCK_EVENT, () => { |
| 60 | + this.onDeleteBlock = () => { |
55 | 61 | if (this.editor) { |
56 | 62 | toRaw(this.editor).deleteActiveBlock() |
57 | 63 | } |
58 | | - }) |
| 64 | + } |
| 65 | + window.heynote.mainProcess.on(DELETE_BLOCK_EVENT, this.onDeleteBlock) |
59 | 66 |
|
60 | | - window.heynote.mainProcess.on(SELECT_ALL_EVENT, () => { |
| 67 | + this.onSelectAll = () => { |
61 | 68 | 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 | + } |
63 | 73 | } |
64 | | - }) |
| 74 | + } |
| 75 | + window.heynote.mainProcess.on(SELECT_ALL_EVENT, this.onSelectAll) |
65 | 76 |
|
66 | 77 | // if debugSyntaxTree prop is set, display syntax tree for debugging |
67 | 78 | if (this.debugSyntaxTree) { |
|
85 | 96 |
|
86 | 97 | beforeUnmount() { |
87 | 98 | 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) |
92 | 103 | this.editorCacheStore.tearDown(); |
93 | 104 | }, |
94 | 105 |
|
|
0 commit comments