@codemirror/autocomplete
Advanced tools
Comparing version 0.19.1 to 0.19.2
@@ -0,1 +1,7 @@ | ||
## 0.19.2 (2021-08-25) | ||
### Bug fixes | ||
Fix an issue where `completeAnyWord` would return results when there was no query and `explicit` was false. | ||
## 0.19.1 (2021-08-11) | ||
@@ -2,0 +8,0 @@ |
@@ -208,3 +208,3 @@ import { EditorState, Transaction, StateCommand, Facet, Extension } from '@codemirror/state'; | ||
other sources, unfiltered completions appear at the top of the | ||
list of completions. `span` must not be given `filter` is | ||
list of completions. `span` must not be given when `filter` is | ||
`false`, because it only works when filtering. | ||
@@ -211,0 +211,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
import { Facet, combineConfig, StateEffect, StateField, Text, EditorSelection, Prec, CharCategory } from '@codemirror/state'; | ||
import { Facet, combineConfig, StateEffect, StateField, Text, EditorSelection, Prec } from '@codemirror/state'; | ||
import { EditorView, Direction, logException, ViewPlugin, Decoration, WidgetType, keymap } from '@codemirror/view'; | ||
@@ -1237,2 +1237,63 @@ import { showTooltip } from '@codemirror/tooltip'; | ||
function wordRE(wordChars) { | ||
let escaped = wordChars.replace(/[\\[.+*?(){|^$]/g, "\\$&"); | ||
try { | ||
return new RegExp(`[\\p{Alphabetic}\\p{Number}_${escaped}]+`, "ug"); | ||
} | ||
catch (_a) { | ||
return new RegExp(`[\w${escaped}]`, "g"); | ||
} | ||
} | ||
function mapRE(re, f) { | ||
return new RegExp(f(re.source), re.unicode ? "u" : ""); | ||
} | ||
const wordCaches = /*@__PURE__*/Object.create(null); | ||
function wordCache(wordChars) { | ||
return wordCaches[wordChars] || (wordCaches[wordChars] = new WeakMap); | ||
} | ||
function storeWords(doc, wordRE, result, seen, ignoreAt) { | ||
for (let lines = doc.iterLines(), pos = 0; !lines.next().done;) { | ||
let { value } = lines, m; | ||
wordRE.lastIndex = 0; | ||
while (m = wordRE.exec(value)) { | ||
if (!seen[m[0]] && pos + m.index != ignoreAt) { | ||
result.push({ type: "text", label: m[0] }); | ||
seen[m[0]] = true; | ||
if (result.length >= 2000 /* MaxList */) | ||
return; | ||
} | ||
} | ||
pos += value.length + 1; | ||
} | ||
} | ||
function collectWords(doc, cache, wordRE, to, ignoreAt) { | ||
let big = doc.length >= 1000 /* MinCacheLen */; | ||
let cached = big && cache.get(doc); | ||
if (cached) | ||
return cached; | ||
let result = [], seen = Object.create(null); | ||
if (doc.children) { | ||
let pos = 0; | ||
for (let ch of doc.children) { | ||
if (ch.length >= 1000 /* MinCacheLen */) { | ||
for (let c of collectWords(ch, cache, wordRE, to - pos, ignoreAt - pos)) { | ||
if (!seen[c.label]) { | ||
seen[c.label] = true; | ||
result.push(c); | ||
} | ||
} | ||
} | ||
else { | ||
storeWords(ch, wordRE, result, seen, ignoreAt - pos); | ||
} | ||
pos += ch.length + 1; | ||
} | ||
} | ||
else { | ||
storeWords(doc, wordRE, result, seen, ignoreAt); | ||
} | ||
if (big && result.length < 2000 /* MaxList */) | ||
cache.set(doc, result); | ||
return result; | ||
} | ||
/** | ||
@@ -1244,32 +1305,10 @@ A completion source that will scan the document for words (using a | ||
const completeAnyWord = context => { | ||
let options = [], seen = Object.create(null); | ||
let cat = context.state.charCategorizer(context.pos); | ||
let start = Math.max(0, context.pos - 50000 /* Range */), end = Math.min(context.state.doc.length, start + 50000 /* Range */ * 2); | ||
let from = context.pos; | ||
for (let cur = context.state.doc.iterRange(start, end), pos = start; !(cur.next()).done;) { | ||
let { value } = cur, start = -1; | ||
for (let i = 0;; i++) { | ||
if (i < value.length && cat(value[i]) == CharCategory.Word) { | ||
if (start < 0) | ||
start = i; | ||
} | ||
else if (start > -1) { | ||
if (pos + start <= context.pos && pos + i >= context.pos) { | ||
from = pos + start; | ||
} | ||
else { | ||
let word = value.slice(start, i); | ||
if (!seen[word]) { | ||
options.push({ type: "text", label: word }); | ||
seen[word] = true; | ||
} | ||
} | ||
start = -1; | ||
} | ||
if (i == value.length) | ||
break; | ||
} | ||
pos += value.length; | ||
} | ||
return { from, options, span: /^\w*/ }; | ||
let wordChars = context.state.languageDataAt("wordChars", context.pos).join(""); | ||
let re = wordRE(wordChars); | ||
let token = context.matchBefore(mapRE(re, s => s + "$")); | ||
if (!token && !context.explicit) | ||
return null; | ||
let from = token ? token.from : context.pos; | ||
let options = collectWords(context.state.doc, wordCache(wordChars), re, 50000 /* Range */, from); | ||
return { from, options, span: mapRE(re, s => "^" + s) }; | ||
}; | ||
@@ -1276,0 +1315,0 @@ |
{ | ||
"name": "@codemirror/autocomplete", | ||
"version": "0.19.1", | ||
"version": "0.19.2", | ||
"description": "Autocompletion for the CodeMirror code editor", | ||
@@ -31,3 +31,3 @@ "scripts": { | ||
"@codemirror/state": "^0.19.0", | ||
"@codemirror/text": "^0.19.0", | ||
"@codemirror/text": "^0.19.2", | ||
"@codemirror/tooltip": "^0.19.0", | ||
@@ -34,0 +34,0 @@ "@codemirror/view": "^0.19.0", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130257
3033
Updated@codemirror/text@^0.19.2