@codemirror/autocomplete 0.20.2 → 6.0.1

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.
@@ -11,6 +11,6 @@ jobs:
11
11
  with:
12
12
  # You should create a personal access token and store it in your repository
13
13
  token: ${{ secrets.DISPATCH_AUTH }}
14
- repo: codemirror.next
14
+ repo: dev
15
15
  owner: codemirror
16
16
  event_type: push
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 6.0.1 (2022-06-09)
2
+
3
+ ### Bug fixes
4
+
5
+ Support escaping `${` or `#{` in snippets.
6
+
7
+ ## 6.0.0 (2022-06-08)
8
+
9
+ ### Bug fixes
10
+
11
+ Scroll the cursor into view when inserting a snippet.
12
+
13
+ ## 0.20.3 (2022-05-30)
14
+
15
+ ### Bug fixes
16
+
17
+ Add an aria-label to the completion listbox.
18
+
19
+ Fix a regression that caused transactions generated for completion to not have a `userEvent` annotation.
20
+
1
21
  ## 0.20.2 (2022-05-24)
2
22
 
3
23
  ### New features
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # @codemirror/autocomplete [![NPM version](https://img.shields.io/npm/v/@codemirror/autocomplete.svg)](https://www.npmjs.org/package/@codemirror/autocomplete)
2
2
 
