@codemirror/autocomplete 6.16.0 → 6.16.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 6.16.2 (2024-05-31)
2
+
3
+ ### Bug fixes
4
+
5
+ Allow backslash-escaped closing braces inside snippet field names/content.
6
+
7
+ ## 6.16.1 (2024-05-29)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix a bug where multiple backslashes before a brace in a snippet were all removed.
12
+
1
13
  ## 6.16.0 (2024-04-12)
2
14
 
3
15
  ### New features
package/dist/index.cjs CHANGED
@@ -1401,8 +1401,9 @@ class Snippet {
1401
1401
  let fields = [];
1402
1402
  let lines = [], positions = [], m;
1403
1403
  for (let line of template.split(/\r\n?|\n/)) {
1404
- while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(line)) {
1405
- let seq = m[1] ? +m[1] : null, name = m[2] || m[3] || "", found = -1;
1404
+ while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(line)) {
1405
+ let seq = m[1] ? +m[1] : null, rawName = m[2] || m[3] || "", found = -1;
1406
+ let name = rawName.replace(/\\[{}]/g, m => m[1]);
1406
1407
  for (let i = 0; i < fields.length; i++) {
1407
1408
  if (seq != null ? fields[i].seq == seq : name ? fields[i].name == name : false)
1408
1409
  found = i;
@@ -1418,16 +1419,16 @@ class Snippet {
1418
1419
  pos.field++;
1419
1420
  }
1420
1421
  positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
1421
- line = line.slice(0, m.index) + name + line.slice(m.index + m[0].length);
1422
+ line = line.slice(0, m.index) + rawName + line.slice(m.index + m[0].length);
1422
1423
  }
1423
- for (let esc; esc = /\\([{}])/.exec(line);) {
1424
- line = line.slice(0, esc.index) + esc[1] + line.slice(esc.index + esc[0].length);
1424
+ line = line.replace(/\\([{}])/g, (_, brace, index) => {
1425
1425
  for (let pos of positions)
1426
- if (pos.line == lines.length && pos.from > esc.index) {
1426
+ if (pos.line == lines.length && pos.from > index) {
1427
1427
  pos.from--;
1428
1428
  pos.to--;
1429
1429
  }
1430
- }
1430
+ return brace;
1431
+ });
1431
1432
  lines.push(line);
1432
1433
  }
1433
1434
  return new Snippet(lines, positions);
package/dist/index.d.cts CHANGED
@@ -522,7 +522,7 @@ interface CloseBracketConfig {
522
522
  /**
523
523
  The opening brackets to close. Defaults to `["(", "[", "{", "'",
524
524
  '"']`. Brackets may be single characters or a triple of quotes
525
- (as in `"''''"`).
525
+ (as in `"'''"`).
526
526
  */
527
527
  brackets?: string[];
528
528
  /**
package/dist/index.d.ts CHANGED
@@ -522,7 +522,7 @@ interface CloseBracketConfig {
522
522
  /**
523
523
  The opening brackets to close. Defaults to `["(", "[", "{", "'",
524
524
  '"']`. Brackets may be single characters or a triple of quotes
525
- (as in `"''''"`).
525
+ (as in `"'''"`).
526
526
  */
527
527
  brackets?: string[];
528
528
  /**
package/dist/index.js CHANGED
@@ -1399,8 +1399,9 @@ class Snippet {
1399
1399
  let fields = [];
1400
1400
  let lines = [], positions = [], m;
1401
1401
  for (let line of template.split(/\r\n?|\n/)) {
1402
- while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(line)) {
1403
- let seq = m[1] ? +m[1] : null, name = m[2] || m[3] || "", found = -1;
1402
+ while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(line)) {
1403
+ let seq = m[1] ? +m[1] : null, rawName = m[2] || m[3] || "", found = -1;
1404
+ let name = rawName.replace(/\\[{}]/g, m => m[1]);
1404
1405
  for (let i = 0; i < fields.length; i++) {
1405
1406
  if (seq != null ? fields[i].seq == seq : name ? fields[i].name == name : false)
1406
1407
  found = i;
@@ -1416,16 +1417,16 @@ class Snippet {
1416
1417
  pos.field++;
1417
1418
  }
1418
1419
  positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
1419
- line = line.slice(0, m.index) + name + line.slice(m.index + m[0].length);
1420
+ line = line.slice(0, m.index) + rawName + line.slice(m.index + m[0].length);
1420
1421
  }
1421
- for (let esc; esc = /\\([{}])/.exec(line);) {
1422
- line = line.slice(0, esc.index) + esc[1] + line.slice(esc.index + esc[0].length);
1422
+ line = line.replace(/\\([{}])/g, (_, brace, index) => {
1423
1423
  for (let pos of positions)
1424
- if (pos.line == lines.length && pos.from > esc.index) {
1424
+ if (pos.line == lines.length && pos.from > index) {
1425
1425
  pos.from--;
1426
1426
  pos.to--;
1427
1427
  }
1428
- }
1428
+ return brace;
1429
+ });
1429
1430
  lines.push(line);
1430
1431
  }
1431
1432
  return new Snippet(lines, positions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.16.0",
3
+ "version": "6.16.2",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",