qword 1.1.16 → 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 CHANGED
@@ -1,3 +1,14 @@
1
+ 2026.09.07, v1.1.18
2
+
3
+ feature:
4
+ - 587085d client: keep-indent-after-vim-paste
5
+
6
+ 2026.09.07, v1.1.17
7
+
8
+ fix:
9
+ - 1ab4367 client: options: vim: keep indent after second enter
10
+ - 7bde795 client: options: vim returns array with keepIndentAfterEnterVim
11
+
1
12
  2026.09.07, v1.1.16
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,10 +22,7 @@ const enterKeepIndent = {
21
22
 
22
23
  export function keymapExtension(name) {
23
24
  if (name === 'vim')
24
- return keymap.of([
25
- vim(),
26
- keepIndentAfterEnterVim,
27
- ]);
25
+ return [vim(), keepIndentAfterEnterVim, normalizeVimPaste];
28
26
 
29
27
  if (name === 'emacs')
30
28
  return keymap.of([...emacsStyleKeymap, indentWithTab]);
@@ -1,4 +1,4 @@
1
- import {EditorState, Prec} from '@codemirror/state';
1
+ import {EditorState} from '@codemirror/state';
2
2
 
3
3
  export const keepIndentAfterEnterVim = EditorState.transactionFilter.of((tr) => {
4
4
  if (!tr.docChanged)
@@ -15,38 +15,41 @@ export const keepIndentAfterEnterVim = EditorState.transactionFilter.of((tr) =>
15
15
  if (pos !== line.from)
16
16
  return tr;
17
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
18
  if (line.number === 1)
30
19
  return tr;
31
20
 
32
21
  const previousLine = tr.newDoc.line(line.number - 1);
33
- const match = previousLine.text.match(/^\s*/);
34
- const indent = match?.[0] || '';
22
+ const indent = previousLine.text.match(/^\s*/)?.[0] || '';
35
23
 
36
24
  if (!indent)
37
25
  return tr;
38
26
 
27
+ let insertedNewline = false;
28
+ let alreadyIndented = false;
29
+
30
+ tr.changes.iterChanges((_fromA, _toA, _fromB, _toB, inserted) => {
31
+ const text = inserted.toString();
32
+
33
+ if (text.includes('\n'))
34
+ insertedNewline = true;
35
+
36
+ if (text.endsWith(`\n${indent}`))
37
+ alreadyIndented = true;
38
+ });
39
+
40
+ if (!insertedNewline || alreadyIndented)
41
+ return tr;
42
+
39
43
  return [
40
44
  tr, {
41
45
  changes: {
42
46
  from: pos,
43
- to: pos,
44
47
  insert: indent,
45
48
  },
46
49
  selection: {
47
50
  anchor: pos + indent.length,
48
51
  },
52
+ sequential: true,
49
53
  },
50
54
  ];
51
55
  });
52
-
@@ -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
+ });