3
- [ [**WEBSITE**](https://codemirror.net/6/) | [**DOCS**](https://codemirror.net/6/docs/ref/#autocomplete) | [**ISSUES**](https://github.com/codemirror/codemirror.next/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/autocomplete/blob/main/CHANGELOG.md) ]
3
+ [ [**WEBSITE**](https://codemirror.net/) | [**DOCS**](https://codemirror.net/docs/ref/#autocomplete) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/autocomplete/blob/main/CHANGELOG.md) ]
4
4
 
5
5
  This package implements autocompletion for the
6
- [CodeMirror](https://codemirror.net/6/) code editor.
6
+ [CodeMirror](https://codemirror.net/) code editor.
7
7
 
8
- The [project page](https://codemirror.net/6/) has more information, a
9
- number of [examples](https://codemirror.net/6/examples/) and the
10
- [documentation](https://codemirror.net/6/docs/).
8
+ The [project page](https://codemirror.net/) has more information, a
9
+ number of [examples](https://codemirror.net/examples/) and the
10
+ [documentation](https://codemirror.net/docs/).
11
11
 
12
12
  This code is released under an
13
13
  [MIT license](https://github.com/codemirror/autocomplete/tree/main/LICENSE).
package/dist/index.cjs CHANGED
@@ -159,7 +159,7 @@ completion's text in the main selection range, and any other
159
159
  selection range that has the same text in front of it.
160
160
  */
161
161
  function insertCompletionText(state$1, text, from, to) {
162
- return state$1.changeByRange(range => {
162
+ return Object.assign(Object.assign({}, state$1.changeByRange(range => {
163
163
  if (range == state$1.selection.main)
164
164
  return {
165
165
  changes: { from: from, to: to, insert: text },
@@ -173,7 +173,7 @@ function insertCompletionText(state$1, text, from, to) {
173
173
  changes: { from: range.from - len, to: range.from, insert: text },
174
174
  range: state.EditorSelection.cursor(range.from - len + text.length)
175
175
  };
176
- });
176
+ })), { userEvent: "input.complete" });
177
177
  }
178
178
  function applyCompletion(view, option) {
179
179
  const apply = option.completion.apply || option.completion.label;
@@ -532,6 +532,7 @@ class CompletionTooltip {
532
532
  ul.id = id;
533
533
  ul.setAttribute("role", "listbox");
534
534
  ul.setAttribute("aria-expanded", "true");
535
+ ul.setAttribute("aria-label", this.view.state.phrase("Completions"));
535
536
  for (let i = range.from; i < range.to; i++) {
536
537
  let { completion, match } = options[i];
537
538
  const li = ul.appendChild(document.createElement("li"));
@@ -1180,6 +1181,14 @@ class Snippet {
1180
1181
  positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
1181
1182
  line = line.slice(0, m.index) + name + line.slice(m.index + m[0].length);
1182
1183
  }
1184
+ for (let esc; esc = /([$#])\\{/.exec(line);) {
1185
+ line = line.slice(0, esc.index) + esc[1] + "{" + line.slice(esc.index + esc[0].length);
1186
+ for (let pos of positions)
1187
+ if (pos.line == lines.length && pos.from > esc.index) {
1188
+ pos.from--;
1189
+ pos.to--;
1190
+ }
1191
+ }
1183
1192
  lines.push(line);
1184
1193
  }
1185
1194
  return new Snippet(lines, positions);
@@ -1263,12 +1272,20 @@ cursor out of the current field deactivates the fields.
1263
1272
  The order of fields defaults to textual order, but you can add
1264
1273
  numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
1265
1274
  a custom order.
1275
+
1276
+ To include a literal `${` or `#{` in your template, put a
1277
+ backslash after the dollar or hash and before the brace (`$\\{`).
1278
+ This will be removed and the sequence will not be interpreted as a
1279
+ placeholder.
1266
1280
  */
1267
1281
  function snippet(template) {
1268
1282
  let snippet = Snippet.parse(template);
1269
1283
  return (editor, _completion, from, to) => {
1270
1284
  let { text, ranges } = snippet.instantiate(editor.state, from);
1271
- let spec = { changes: { from, to, insert: state.Text.of(text) } };
1285
+ let spec = {
1286
+ changes: { from, to, insert: state.Text.of(text) },
1287
+ scrollIntoView: true
1288
+ };
1272
1289
  if (ranges.length)
1273
1290
  spec.selection = fieldSelection(ranges, 0);
1274
1291
  if (ranges.length > 1) {
package/dist/index.d.ts CHANGED
@@ -302,6 +302,11 @@ cursor out of the current field deactivates the fields.
302
302
  The order of fields defaults to textual order, but you can add
303
303
  numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
304
304
  a custom order.
305
+
306
+ To include a literal `${` or `#{` in your template, put a
307
+ backslash after the dollar or hash and before the brace (`$\\{`).
308
+ This will be removed and the sequence will not be interpreted as a
309
+ placeholder.
305
310
  */
306
311
  declare function snippet(template: string): (editor: {
307
312
  state: EditorState;
package/dist/index.js CHANGED
@@ -155,7 +155,7 @@ completion's text in the main selection range, and any other
155
155
  selection range that has the same text in front of it.
156
156
  */
157
157
  function insertCompletionText(state, text, from, to) {
158
- return state.changeByRange(range => {
158
+ return Object.assign(Object.assign({}, state.changeByRange(range => {
159
159
  if (range == state.selection.main)
160
160
  return {
161
161
  changes: { from: from, to: to, insert: text },
@@ -169,7 +169,7 @@ function insertCompletionText(state, text, from, to) {
169
169
  changes: { from: range.from - len, to: range.from, insert: text },
170
170
  range: EditorSelection.cursor(range.from - len + text.length)
171
171
  };
172
- });
172
+ })), { userEvent: "input.complete" });
173
173
  }
174
174
  function applyCompletion(view, option) {
175
175
  const apply = option.completion.apply || option.completion.label;
@@ -528,6 +528,7 @@ class CompletionTooltip {
528
528
  ul.id = id;
529
529
  ul.setAttribute("role", "listbox");
530
530
  ul.setAttribute("aria-expanded", "true");
531
+ ul.setAttribute("aria-label", this.view.state.phrase("Completions"));
531
532
  for (let i = range.from; i < range.to; i++) {
532
533
  let { completion, match } = options[i];
533
534
  const li = ul.appendChild(document.createElement("li"));
@@ -1176,6 +1177,14 @@ class Snippet {
1176
1177
  positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
1177
1178
  line = line.slice(0, m.index) + name + line.slice(m.index + m[0].length);
1178
1179
  }
1180
+ for (let esc; esc = /([$#])\\{/.exec(line);) {
1181
+ line = line.slice(0, esc.index) + esc[1] + "{" + line.slice(esc.index + esc[0].length);
1182
+ for (let pos of positions)
1183
+ if (pos.line == lines.length && pos.from > esc.index) {
1184
+ pos.from--;
1185
+ pos.to--;
1186
+ }
1187
+ }
1179
1188
  lines.push(line);
1180
1189
  }
1181
1190
  return new Snippet(lines, positions);
@@ -1259,12 +1268,20 @@ cursor out of the current field deactivates the fields.
1259
1268
  The order of fields defaults to textual order, but you can add
1260
1269
  numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
1261
1270
  a custom order.
1271
+
1272
+ To include a literal `${` or `#{` in your template, put a
1273
+ backslash after the dollar or hash and before the brace (`$\\{`).
1274
+ This will be removed and the sequence will not be interpreted as a
1275
+ placeholder.
1262
1276
  */
1263
1277
  function snippet(template) {
1264
1278
  let snippet = Snippet.parse(template);
1265
1279
  return (editor, _completion, from, to) => {
1266
1280
  let { text, ranges } = snippet.instantiate(editor.state, from);
1267
- let spec = { changes: { from, to, insert: Text.of(text) } };
1281
+ let spec = {
1282
+ changes: { from, to, insert: Text.of(text) },
1283
+ scrollIntoView: true
1284
+ };
1268
1285
  if (ranges.length)
1269
1286
  spec.selection = fieldSelection(ranges, 0);
1270
1287
  if (ranges.length > 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "0.20.2",
3
+ "version": "6.0.1",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -26,10 +26,10 @@
26
26
  "sideEffects": false,
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@codemirror/language": "^0.20.0",
30
- "@codemirror/state": "^0.20.0",
31
- "@codemirror/view": "^0.20.0",
32
- "@lezer/common": "^0.16.0"
29
+ "@codemirror/language": "^6.0.0",
30
+ "@codemirror/state": "^6.0.0",
31
+ "@codemirror/view": "^6.0.0",
32
+ "@lezer/common": "^1.0.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@codemirror/buildhelper": "^0.1.5"