@bhsd/codemirror-mediawiki 3.6.0 → 3.6.2

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.
@@ -10,14 +10,12 @@ export const findEnclosingBrackets = (node, pos, brackets) => {
10
10
  return { start: firstChild, end: lastChild, matched: true };
11
11
  }
12
12
  }
13
- ({ parent } = parent); // eslint-disable-line no-param-reassign
13
+ ({ parent } = parent);
14
14
  }
15
15
  return undefined;
16
16
  };
17
17
  export const findEnclosingPlainBrackets = (state, pos, config) => {
18
- const { brackets, maxScanDistance } = config, re = new RegExp(`[${
19
- // eslint-disable-next-line @typescript-eslint/no-misused-spread
20
- [...brackets].filter((_, i) => i % 2).map(c => c === ']' ? String.raw `\]` : c).join('')}]`, 'gu'), str = state.sliceDoc(pos, pos + maxScanDistance);
18
+ const { brackets, maxScanDistance } = config, re = new RegExp(`[${[...brackets].filter((_, i) => i % 2).map(c => c === ']' ? String.raw `\]` : c).join('')}]`, 'gu'), str = state.sliceDoc(pos, pos + maxScanDistance);
21
19
  let mt = re.exec(str);
22
20
  while (mt) {
23
21
  const result = matchBrackets(state, pos + mt.index + 1, -1, config), left = result?.end?.to;
package/dist/mediawiki.js CHANGED
@@ -20,14 +20,19 @@ import { EditorView } from '@codemirror/view';
20
20
  * @param to 结束位置
21
21
  */
22
22
  const apply = (view, completion, from, to) => {
23
- let { label } = completion;
24
- const initial = label.charAt(0).toLowerCase();
25
- if (view.state.sliceDoc(from, from + 1) === initial) {
23
+ let { label } = completion, selection;
24
+ const initial = label.charAt(0).toLowerCase(), { state } = view, after = state.sliceDoc(to);
25
+ if (state.sliceDoc(from, from + 1) === initial) {
26
26
  label = initial + label.slice(1);
27
27
  }
28
+ if (!/^\s*\|/u.test(after)) {
29
+ selection = { anchor: from + label.length + 1, head: from + label.length * 2 + 1 };
30
+ label += `|${label}${/^\s*\]\]/u.test(after) ? '' : ']]'}`;
31
+ }
28
32
  view.dispatch({
29
- ...insertCompletionText(view.state, label, from, to),
33
+ ...insertCompletionText(state, label, from, to),
30
34
  annotations: pickedCompletion.of(completion),
35
+ selection,
31
36
  });
32
37
  };
33
38
  export class FullMediaWiki extends MediaWiki {
@@ -99,7 +104,6 @@ export class FullMediaWiki extends MediaWiki {
99
104
  return undefined;
100
105
  }
101
106
  let subpage = false, search = str, offset = 0;
102
- /* eslint-disable no-param-reassign */
103
107
  if (search.startsWith('/')) {
104
108
  ns = 0;
105
109
  subpage = true;
@@ -126,7 +130,6 @@ export class FullMediaWiki extends MediaWiki {
126
130
  search = `${ns === -2 ? 'File' : prefix}:${search.slice(length)}`;
127
131
  }
128
132
  }
129
- /* eslint-enable no-param-reassign */
130
133
  const underscore = str.slice(offset).includes('_');
131
134
  return {
132
135
  offset,