-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwap Enter.js
43 lines (36 loc) · 1.3 KB
/
Swap Enter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// swap "enter" and "shift + enter"
class ChangeConfigWidget extends api.NoteContextAwareWidget {
get parentWidget() { return "left-pane"; }
doRender() {
this.$widget = $("");
this.editorIntervalId = null;
this.initializedEditorIds = [];
}
refreshWithNote() {
if (this.note.type === "text") {
this.initializeEditor();
}
}
initializeEditor() {
this.editorIntervalId = setInterval(async () => {
const editor = await api.getActiveContextTextEditor();
clearInterval(this.editorIntervalId);
if (this.initializedEditorIds.includes(editor.id)) {
return;
}
this.initializedEditorIds.push(editor.id);
editor.editing.view.document.on( 'enter', ( evt, data ) => {
data.preventDefault();
evt.stop();
if ( data.isSoft ) {
editor.execute( 'enter' );
editor.editing.view.scrollToTheSelection();
return;
}
editor.execute( 'shiftEnter' );
editor.editing.view.scrollToTheSelection();
}, { priority: 'high' } );
}, 1000);
}
}
module.exports = new ChangeConfigWidget();