qword 1.1.17 → 1.1.19
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 +11 -0
- package/client/create.js +2 -0
- package/client/options/options.js +2 -1
- package/client/options/vim/keep-indent-after-enter-vim.js +5 -1
- package/client/options/vim/keep-indent-after-vim-paste.js +54 -0
- package/dist/qword.js +3 -3
- package/dist/qword.js.map +1 -1
- package/dist-dev/qword.js +12 -3
- package/package.json +49 -13
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2026.09.08, v1.1.19
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- eb386eb client: indent after paste
|
|
5
|
+
- c3e8704 client: options: vim: correct selection not empty test assertion
|
|
6
|
+
|
|
7
|
+
2026.09.07, v1.1.18
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 587085d client: keep-indent-after-vim-paste
|
|
11
|
+
|
|
1
12
|
2026.09.07, v1.1.17
|
|
2
13
|
|
|
3
14
|
fix:
|
package/client/create.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
themeExtension,
|
|
21
21
|
languageExtension,
|
|
22
22
|
} from './options/options.js';
|
|
23
|
+
import {normalizeVimPaste} from './options/vim/keep-indent-after-vim-paste.js';
|
|
23
24
|
import {markField, lineField} from './decorations.js';
|
|
24
25
|
|
|
25
26
|
export function createEditor(element, options = {}) {
|
|
@@ -58,6 +59,7 @@ export function createEditor(element, options = {}) {
|
|
|
58
59
|
langCompartment.of(languageExtension(mode)),
|
|
59
60
|
syntaxHighlighting(highlightStyle),
|
|
60
61
|
indentOnInput(),
|
|
62
|
+
normalizeVimPaste,
|
|
61
63
|
indentUnit.of(' '),
|
|
62
64
|
...lineNumbers
|
|
63
65
|
? [
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from '@codemirror/commands';
|
|
14
14
|
|
|
15
15
|
import {keepIndentAfterEnterVim} from './vim/keep-indent-after-enter-vim.js';
|
|
16
|
+
import {normalizeVimPaste} from './vim/keep-indent-after-vim-paste.js';
|
|
16
17
|
|
|
17
18
|
const enterKeepIndent = {
|
|
18
19
|
key: 'Enter',
|
|
@@ -21,7 +22,7 @@ const enterKeepIndent = {
|
|
|
21
22
|
|
|
22
23
|
export function keymapExtension(name) {
|
|
23
24
|
if (name === 'vim')
|
|
24
|
-
return [vim(), keepIndentAfterEnterVim];
|
|
25
|
+
return [vim(), keepIndentAfterEnterVim, normalizeVimPaste];
|
|
25
26
|
|
|
26
27
|
if (name === 'emacs')
|
|
27
28
|
return keymap.of([...emacsStyleKeymap, indentWithTab]);
|
|
@@ -26,6 +26,7 @@ export const keepIndentAfterEnterVim = EditorState.transactionFilter.of((tr) =>
|
|
|
26
26
|
|
|
27
27
|
let insertedNewline = false;
|
|
28
28
|
let alreadyIndented = false;
|
|
29
|
+
let isMultilinePaste = false;
|
|
29
30
|
|
|
30
31
|
tr.changes.iterChanges((_fromA, _toA, _fromB, _toB, inserted) => {
|
|
31
32
|
const text = inserted.toString();
|
|
@@ -33,11 +34,14 @@ export const keepIndentAfterEnterVim = EditorState.transactionFilter.of((tr) =>
|
|
|
33
34
|
if (text.includes('\n'))
|
|
34
35
|
insertedNewline = true;
|
|
35
36
|
|
|
37
|
+
if (text.split('\n').length > 2)
|
|
38
|
+
isMultilinePaste = true;
|
|
39
|
+
|
|
36
40
|
if (text.endsWith(`\n${indent}`))
|
|
37
41
|
alreadyIndented = true;
|
|
38
42
|
});
|
|
39
43
|
|
|
40
|
-
if (!insertedNewline || alreadyIndented)
|
|
44
|
+
if (!insertedNewline || alreadyIndented || isMultilinePaste)
|
|
41
45
|
return tr;
|
|
42
46
|
|
|
43
47
|
return [
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {EditorState, Transaction} from '@codemirror/state';
|
|
2
|
+
|
|
3
|
+
export const normalizeVimPaste = EditorState.transactionFilter.of((tr) => {
|
|
4
|
+
if (!tr.docChanged)
|
|
5
|
+
return tr;
|
|
6
|
+
|
|
7
|
+
if (!tr.isUserEvent('input.type.compose'))
|
|
8
|
+
return tr;
|
|
9
|
+
|
|
10
|
+
if (!tr.newSelection.empty)
|
|
11
|
+
return tr;
|
|
12
|
+
|
|
13
|
+
const pos = tr.newSelection.main.head;
|
|
14
|
+
const line = tr.newDoc.lineAt(pos);
|
|
15
|
+
|
|
16
|
+
if (pos !== line.from)
|
|
17
|
+
return tr;
|
|
18
|
+
|
|
19
|
+
let hasNewlineInsert = false;
|
|
20
|
+
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
|
21
|
+
if (inserted.toString().includes('\n'))
|
|
22
|
+
hasNewlineInsert = true;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (!hasNewlineInsert)
|
|
26
|
+
return tr;
|
|
27
|
+
|
|
28
|
+
const destIndent = line.text.match(/^\s*/)?.[0] || '';
|
|
29
|
+
if (!destIndent)
|
|
30
|
+
return tr;
|
|
31
|
+
|
|
32
|
+
let hasBuggyPrefix = false;
|
|
33
|
+
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
|
34
|
+
const text = inserted.toString();
|
|
35
|
+
if (text.startsWith('\n') && text.slice(1).startsWith(destIndent))
|
|
36
|
+
hasBuggyPrefix = true;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (!hasBuggyPrefix)
|
|
40
|
+
return tr;
|
|
41
|
+
|
|
42
|
+
const newAnnotations = tr.annotations
|
|
43
|
+
.filter((a) => a.type !== Transaction.userEvent)
|
|
44
|
+
.concat(Transaction.userEvent.of('input.paste'));
|
|
45
|
+
|
|
46
|
+
return Transaction.create(
|
|
47
|
+
tr.startState,
|
|
48
|
+
tr.changes,
|
|
49
|
+
tr.selection,
|
|
50
|
+
tr.effects,
|
|
51
|
+
newAnnotations,
|
|
52
|
+
tr.scrollIntoView
|
|
53
|
+
);
|
|
54
|
+
});
|