@codemirror/autocomplete 6.4.0 → 6.4.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 +14 -0
- package/LICENSE +1 -1
- package/dist/index.cjs +21 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 6.4.2 (2023-02-17)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix a bug where the apply method created by `snippet` didn't add a `pickedCompletion` annotation to the transactions it created.
|
|
6
|
+
|
|
7
|
+
## 6.4.1 (2023-02-14)
|
|
8
|
+
|
|
9
|
+
### Bug fixes
|
|
10
|
+
|
|
11
|
+
Don't consider node names in trees that aren't the same language as the one at the completion position in `ifIn` and `ifNotIn`.
|
|
12
|
+
|
|
13
|
+
Make sure completions that exactly match the input get a higher score than those that don't (so that even if the latter has a score boost, it ends up lower in the list).
|
|
14
|
+
|
|
1
15
|
## 6.4.0 (2022-12-14)
|
|
2
16
|
|
|
3
17
|
### Bug fixes
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (C) 2018-2021 by Marijn Haverbeke <
|
|
3
|
+
Copyright (C) 2018-2021 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/index.cjs
CHANGED
|
@@ -112,9 +112,12 @@ cursor is in a syntax node with one of the given names.
|
|
|
112
112
|
*/
|
|
113
113
|
function ifIn(nodes, source) {
|
|
114
114
|
return (context) => {
|
|
115
|
-
for (let pos = language.syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent)
|
|
115
|
+
for (let pos = language.syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) {
|
|
116
116
|
if (nodes.indexOf(pos.name) > -1)
|
|
117
117
|
return source(context);
|
|
118
|
+
if (pos.type.isTop)
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
118
121
|
return null;
|
|
119
122
|
};
|
|
120
123
|
}
|
|
@@ -124,9 +127,12 @@ cursor is in a syntax node with one of the given names.
|
|
|
124
127
|
*/
|
|
125
128
|
function ifNotIn(nodes, source) {
|
|
126
129
|
return (context) => {
|
|
127
|
-
for (let pos = language.syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent)
|
|
130
|
+
for (let pos = language.syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) {
|
|
128
131
|
if (nodes.indexOf(pos.name) > -1)
|
|
129
132
|
return null;
|
|
133
|
+
if (pos.type.isTop)
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
130
136
|
return source(context);
|
|
131
137
|
};
|
|
132
138
|
}
|
|
@@ -231,13 +237,18 @@ class FuzzyMatcher {
|
|
|
231
237
|
// For single-character queries, only match when they occur right
|
|
232
238
|
// at the start
|
|
233
239
|
if (chars.length == 1) {
|
|
234
|
-
let first = state.codePointAt(word, 0);
|
|
235
|
-
|
|
236
|
-
|
|
240
|
+
let first = state.codePointAt(word, 0), firstSize = state.codePointSize(first);
|
|
241
|
+
let score = firstSize == word.length ? 0 : -100 /* Penalty.NotFull */;
|
|
242
|
+
if (first == chars[0]) ;
|
|
243
|
+
else if (first == folded[0])
|
|
244
|
+
score += -200 /* Penalty.CaseFold */;
|
|
245
|
+
else
|
|
246
|
+
return null;
|
|
247
|
+
return [score, 0, firstSize];
|
|
237
248
|
}
|
|
238
249
|
let direct = word.indexOf(this.pattern);
|
|
239
250
|
if (direct == 0)
|
|
240
|
-
return [0
|
|
251
|
+
return [word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */, 0, this.pattern.length];
|
|
241
252
|
let len = chars.length, anyTo = 0;
|
|
242
253
|
if (direct < 0) {
|
|
243
254
|
for (let i = 0, e = Math.min(word.length, 200); i < e && anyTo < len;) {
|
|
@@ -293,7 +304,7 @@ class FuzzyMatcher {
|
|
|
293
304
|
if (byWordTo == len && byWord[0] == 0 && wordAdjacent)
|
|
294
305
|
return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0), byWord, word);
|
|
295
306
|
if (adjacentTo == len && adjacentStart == 0)
|
|
296
|
-
return [-200 /* Penalty.CaseFold */ - word.length, 0, adjacentEnd];
|
|
307
|
+
return [-200 /* Penalty.CaseFold */ - word.length + (adjacentEnd == word.length ? 0 : -100 /* Penalty.NotFull */), 0, adjacentEnd];
|
|
297
308
|
if (direct > -1)
|
|
298
309
|
return [-700 /* Penalty.NotStart */ - word.length, direct, direct + this.pattern.length];
|
|
299
310
|
if (adjacentTo == len)
|
|
@@ -1356,11 +1367,12 @@ interpreted as indicating a placeholder.
|
|
|
1356
1367
|
*/
|
|
1357
1368
|
function snippet(template) {
|
|
1358
1369
|
let snippet = Snippet.parse(template);
|
|
1359
|
-
return (editor,
|
|
1370
|
+
return (editor, completion, from, to) => {
|
|
1360
1371
|
let { text, ranges } = snippet.instantiate(editor.state, from);
|
|
1361
1372
|
let spec = {
|
|
1362
1373
|
changes: { from, to, insert: state.Text.of(text) },
|
|
1363
|
-
scrollIntoView: true
|
|
1374
|
+
scrollIntoView: true,
|
|
1375
|
+
annotations: pickedCompletion.of(completion)
|
|
1364
1376
|
};
|
|
1365
1377
|
if (ranges.length)
|
|
1366
1378
|
spec.selection = fieldSelection(ranges, 0);
|
package/dist/index.d.ts
CHANGED
|
@@ -338,7 +338,7 @@ interpreted as indicating a placeholder.
|
|
|
338
338
|
declare function snippet(template: string): (editor: {
|
|
339
339
|
state: EditorState;
|
|
340
340
|
dispatch: (tr: Transaction) => void;
|
|
341
|
-
},
|
|
341
|
+
}, completion: Completion, from: number, to: number) => void;
|
|
342
342
|
/**
|
|
343
343
|
A command that clears the active snippet, if any.
|
|
344
344
|
*/
|
package/dist/index.js
CHANGED
|
@@ -108,9 +108,12 @@ cursor is in a syntax node with one of the given names.
|
|
|
108
108
|
*/
|
|
109
109
|
function ifIn(nodes, source) {
|
|
110
110
|
return (context) => {
|
|
111
|
-
for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent)
|
|
111
|
+
for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) {
|
|
112
112
|
if (nodes.indexOf(pos.name) > -1)
|
|
113
113
|
return source(context);
|
|
114
|
+
if (pos.type.isTop)
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
114
117
|
return null;
|
|
115
118
|
};
|
|
116
119
|
}
|
|
@@ -120,9 +123,12 @@ cursor is in a syntax node with one of the given names.
|
|
|
120
123
|
*/
|
|
121
124
|
function ifNotIn(nodes, source) {
|
|
122
125
|
return (context) => {
|
|
123
|
-
for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent)
|
|
126
|
+
for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) {
|
|
124
127
|
if (nodes.indexOf(pos.name) > -1)
|
|
125
128
|
return null;
|
|
129
|
+
if (pos.type.isTop)
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
126
132
|
return source(context);
|
|
127
133
|
};
|
|
128
134
|
}
|
|
@@ -227,13 +233,18 @@ class FuzzyMatcher {
|
|
|
227
233
|
// For single-character queries, only match when they occur right
|
|
228
234
|
// at the start
|
|
229
235
|
if (chars.length == 1) {
|
|
230
|
-
let first = codePointAt(word, 0);
|
|
231
|
-
|
|
232
|
-
|
|
236
|
+
let first = codePointAt(word, 0), firstSize = codePointSize(first);
|
|
237
|
+
let score = firstSize == word.length ? 0 : -100 /* Penalty.NotFull */;
|
|
238
|
+
if (first == chars[0]) ;
|
|
239
|
+
else if (first == folded[0])
|
|
240
|
+
score += -200 /* Penalty.CaseFold */;
|
|
241
|
+
else
|
|
242
|
+
return null;
|
|
243
|
+
return [score, 0, firstSize];
|
|
233
244
|
}
|
|
234
245
|
let direct = word.indexOf(this.pattern);
|
|
235
246
|
if (direct == 0)
|
|
236
|
-
return [0
|
|
247
|
+
return [word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */, 0, this.pattern.length];
|
|
237
248
|
let len = chars.length, anyTo = 0;
|
|
238
249
|
if (direct < 0) {
|
|
239
250
|
for (let i = 0, e = Math.min(word.length, 200); i < e && anyTo < len;) {
|
|
@@ -289,7 +300,7 @@ class FuzzyMatcher {
|
|
|
289
300
|
if (byWordTo == len && byWord[0] == 0 && wordAdjacent)
|
|
290
301
|
return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0), byWord, word);
|
|
291
302
|
if (adjacentTo == len && adjacentStart == 0)
|
|
292
|
-
return [-200 /* Penalty.CaseFold */ - word.length, 0, adjacentEnd];
|
|
303
|
+
return [-200 /* Penalty.CaseFold */ - word.length + (adjacentEnd == word.length ? 0 : -100 /* Penalty.NotFull */), 0, adjacentEnd];
|
|
293
304
|
if (direct > -1)
|
|
294
305
|
return [-700 /* Penalty.NotStart */ - word.length, direct, direct + this.pattern.length];
|
|
295
306
|
if (adjacentTo == len)
|
|
@@ -1352,11 +1363,12 @@ interpreted as indicating a placeholder.
|
|
|
1352
1363
|
*/
|
|
1353
1364
|
function snippet(template) {
|
|
1354
1365
|
let snippet = Snippet.parse(template);
|
|
1355
|
-
return (editor,
|
|
1366
|
+
return (editor, completion, from, to) => {
|
|
1356
1367
|
let { text, ranges } = snippet.instantiate(editor.state, from);
|
|
1357
1368
|
let spec = {
|
|
1358
1369
|
changes: { from, to, insert: Text.of(text) },
|
|
1359
|
-
scrollIntoView: true
|
|
1370
|
+
scrollIntoView: true,
|
|
1371
|
+
annotations: pickedCompletion.of(completion)
|
|
1360
1372
|
};
|
|
1361
1373
|
if (ranges.length)
|
|
1362
1374
|
spec.selection = fieldSelection(ranges, 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemirror/autocomplete",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.2",
|
|
4
4
|
"description": "Autocompletion for the CodeMirror code editor",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "cm-runtests",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"author": {
|
|
14
14
|
"name": "Marijn Haverbeke",
|
|
15
|
-
"email": "
|
|
15
|
+
"email": "marijn@haverbeke.berlin",
|
|
16
16
|
"url": "http://marijnhaverbeke.nl"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|