qword 1.1.17 → 1.1.18
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 +2 -0
- package/client/options/options.js +2 -1
- package/client/options/vim/keep-indent-after-vim-paste.js +54 -0
- package/dist/qword.js +2 -2
- package/dist/qword.js.map +1 -1
- package/dist-dev/qword.js +11 -2
- package/package.json +49 -13
package/ChangeLog
CHANGED
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]);
|
|
@@ -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
|
+
});
|