qword 1.1.15 → 1.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog +5 -0
- package/client/create.js +1 -1
- package/client/editor.d.ts +1 -1
- package/client/editor.js +1 -1
- package/client/index.d.ts +1 -1
- package/client/index.js +1 -1
- package/client/{options.d.ts → options/options.d.ts} +2 -2
- package/client/{options.js → options/options.js} +6 -1
- package/client/options/vim/keep-indent-after-enter-vim.js +52 -0
- package/dist/qword.js +2 -2
- package/dist/qword.js.map +1 -1
- package/dist-dev/qword.js +16 -7
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/client/create.js
CHANGED
package/client/editor.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
type CreateEditorOptions,
|
|
4
4
|
} from './create.js';
|
|
5
5
|
import type {MarkHandle} from './decorations.js';
|
|
6
|
-
import type {OptionKey, OptionValue} from './options.js';
|
|
6
|
+
import type {OptionKey, OptionValue} from './options/options.js';
|
|
7
7
|
import type {
|
|
8
8
|
SourceCode,
|
|
9
9
|
SourcePosition,
|
package/client/editor.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
addLineClass,
|
|
13
13
|
removeLineClass,
|
|
14
14
|
} from './decorations.js';
|
|
15
|
-
import {setOption} from './options.js';
|
|
15
|
+
import {setOption} from './options/options.js';
|
|
16
16
|
import {clearHistory} from './history.js';
|
|
17
17
|
import {observeResize} from './dom.js';
|
|
18
18
|
|
package/client/index.d.ts
CHANGED
package/client/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {type Extension} from '@codemirror/state';
|
|
2
|
-
import type {QwordEditorView} from '
|
|
2
|
+
import type {QwordEditorView} from '../create.js';
|
|
3
3
|
import type {
|
|
4
4
|
KeyMap,
|
|
5
5
|
EditorMode,
|
|
6
6
|
EditorTheme,
|
|
7
|
-
} from '
|
|
7
|
+
} from '../types.js';
|
|
8
8
|
|
|
9
9
|
export function keymapExtension(name: KeyMap): Extension;
|
|
10
10
|
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
insertNewlineAndIndent,
|
|
13
13
|
} from '@codemirror/commands';
|
|
14
14
|
|
|
15
|
+
import {keepIndentAfterEnterVim} from './vim/keep-indent-after-enter-vim.js';
|
|
16
|
+
|
|
15
17
|
const enterKeepIndent = {
|
|
16
18
|
key: 'Enter',
|
|
17
19
|
run: insertNewlineAndIndent,
|
|
@@ -19,7 +21,10 @@ const enterKeepIndent = {
|
|
|
19
21
|
|
|
20
22
|
export function keymapExtension(name) {
|
|
21
23
|
if (name === 'vim')
|
|
22
|
-
return
|
|
24
|
+
return keymap.of([
|
|
25
|
+
vim(),
|
|
26
|
+
keepIndentAfterEnterVim,
|
|
27
|
+
]);
|
|
23
28
|
|
|
24
29
|
if (name === 'emacs')
|
|
25
30
|
return keymap.of([...emacsStyleKeymap, indentWithTab]);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {EditorState, Prec} from '@codemirror/state';
|
|
2
|
+
|
|
3
|
+
export const keepIndentAfterEnterVim = EditorState.transactionFilter.of((tr) => {
|
|
4
|
+
if (!tr.docChanged)
|
|
5
|
+
return tr;
|
|
6
|
+
|
|
7
|
+
const selection = tr.newSelection.main;
|
|
8
|
+
|
|
9
|
+
if (!selection.empty)
|
|
10
|
+
return tr;
|
|
11
|
+
|
|
12
|
+
const pos = selection.head;
|
|
13
|
+
const line = tr.newDoc.lineAt(pos);
|
|
14
|
+
|
|
15
|
+
if (pos !== line.from)
|
|
16
|
+
return tr;
|
|
17
|
+
|
|
18
|
+
let insertedNewline = false;
|
|
19
|
+
|
|
20
|
+
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
|
21
|
+
if (inserted.toString().includes('\n'))
|
|
22
|
+
insertedNewline = true;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (!insertedNewline)
|
|
26
|
+
return tr;
|
|
27
|
+
|
|
28
|
+
// Берём indentation предыдущей строки.
|
|
29
|
+
if (line.number === 1)
|
|
30
|
+
return tr;
|
|
31
|
+
|
|
32
|
+
const previousLine = tr.newDoc.line(line.number - 1);
|
|
33
|
+
const match = previousLine.text.match(/^\s*/);
|
|
34
|
+
const indent = match?.[0] || '';
|
|
35
|
+
|
|
36
|
+
if (!indent)
|
|
37
|
+
return tr;
|
|
38
|
+
|
|
39
|
+
return [
|
|
40
|
+
tr, {
|
|
41
|
+
changes: {
|
|
42
|
+
from: pos,
|
|
43
|
+
to: pos,
|
|
44
|
+
insert: indent,
|
|
45
|
+
},
|
|
46
|
+
selection: {
|
|
47
|
+
anchor: pos + indent.length,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
});
|
|
52
|
+
|