@codemirror/autocomplete 0.20.3 → 6.0.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.
@@ -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,21 @@
1
+ ## 6.0.2 (2022-06-15)
2
+
3
+ ### Bug fixes
4
+
5
+ Declare package dependencies as peer dependencies as an attempt to avoid duplicated package issues.
6
+
7
+ ## 6.0.1 (2022-06-09)
8
+
9
+ ### Bug fixes
10
+
11
+ Support escaping `${` or `#{` in snippets.
12
+
13
+ ## 6.0.0 (2022-06-08)
14
+
15
+ ### Bug fixes
16
+
17
+ Scroll the cursor into view when inserting a snippet.
18
+
1
19
  ## 0.20.3 (2022-05-30)
2
20
 
3
21
  ### Bug fixes
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
@@ -1181,6 +1181,14 @@ class Snippet {
1181
1181
  positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
1182
1182
  line = line.slice(0, m.index) + name + line.slice(m.index + m[0].length);
1183
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
+ }
1184
1192
  lines.push(line);
1185
1193
  }
1186
1194
  return new Snippet(lines, positions);
@@ -1264,12 +1272,20 @@ cursor out of the current field deactivates the fields.
1264
1272
  The order of fields defaults to textual order, but you can add
1265
1273
  numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
1266
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.
1267
1280
  */
1268
1281
  function snippet(template) {
1269
1282
  let snippet = Snippet.parse(template);
1270
1283
  return (editor, _completion, from, to) => {
1271
1284
  let { text, ranges } = snippet.instantiate(editor.state, from);
1272
- 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
+ };
1273
1289
  if (ranges.length)
1274
1290
  spec.selection = fieldSelection(ranges, 0);
1275
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
@@ -1177,6 +1177,14 @@ class Snippet {
1177
1177
  positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
1178
1178
  line = line.slice(0, m.index) + name + line.slice(m.index + m[0].length);
1179
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
+ }
1180
1188
  lines.push(line);
1181
1189
  }
1182
1190
  return new Snippet(lines, positions);
@@ -1260,12 +1268,20 @@ cursor out of the current field deactivates the fields.
1260
1268
  The order of fields defaults to textual order, but you can add
1261
1269
  numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
1262
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.
1263
1276
  */
1264
1277
  function snippet(template) {
1265
1278
  let snippet = Snippet.parse(template);
1266
1279
  return (editor, _completion, from, to) => {
1267
1280
  let { text, ranges } = snippet.instantiate(editor.state, from);
1268
- let spec = { changes: { from, to, insert: Text.of(text) } };
1281
+ let spec = {
1282
+ changes: { from, to, insert: Text.of(text) },
1283
+ scrollIntoView: true
1284
+ };
1269
1285
  if (ranges.length)
1270
1286
  spec.selection = fieldSelection(ranges, 0);
1271
1287
  if (ranges.length > 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "0.20.3",
3
+ "version": "6.0.2",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -26,10 +26,16 @@
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
+ },
34
+ "peerDependencies": {
35
+ "@codemirror/language": "^6.0.0",
36
+ "@codemirror/state": "^6.0.0",
37
+ "@codemirror/view": "^6.0.0",
38
+ "@lezer/common": "^1.0.0"
33
39
  },
34
40
  "devDependencies": {
35
41
  "@codemirror/buildhelper": "^0.1.5"