diff --git a/css/styles.css b/css/styles.css index 21c54675..69e82e79 100644 --- a/css/styles.css +++ b/css/styles.css @@ -45,4 +45,8 @@ main { .CodeMirror-scroll { height: auto !important; overflow: visible !important; +} + +.cm-editor { + max-height: 100vh; } \ No newline at end of file diff --git a/main.js b/main.js index e795c47f..a6ea1005 100644 --- a/main.js +++ b/main.js @@ -13467,7 +13467,7 @@ function buildTheme(main, spec, scopes) { } }); } -const baseTheme$1$2 = /*@__PURE__*/buildTheme("." + baseThemeID, { +const baseTheme$1$3 = /*@__PURE__*/buildTheme("." + baseThemeID, { "&": { position: "relative !important", boxSizing: "border-box", @@ -15233,7 +15233,7 @@ class EditorView { mountStyles() { this.styleModules = this.state.facet(styleModule); let nonce = this.state.facet(EditorView.cspNonce); - StyleModule.mount(this.root, this.styleModules.concat(baseTheme$1$2).reverse(), nonce ? { nonce } : undefined); + StyleModule.mount(this.root, this.styleModules.concat(baseTheme$1$3).reverse(), nonce ? { nonce } : undefined); } readMeasured() { if (this.updateState == 2 /* UpdateState.Updating */) @@ -17331,7 +17331,7 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class { scroll() { this.maybeMeasure(); } } }); -const baseTheme$5 = /*@__PURE__*/EditorView.baseTheme({ +const baseTheme$4 = /*@__PURE__*/EditorView.baseTheme({ ".cm-tooltip": { zIndex: 100, boxSizing: "border-box" @@ -17398,7 +17398,7 @@ const noOffset = { x: 0, y: 0 }; Facet to which an extension can add a value to show a tooltip. */ const showTooltip = /*@__PURE__*/Facet.define({ - enables: [tooltipPlugin, baseTheme$5] + enables: [tooltipPlugin, baseTheme$4] }); const showHoverTooltip = /*@__PURE__*/Facet.define({ combine: inputs => inputs.reduce((a, i) => a.concat(i), []) @@ -19601,7 +19601,7 @@ const foldConfig = /*@__PURE__*/Facet.define({ Create an extension that configures code folding. */ function codeFolding(config) { - let result = [foldState, baseTheme$1$1]; + let result = [foldState, baseTheme$1$2]; return result; } function widgetToDOM(view, prepared) { @@ -19717,7 +19717,7 @@ function foldGutter(config = {}) { codeFolding() ]; } -const baseTheme$1$1 = /*@__PURE__*/EditorView.baseTheme({ +const baseTheme$1$2 = /*@__PURE__*/EditorView.baseTheme({ ".cm-foldPlaceholder": { backgroundColor: "#eee", border: "1px solid #ddd", @@ -19895,7 +19895,7 @@ const defaultHighlightStyle = /*@__PURE__*/HighlightStyle.define([ color: "#f00" } ]); -const baseTheme$4 = /*@__PURE__*/EditorView.baseTheme({ +const baseTheme$3 = /*@__PURE__*/EditorView.baseTheme({ "&.cm-focused .cm-matchingBracket": { backgroundColor: "#328c8252" }, "&.cm-focused .cm-nonmatchingBracket": { backgroundColor: "#bb555544" } }); @@ -19943,7 +19943,7 @@ const bracketMatchingState = /*@__PURE__*/StateField.define({ }); const bracketMatchingUnique = [ bracketMatchingState, - baseTheme$4 + baseTheme$3 ]; /** Create an extension that enables bracket matching. Whenever the @@ -20455,6890 +20455,6899 @@ var githubDarkInit = options => { }; githubDarkInit(); +function crelt() { + var elt = arguments[0]; + if (typeof elt == "string") elt = document.createElement(elt); + var i = 1, next = arguments[1]; + if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) { + for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) { + var value = next[name]; + if (typeof value == "string") elt.setAttribute(name, value); + else if (value != null) elt[name] = value; + } + i++; + } + for (; i < arguments.length; i++) add(elt, arguments[i]); + return elt +} + +function add(elt, child) { + if (typeof child == "string") { + elt.appendChild(document.createTextNode(child)); + } else if (child == null) ; else if (child.nodeType != null) { + elt.appendChild(child); + } else if (Array.isArray(child)) { + for (var i = 0; i < child.length; i++) add(elt, child[i]); + } else { + throw new RangeError("Unsupported child node: " + child) + } +} + +const basicNormalize = typeof String.prototype.normalize == "function" + ? x => x.normalize("NFKD") : x => x; /** -A parse stack. These are used internally by the parser to track -parsing progress. They also provide some properties and methods -that external code such as a tokenizer can use to get information -about the parse state. +A search cursor provides an iterator over text matches in a +document. */ -class Stack { - /** - @internal - */ - constructor( - /** - The parse that this stack is part of @internal - */ - p, - /** - Holds state, input pos, buffer index triplets for all but the - top state @internal - */ - stack, - /** - The current parse state @internal - */ - state, - // The position at which the next reduce should take place. This - // can be less than `this.pos` when skipped expressions have been - // added to the stack (which should be moved outside of the next - // reduction) - /** - @internal - */ - reducePos, - /** - The input position up to which this stack has parsed. - */ - pos, - /** - The dynamic score of the stack, including dynamic precedence - and error-recovery penalties - @internal - */ - score, - // The output buffer. Holds (type, start, end, size) quads - // representing nodes created by the parser, where `size` is - // amount of buffer array entries covered by this node. - /** - @internal - */ - buffer, - // The base offset of the buffer. When stacks are split, the split - // instance shared the buffer history with its parent up to - // `bufferBase`, which is the absolute offset (including the - // offset of previous splits) into the buffer at which this stack - // starts writing. - /** - @internal - */ - bufferBase, - /** - @internal - */ - curContext, - /** - @internal - */ - lookAhead = 0, - // A parent stack from which this was split off, if any. This is - // set up so that it always points to a stack that has some - // additional buffer content, never to a stack with an equal - // `bufferBase`. - /** - @internal - */ - parent) { - this.p = p; - this.stack = stack; - this.state = state; - this.reducePos = reducePos; - this.pos = pos; - this.score = score; - this.buffer = buffer; - this.bufferBase = bufferBase; - this.curContext = curContext; - this.lookAhead = lookAhead; - this.parent = parent; - } +class SearchCursor { /** - @internal + Create a text cursor. The query is the search string, `from` to + `to` provides the region to search. + + When `normalize` is given, it will be called, on both the query + string and the content it is matched against, before comparing. + You can, for example, create a case-insensitive search by + passing `s => s.toLowerCase()`. + + Text is always normalized with + [`.normalize("NFKD")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize) + (when supported). */ - toString() { - return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`; + constructor(text, query, from = 0, to = text.length, normalize, test) { + this.test = test; + /** + The current match (only holds a meaningful value after + [`next`](https://codemirror.net/6/docs/ref/#search.SearchCursor.next) has been called and when + `done` is false). + */ + this.value = { from: 0, to: 0 }; + /** + Whether the end of the iterated region has been reached. + */ + this.done = false; + this.matches = []; + this.buffer = ""; + this.bufferPos = 0; + this.iter = text.iterRange(from, to); + this.bufferStart = from; + this.normalize = normalize ? x => normalize(basicNormalize(x)) : basicNormalize; + this.query = this.normalize(query); } - // Start an empty stack - /** - @internal - */ - static start(p, state, pos = 0) { - let cx = p.parser.context; - return new Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null); + peek() { + if (this.bufferPos == this.buffer.length) { + this.bufferStart += this.buffer.length; + this.iter.next(); + if (this.iter.done) + return -1; + this.bufferPos = 0; + this.buffer = this.iter.value; + } + return codePointAt(this.buffer, this.bufferPos); } /** - The stack's current [context](#lr.ContextTracker) value, if - any. Its type will depend on the context tracker's type - parameter, or it will be `null` if there is no context - tracker. - */ - get context() { return this.curContext ? this.curContext.context : null; } - // Push a state onto the stack, tracking its start position as well - // as the buffer base at that point. - /** - @internal + Look for the next match. Updates the iterator's + [`value`](https://codemirror.net/6/docs/ref/#search.SearchCursor.value) and + [`done`](https://codemirror.net/6/docs/ref/#search.SearchCursor.done) properties. Should be called + at least once before using the cursor. */ - pushState(state, start) { - this.stack.push(this.state, start, this.bufferBase + this.buffer.length); - this.state = state; + next() { + while (this.matches.length) + this.matches.pop(); + return this.nextOverlapping(); } - // Apply a reduce action /** - @internal + The `next` method will ignore matches that partially overlap a + previous match. This method behaves like `next`, but includes + such matches. */ - reduce(action) { - var _a; - let depth = action >> 19 /* Action.ReduceDepthShift */, type = action & 65535 /* Action.ValueMask */; - let { parser } = this.p; - if (this.reducePos < this.pos - 25 /* Lookahead.Margin */) - this.setLookAhead(this.pos); - let dPrec = parser.dynamicPrecedence(type); - if (dPrec) - this.score += dPrec; - if (depth == 0) { - this.pushState(parser.getGoto(this.state, type, true), this.reducePos); - // Zero-depth reductions are a special case—they add stuff to - // the stack without popping anything off. - if (type < parser.minRepeatTerm) - this.storeNode(type, this.reducePos, this.reducePos, 4, true); - this.reduceContext(type, this.reducePos); - return; - } - // Find the base index into `this.stack`, content after which will - // be dropped. Note that with `StayFlag` reductions we need to - // consume two extra frames (the dummy parent node for the skipped - // expression and the state that we'll be staying in, which should - // be moved to `this.state`). - let base = this.stack.length - ((depth - 1) * 3) - (action & 262144 /* Action.StayFlag */ ? 6 : 0); - let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start; - // This is a kludge to try and detect overly deep left-associative - // trees, which will not increase the parse stack depth and thus - // won't be caught by the regular stack-depth limit check. - if (size >= 2000 /* Recover.MinBigReduction */ && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) { - if (start == this.p.lastBigReductionStart) { - this.p.bigReductionCount++; - this.p.lastBigReductionSize = size; + nextOverlapping() { + for (;;) { + let next = this.peek(); + if (next < 0) { + this.done = true; + return this; } - else if (this.p.lastBigReductionSize < size) { - this.p.bigReductionCount = 1; - this.p.lastBigReductionStart = start; - this.p.lastBigReductionSize = size; + let str = fromCodePoint(next), start = this.bufferStart + this.bufferPos; + this.bufferPos += codePointSize(next); + let norm = this.normalize(str); + for (let i = 0, pos = start;; i++) { + let code = norm.charCodeAt(i); + let match = this.match(code, pos, this.bufferPos + this.bufferStart); + if (i == norm.length - 1) { + if (match) { + this.value = match; + return this; + } + break; + } + if (pos == start && i < str.length && str.charCodeAt(i) == code) + pos++; } } - let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase; - // Store normal terms or `R -> R R` repeat reductions - if (type < parser.minRepeatTerm || (action & 131072 /* Action.RepeatFlag */)) { - let pos = parser.stateFlag(this.state, 1 /* StateFlag.Skipped */) ? this.pos : this.reducePos; - this.storeNode(type, start, pos, count + 4, true); - } - if (action & 262144 /* Action.StayFlag */) { - this.state = this.stack[base]; - } - else { - let baseStateID = this.stack[base - 3]; - this.state = parser.getGoto(baseStateID, type, true); - } - while (this.stack.length > base) - this.stack.pop(); - this.reduceContext(type, start); } - // Shift a value into the buffer - /** - @internal - */ - storeNode(term, start, end, size = 4, isReduce = false) { - if (term == 0 /* Term.Err */ && - (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) { - // Try to omit/merge adjacent error nodes - let cur = this, top = this.buffer.length; - if (top == 0 && cur.parent) { - top = cur.bufferBase - cur.parent.bufferBase; - cur = cur.parent; - } - if (top > 0 && cur.buffer[top - 4] == 0 /* Term.Err */ && cur.buffer[top - 1] > -1) { - if (start == end) - return; - if (cur.buffer[top - 2] >= start) { - cur.buffer[top - 2] = end; - return; + match(code, pos, end) { + let match = null; + for (let i = 0; i < this.matches.length; i += 2) { + let index = this.matches[i], keep = false; + if (this.query.charCodeAt(index) == code) { + if (index == this.query.length - 1) { + match = { from: this.matches[i + 1], to: end }; + } + else { + this.matches[i]++; + keep = true; } } + if (!keep) { + this.matches.splice(i, 2); + i -= 2; + } } - if (!isReduce || this.pos == end) { // Simple case, just append - this.buffer.push(term, start, end, size); - } - else { // There may be skipped nodes that have to be moved forward - let index = this.buffer.length; - if (index > 0 && this.buffer[index - 4] != 0 /* Term.Err */) - while (index > 0 && this.buffer[index - 2] > end) { - // Move this record forward - this.buffer[index] = this.buffer[index - 4]; - this.buffer[index + 1] = this.buffer[index - 3]; - this.buffer[index + 2] = this.buffer[index - 2]; - this.buffer[index + 3] = this.buffer[index - 1]; - index -= 4; - if (size > 4) - size -= 4; - } - this.buffer[index] = term; - this.buffer[index + 1] = start; - this.buffer[index + 2] = end; - this.buffer[index + 3] = size; + if (this.query.charCodeAt(0) == code) { + if (this.query.length == 1) + match = { from: pos, to: end }; + else + this.matches.push(1, pos); } + if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferStart)) + match = null; + return match; } - // Apply a shift action +} +if (typeof Symbol != "undefined") + SearchCursor.prototype[Symbol.iterator] = function () { return this; }; + +const empty = { from: -1, to: -1, match: /*@__PURE__*//.*/.exec("") }; +const baseFlags = "gm" + (/x/.unicode == null ? "" : "u"); +/** +This class is similar to [`SearchCursor`](https://codemirror.net/6/docs/ref/#search.SearchCursor) +but searches for a regular expression pattern instead of a plain +string. +*/ +class RegExpCursor { /** - @internal + Create a cursor that will search the given range in the given + document. `query` should be the raw pattern (as you'd pass it to + `new RegExp`). */ - shift(action, type, start, end) { - if (action & 131072 /* Action.GotoFlag */) { - this.pushState(action & 65535 /* Action.ValueMask */, this.pos); - } - else if ((action & 262144 /* Action.StayFlag */) == 0) { // Regular shift - let nextState = action, { parser } = this.p; - if (end > this.pos || type <= parser.maxNode) { - this.pos = end; - if (!parser.stateFlag(nextState, 1 /* StateFlag.Skipped */)) - this.reducePos = end; - } - this.pushState(nextState, start); - this.shiftContext(type, start); - if (type <= parser.maxNode) - this.buffer.push(type, start, end, 4); + constructor(text, query, options, from = 0, to = text.length) { + this.text = text; + this.to = to; + this.curLine = ""; + /** + Set to `true` when the cursor has reached the end of the search + range. + */ + this.done = false; + /** + Will contain an object with the extent of the match and the + match object when [`next`](https://codemirror.net/6/docs/ref/#search.RegExpCursor.next) + sucessfully finds a match. + */ + this.value = empty; + if (/\\[sWDnr]|\n|\r|\[\^/.test(query)) + return new MultilineRegExpCursor(text, query, options, from, to); + this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : "")); + this.test = options === null || options === void 0 ? void 0 : options.test; + this.iter = text.iter(); + let startLine = text.lineAt(from); + this.curLineStart = startLine.from; + this.matchPos = toCharEnd(text, from); + this.getLine(this.curLineStart); + } + getLine(skip) { + this.iter.next(skip); + if (this.iter.lineBreak) { + this.curLine = ""; } - else { // Shift-and-stay, which means this is a skipped token - this.pos = end; - this.shiftContext(type, start); - if (type <= this.p.parser.maxNode) - this.buffer.push(type, start, end, 4); + else { + this.curLine = this.iter.value; + if (this.curLineStart + this.curLine.length > this.to) + this.curLine = this.curLine.slice(0, this.to - this.curLineStart); + this.iter.next(); } } - // Apply an action - /** - @internal - */ - apply(action, next, nextStart, nextEnd) { - if (action & 65536 /* Action.ReduceFlag */) - this.reduce(action); + nextLine() { + this.curLineStart = this.curLineStart + this.curLine.length + 1; + if (this.curLineStart > this.to) + this.curLine = ""; else - this.shift(action, next, nextStart, nextEnd); + this.getLine(0); } - // Add a prebuilt (reused) node into the buffer. /** - @internal + Move to the next match, if there is one. */ - useNode(value, next) { - let index = this.p.reused.length - 1; - if (index < 0 || this.p.reused[index] != value) { - this.p.reused.push(value); - index++; + next() { + for (let off = this.matchPos - this.curLineStart;;) { + this.re.lastIndex = off; + let match = this.matchPos <= this.to && this.re.exec(this.curLine); + if (match) { + let from = this.curLineStart + match.index, to = from + match[0].length; + this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0)); + if (from == this.curLineStart + this.curLine.length) + this.nextLine(); + if ((from < to || from > this.value.to) && (!this.test || this.test(from, to, match))) { + this.value = { from, to, match }; + return this; + } + off = this.matchPos - this.curLineStart; + } + else if (this.curLineStart + this.curLine.length < this.to) { + this.nextLine(); + off = 0; + } + else { + this.done = true; + return this; + } } - let start = this.pos; - this.reducePos = this.pos = start + value.length; - this.pushState(next, start); - this.buffer.push(index, start, this.reducePos, -1 /* size == -1 means this is a reused value */); - if (this.curContext) - this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length))); } - // Split the stack. Due to the buffer sharing and the fact - // that `this.stack` tends to stay quite shallow, this isn't very - // expensive. - /** - @internal - */ - split() { - let parent = this; - let off = parent.buffer.length; - // Because the top of the buffer (after this.pos) may be mutated - // to reorder reductions and skipped tokens, and shared buffers - // should be immutable, this copies any outstanding skipped tokens - // to the new buffer, and puts the base pointer before them. - while (off > 0 && parent.buffer[off - 2] > parent.reducePos) - off -= 4; - let buffer = parent.buffer.slice(off), base = parent.bufferBase + off; - // Make sure parent points to an actual parent with content, if there is such a parent. - while (parent && base == parent.bufferBase) - parent = parent.parent; - return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent); +} +const flattened = /*@__PURE__*/new WeakMap(); +// Reusable (partially) flattened document strings +class FlattenedDoc { + constructor(from, text) { + this.from = from; + this.text = text; } - // Try to recover from an error by 'deleting' (ignoring) one token. - /** - @internal - */ - recoverByDelete(next, nextEnd) { - let isNode = next <= this.p.parser.maxNode; - if (isNode) - this.storeNode(next, this.pos, nextEnd, 4); - this.storeNode(0 /* Term.Err */, this.pos, nextEnd, isNode ? 8 : 4); - this.pos = this.reducePos = nextEnd; - this.score -= 190 /* Recover.Delete */; + get to() { return this.from + this.text.length; } + static get(doc, from, to) { + let cached = flattened.get(doc); + if (!cached || cached.from >= to || cached.to <= from) { + let flat = new FlattenedDoc(from, doc.sliceString(from, to)); + flattened.set(doc, flat); + return flat; + } + if (cached.from == from && cached.to == to) + return cached; + let { text, from: cachedFrom } = cached; + if (cachedFrom > from) { + text = doc.sliceString(from, cachedFrom) + text; + cachedFrom = from; + } + if (cached.to < to) + text += doc.sliceString(cached.to, to); + flattened.set(doc, new FlattenedDoc(cachedFrom, text)); + return new FlattenedDoc(from, text.slice(from - cachedFrom, to - cachedFrom)); } - /** - Check if the given term would be able to be shifted (optionally - after some reductions) on this stack. This can be useful for - external tokenizers that want to make sure they only provide a - given token when it applies. - */ - canShift(term) { - for (let sim = new SimulatedStack(this);;) { - let action = this.p.parser.stateSlot(sim.state, 4 /* ParseState.DefaultReduce */) || this.p.parser.hasAction(sim.state, term); - if (action == 0) - return false; - if ((action & 65536 /* Action.ReduceFlag */) == 0) - return true; - sim.reduce(action); - } +} +class MultilineRegExpCursor { + constructor(text, query, options, from, to) { + this.text = text; + this.to = to; + this.done = false; + this.value = empty; + this.matchPos = toCharEnd(text, from); + this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : "")); + this.test = options === null || options === void 0 ? void 0 : options.test; + this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5000 /* Chunk.Base */)); } - // Apply up to Recover.MaxNext recovery actions that conceptually - // inserts some missing token or rule. - /** - @internal - */ - recoverByInsert(next) { - if (this.stack.length >= 300 /* Recover.MaxInsertStackDepth */) - return []; - let nextStates = this.p.parser.nextStates(this.state); - if (nextStates.length > 4 /* Recover.MaxNext */ << 1 || this.stack.length >= 120 /* Recover.DampenInsertStackDepth */) { - let best = []; - for (let i = 0, s; i < nextStates.length; i += 2) { - if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next)) - best.push(nextStates[i], s); + chunkEnd(pos) { + return pos >= this.to ? this.to : this.text.lineAt(pos).to; + } + next() { + for (;;) { + let off = this.re.lastIndex = this.matchPos - this.flat.from; + let match = this.re.exec(this.flat.text); + // Skip empty matches directly after the last match + if (match && !match[0] && match.index == off) { + this.re.lastIndex = off + 1; + match = this.re.exec(this.flat.text); } - if (this.stack.length < 120 /* Recover.DampenInsertStackDepth */) - for (let i = 0; best.length < 4 /* Recover.MaxNext */ << 1 && i < nextStates.length; i += 2) { - let s = nextStates[i + 1]; - if (!best.some((v, i) => (i & 1) && v == s)) - best.push(nextStates[i], s); + if (match) { + let from = this.flat.from + match.index, to = from + match[0].length; + // If a match goes almost to the end of a noncomplete chunk, try + // again, since it'll likely be able to match more + if ((this.flat.to >= this.to || match.index + match[0].length <= this.flat.text.length - 10) && + (!this.test || this.test(from, to, match))) { + this.value = { from, to, match }; + this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0)); + return this; } - nextStates = best; - } - let result = []; - for (let i = 0; i < nextStates.length && result.length < 4 /* Recover.MaxNext */; i += 2) { - let s = nextStates[i + 1]; - if (s == this.state) - continue; - let stack = this.split(); - stack.pushState(s, this.pos); - stack.storeNode(0 /* Term.Err */, stack.pos, stack.pos, 4, true); - stack.shiftContext(nextStates[i], this.pos); - stack.reducePos = this.pos; - stack.score -= 200 /* Recover.Insert */; - result.push(stack); - } - return result; - } - // Force a reduce, if possible. Return false if that can't - // be done. - /** - @internal - */ - forceReduce() { - let { parser } = this.p; - let reduce = parser.stateSlot(this.state, 5 /* ParseState.ForcedReduce */); - if ((reduce & 65536 /* Action.ReduceFlag */) == 0) - return false; - if (!parser.validAction(this.state, reduce)) { - let depth = reduce >> 19 /* Action.ReduceDepthShift */, term = reduce & 65535 /* Action.ValueMask */; - let target = this.stack.length - depth * 3; - if (target < 0 || parser.getGoto(this.stack[target], term, false) < 0) { - let backup = this.findForcedReduction(); - if (backup == null) - return false; - reduce = backup; } - this.storeNode(0 /* Term.Err */, this.pos, this.pos, 4, true); - this.score -= 100 /* Recover.Reduce */; + if (this.flat.to == this.to) { + this.done = true; + return this; + } + // Grow the flattened doc + this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2)); } - this.reducePos = this.pos; - this.reduce(reduce); + } +} +if (typeof Symbol != "undefined") { + RegExpCursor.prototype[Symbol.iterator] = MultilineRegExpCursor.prototype[Symbol.iterator] = + function () { return this; }; +} +function validRegExp(source) { + try { + new RegExp(source, baseFlags); return true; } - /** - Try to scan through the automaton to find some kind of reduction - that can be applied. Used when the regular ForcedReduce field - isn't a valid action. @internal - */ - findForcedReduction() { - let { parser } = this.p, seen = []; - let explore = (state, depth) => { - if (seen.includes(state)) - return; - seen.push(state); - return parser.allActions(state, (action) => { - if (action & (262144 /* Action.StayFlag */ | 131072 /* Action.GotoFlag */)) ; - else if (action & 65536 /* Action.ReduceFlag */) { - let rDepth = (action >> 19 /* Action.ReduceDepthShift */) - depth; - if (rDepth > 1) { - let term = action & 65535 /* Action.ValueMask */, target = this.stack.length - rDepth * 3; - if (target >= 0 && parser.getGoto(this.stack[target], term, false) >= 0) - return (rDepth << 19 /* Action.ReduceDepthShift */) | 65536 /* Action.ReduceFlag */ | term; - } - } - else { - let found = explore(action, depth + 1); - if (found != null) - return found; - } - }); - }; - return explore(this.state, 0); + catch (_a) { + return false; } - /** - @internal - */ - forceAll() { - while (!this.p.parser.stateFlag(this.state, 2 /* StateFlag.Accepting */)) { - if (!this.forceReduce()) { - this.storeNode(0 /* Term.Err */, this.pos, this.pos, 4, true); - break; +} +function toCharEnd(text, pos) { + if (pos >= text.length) + return pos; + let line = text.lineAt(pos), next; + while (pos < line.to && (next = line.text.charCodeAt(pos - line.from)) >= 0xDC00 && next < 0xE000) + pos++; + return pos; +} + +function createLineDialog(view) { + let line = String(view.state.doc.lineAt(view.state.selection.main.head).number); + let input = crelt("input", { class: "cm-textfield", name: "line", value: line }); + let dom = crelt("form", { + class: "cm-gotoLine", + onkeydown: (event) => { + if (event.keyCode == 27) { // Escape + event.preventDefault(); + view.dispatch({ effects: dialogEffect.of(false) }); + view.focus(); } + else if (event.keyCode == 13) { // Enter + event.preventDefault(); + go(); + } + }, + onsubmit: (event) => { + event.preventDefault(); + go(); } - return this; + }, crelt("label", view.state.phrase("Go to line"), ": ", input), " ", crelt("button", { class: "cm-button", type: "submit" }, view.state.phrase("go"))); + function go() { + let match = /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(input.value); + if (!match) + return; + let { state } = view, startLine = state.doc.lineAt(state.selection.main.head); + let [, sign, ln, cl, percent] = match; + let col = cl ? +cl.slice(1) : 0; + let line = ln ? +ln : startLine.number; + if (ln && percent) { + let pc = line / 100; + if (sign) + pc = pc * (sign == "-" ? -1 : 1) + (startLine.number / state.doc.lines); + line = Math.round(state.doc.lines * pc); + } + else if (ln && sign) { + line = line * (sign == "-" ? -1 : 1) + startLine.number; + } + let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line))); + let selection = EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length))); + view.dispatch({ + effects: [dialogEffect.of(false), EditorView.scrollIntoView(selection.from, { y: 'center' })], + selection, + }); + view.focus(); } - /** - Check whether this state has no further actions (assumed to be a direct descendant of the - top state, since any other states must be able to continue - somehow). @internal - */ - get deadEnd() { - if (this.stack.length != 3) - return false; - let { parser } = this.p; - return parser.data[parser.stateSlot(this.state, 1 /* ParseState.Actions */)] == 65535 /* Seq.End */ && - !parser.stateSlot(this.state, 4 /* ParseState.DefaultReduce */); + return { dom }; +} +const dialogEffect = /*@__PURE__*/StateEffect.define(); +const dialogField = /*@__PURE__*/StateField.define({ + create() { return true; }, + update(value, tr) { + for (let e of tr.effects) + if (e.is(dialogEffect)) + value = e.value; + return value; + }, + provide: f => showPanel.from(f, val => val ? createLineDialog : null) +}); +/** +Command that shows a dialog asking the user for a line number, and +when a valid position is provided, moves the cursor to that line. + +Supports line numbers, relative line offsets prefixed with `+` or +`-`, document percentages suffixed with `%`, and an optional +column position by adding `:` and a second number after the line +number. +*/ +const gotoLine = view => { + let panel = getPanel(view, createLineDialog); + if (!panel) { + let effects = [dialogEffect.of(true)]; + if (view.state.field(dialogField, false) == null) + effects.push(StateEffect.appendConfig.of([dialogField, baseTheme$1$1])); + view.dispatch({ effects }); + panel = getPanel(view, createLineDialog); } - /** - Restart the stack (put it back in its start state). Only safe - when this.stack.length == 3 (state is directly below the top - state). @internal - */ - restart() { - this.storeNode(0 /* Term.Err */, this.pos, this.pos, 4, true); - this.state = this.stack[0]; - this.stack.length = 0; + if (panel) + panel.dom.querySelector("input").select(); + return true; +}; +const baseTheme$1$1 = /*@__PURE__*/EditorView.baseTheme({ + ".cm-panel.cm-gotoLine": { + padding: "2px 6px 4px", + "& label": { fontSize: "80%" } } - /** - @internal - */ - sameState(other) { - if (this.state != other.state || this.stack.length != other.stack.length) - return false; - for (let i = 0; i < this.stack.length; i += 3) - if (this.stack[i] != other.stack[i]) - return false; - return true; +}); + +const defaultHighlightOptions = { + highlightWordAroundCursor: false, + minSelectionLength: 1, + maxMatches: 100, + wholeWords: false +}; +const highlightConfig = /*@__PURE__*/Facet.define({ + combine(options) { + return combineConfig(options, defaultHighlightOptions, { + highlightWordAroundCursor: (a, b) => a || b, + minSelectionLength: Math.min, + maxMatches: Math.min + }); } - /** - Get the parser used by this stack. - */ - get parser() { return this.p.parser; } - /** - Test whether a given dialect (by numeric ID, as exported from - the terms file) is enabled. - */ - dialectEnabled(dialectID) { return this.p.parser.dialect.flags[dialectID]; } - shiftContext(term, start) { - if (this.curContext) - this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start))); +}); +/** +This extension highlights text that matches the selection. It uses +the `"cm-selectionMatch"` class for the highlighting. When +`highlightWordAroundCursor` is enabled, the word at the cursor +itself will be highlighted with `"cm-selectionMatch-main"`. +*/ +function highlightSelectionMatches(options) { + let ext = [defaultTheme, matchHighlighter]; + return ext; +} +const matchDeco = /*@__PURE__*/Decoration.mark({ class: "cm-selectionMatch" }); +const mainMatchDeco = /*@__PURE__*/Decoration.mark({ class: "cm-selectionMatch cm-selectionMatch-main" }); +// Whether the characters directly outside the given positions are non-word characters +function insideWordBoundaries(check, state, from, to) { + return (from == 0 || check(state.sliceDoc(from - 1, from)) != CharCategory.Word) && + (to == state.doc.length || check(state.sliceDoc(to, to + 1)) != CharCategory.Word); +} +// Whether the characters directly at the given positions are word characters +function insideWord(check, state, from, to) { + return check(state.sliceDoc(from, from + 1)) == CharCategory.Word + && check(state.sliceDoc(to - 1, to)) == CharCategory.Word; +} +const matchHighlighter = /*@__PURE__*/ViewPlugin.fromClass(class { + constructor(view) { + this.decorations = this.getDeco(view); } - reduceContext(term, start) { - if (this.curContext) - this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start))); + update(update) { + if (update.selectionSet || update.docChanged || update.viewportChanged) + this.decorations = this.getDeco(update.view); + } + getDeco(view) { + let conf = view.state.facet(highlightConfig); + let { state } = view, sel = state.selection; + if (sel.ranges.length > 1) + return Decoration.none; + let range = sel.main, query, check = null; + if (range.empty) { + if (!conf.highlightWordAroundCursor) + return Decoration.none; + let word = state.wordAt(range.head); + if (!word) + return Decoration.none; + check = state.charCategorizer(range.head); + query = state.sliceDoc(word.from, word.to); + } + else { + let len = range.to - range.from; + if (len < conf.minSelectionLength || len > 200) + return Decoration.none; + if (conf.wholeWords) { + query = state.sliceDoc(range.from, range.to); // TODO: allow and include leading/trailing space? + check = state.charCategorizer(range.head); + if (!(insideWordBoundaries(check, state, range.from, range.to) && + insideWord(check, state, range.from, range.to))) + return Decoration.none; + } + else { + query = state.sliceDoc(range.from, range.to); + if (!query) + return Decoration.none; + } + } + let deco = []; + for (let part of view.visibleRanges) { + let cursor = new SearchCursor(state.doc, query, part.from, part.to); + while (!cursor.next().done) { + let { from, to } = cursor.value; + if (!check || insideWordBoundaries(check, state, from, to)) { + if (range.empty && from <= range.from && to >= range.to) + deco.push(mainMatchDeco.range(from, to)); + else if (from >= range.to || to <= range.from) + deco.push(matchDeco.range(from, to)); + if (deco.length > conf.maxMatches) + return Decoration.none; + } + } + } + return Decoration.set(deco); + } +}, { + decorations: v => v.decorations +}); +const defaultTheme = /*@__PURE__*/EditorView.baseTheme({ + ".cm-selectionMatch": { backgroundColor: "#99ff7780" }, + ".cm-searchMatch .cm-selectionMatch": { backgroundColor: "transparent" } +}); +// Select the words around the cursors. +const selectWord = ({ state, dispatch }) => { + let { selection } = state; + let newSel = EditorSelection.create(selection.ranges.map(range => state.wordAt(range.head) || EditorSelection.cursor(range.head)), selection.mainIndex); + if (newSel.eq(selection)) + return false; + dispatch(state.update({ selection: newSel })); + return true; +}; +// Find next occurrence of query relative to last cursor. Wrap around +// the document if there are no more matches. +function findNextOccurrence(state, query) { + let { main, ranges } = state.selection; + let word = state.wordAt(main.head), fullWord = word && word.from == main.from && word.to == main.to; + for (let cycled = false, cursor = new SearchCursor(state.doc, query, ranges[ranges.length - 1].to);;) { + cursor.next(); + if (cursor.done) { + if (cycled) + return null; + cursor = new SearchCursor(state.doc, query, 0, Math.max(0, ranges[ranges.length - 1].from - 1)); + cycled = true; + } + else { + if (cycled && ranges.some(r => r.from == cursor.value.from)) + continue; + if (fullWord) { + let word = state.wordAt(cursor.value.from); + if (!word || word.from != cursor.value.from || word.to != cursor.value.to) + continue; + } + return cursor.value; + } + } +} +/** +Select next occurrence of the current selection. Expand selection +to the surrounding word when the selection is empty. +*/ +const selectNextOccurrence = ({ state, dispatch }) => { + let { ranges } = state.selection; + if (ranges.some(sel => sel.from === sel.to)) + return selectWord({ state, dispatch }); + let searchedText = state.sliceDoc(ranges[0].from, ranges[0].to); + if (state.selection.ranges.some(r => state.sliceDoc(r.from, r.to) != searchedText)) + return false; + let range = findNextOccurrence(state, searchedText); + if (!range) + return false; + dispatch(state.update({ + selection: state.selection.addRange(EditorSelection.range(range.from, range.to), false), + effects: EditorView.scrollIntoView(range.to) + })); + return true; +}; + +const searchConfigFacet = /*@__PURE__*/Facet.define({ + combine(configs) { + return combineConfig(configs, { + top: false, + caseSensitive: false, + literal: false, + regexp: false, + wholeWord: false, + createPanel: view => new SearchPanel(view), + scrollToMatch: range => EditorView.scrollIntoView(range) + }); } +}); +/** +Add search state to the editor configuration, and optionally +configure the search extension. +([`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSearchPanel) will automatically +enable this if it isn't already on). +*/ +function search(config) { + return config ? [searchConfigFacet.of(config), searchExtensions] : searchExtensions; +} +/** +A search query. Part of the editor's search state. +*/ +class SearchQuery { /** - @internal + Create a query object. */ - emitContext() { - let last = this.buffer.length - 1; - if (last < 0 || this.buffer[last] != -3) - this.buffer.push(this.curContext.hash, this.pos, this.pos, -3); + constructor(config) { + this.search = config.search; + this.caseSensitive = !!config.caseSensitive; + this.literal = !!config.literal; + this.regexp = !!config.regexp; + this.replace = config.replace || ""; + this.valid = !!this.search && (!this.regexp || validRegExp(this.search)); + this.unquoted = this.unquote(this.search); + this.wholeWord = !!config.wholeWord; } /** @internal */ - emitLookAhead() { - let last = this.buffer.length - 1; - if (last < 0 || this.buffer[last] != -4) - this.buffer.push(this.lookAhead, this.pos, this.pos, -4); - } - updateContext(context) { - if (context != this.curContext.context) { - let newCx = new StackContext(this.curContext.tracker, context); - if (newCx.hash != this.curContext.hash) - this.emitContext(); - this.curContext = newCx; - } + unquote(text) { + return this.literal ? text : + text.replace(/\\([nrt\\])/g, (_, ch) => ch == "n" ? "\n" : ch == "r" ? "\r" : ch == "t" ? "\t" : "\\"); } /** - @internal + Compare this query to another query. */ - setLookAhead(lookAhead) { - if (lookAhead > this.lookAhead) { - this.emitLookAhead(); - this.lookAhead = lookAhead; - } + eq(other) { + return this.search == other.search && this.replace == other.replace && + this.caseSensitive == other.caseSensitive && this.regexp == other.regexp && + this.wholeWord == other.wholeWord; } /** @internal */ - close() { - if (this.curContext && this.curContext.tracker.strict) - this.emitContext(); - if (this.lookAhead > 0) - this.emitLookAhead(); + create() { + return this.regexp ? new RegExpQuery(this) : new StringQuery(this); + } + /** + Get a search cursor for this query, searching through the given + range in the given state. + */ + getCursor(state, from = 0, to) { + let st = state.doc ? state : EditorState.create({ doc: state }); + if (to == null) + to = st.doc.length; + return this.regexp ? regexpCursor(this, st, from, to) : stringCursor(this, st, from, to); } } -class StackContext { - constructor(tracker, context) { - this.tracker = tracker; - this.context = context; - this.hash = tracker.strict ? tracker.hash(context) : 0; +class QueryType { + constructor(spec) { + this.spec = spec; } } -// Used to cheaply run some reductions to scan ahead without mutating -// an entire stack -class SimulatedStack { - constructor(start) { - this.start = start; - this.state = start.state; - this.stack = start.stack; - this.base = this.stack.length; +function stringCursor(spec, state, from, to) { + return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined); +} +function stringWordTest(doc, categorizer) { + return (from, to, buf, bufPos) => { + if (bufPos > from || bufPos + buf.length < to) { + bufPos = Math.max(0, from - 2); + buf = doc.sliceString(bufPos, Math.min(doc.length, to + 2)); + } + return (categorizer(charBefore(buf, from - bufPos)) != CharCategory.Word || + categorizer(charAfter(buf, from - bufPos)) != CharCategory.Word) && + (categorizer(charAfter(buf, to - bufPos)) != CharCategory.Word || + categorizer(charBefore(buf, to - bufPos)) != CharCategory.Word); + }; +} +class StringQuery extends QueryType { + constructor(spec) { + super(spec); } - reduce(action) { - let term = action & 65535 /* Action.ValueMask */, depth = action >> 19 /* Action.ReduceDepthShift */; - if (depth == 0) { - if (this.stack == this.start.stack) - this.stack = this.stack.slice(); - this.stack.push(this.state, 0, 0); - this.base += 3; + nextMatch(state, curFrom, curTo) { + let cursor = stringCursor(this.spec, state, curTo, state.doc.length).nextOverlapping(); + if (cursor.done) + cursor = stringCursor(this.spec, state, 0, curFrom).nextOverlapping(); + return cursor.done ? null : cursor.value; + } + // Searching in reverse is, rather than implementing an inverted search + // cursor, done by scanning chunk after chunk forward. + prevMatchInRange(state, from, to) { + for (let pos = to;;) { + let start = Math.max(from, pos - 10000 /* FindPrev.ChunkSize */ - this.spec.unquoted.length); + let cursor = stringCursor(this.spec, state, start, pos), range = null; + while (!cursor.nextOverlapping().done) + range = cursor.value; + if (range) + return range; + if (start == from) + return null; + pos -= 10000 /* FindPrev.ChunkSize */; } - else { - this.base -= (depth - 1) * 3; + } + prevMatch(state, curFrom, curTo) { + return this.prevMatchInRange(state, 0, curFrom) || + this.prevMatchInRange(state, curTo, state.doc.length); + } + getReplacement(_result) { return this.spec.unquote(this.spec.replace); } + matchAll(state, limit) { + let cursor = stringCursor(this.spec, state, 0, state.doc.length), ranges = []; + while (!cursor.next().done) { + if (ranges.length >= limit) + return null; + ranges.push(cursor.value); } - let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true); - this.state = goto; + return ranges; } -} -// This is given to `Tree.build` to build a buffer, and encapsulates -// the parent-stack-walking necessary to read the nodes. -class StackBufferCursor { - constructor(stack, pos, index) { - this.stack = stack; - this.pos = pos; - this.index = index; - this.buffer = stack.buffer; - if (this.index == 0) - this.maybeNext(); + highlight(state, from, to, add) { + let cursor = stringCursor(this.spec, state, Math.max(0, from - this.spec.unquoted.length), Math.min(to + this.spec.unquoted.length, state.doc.length)); + while (!cursor.next().done) + add(cursor.value.from, cursor.value.to); } - static create(stack, pos = stack.bufferBase + stack.buffer.length) { - return new StackBufferCursor(stack, pos, pos - stack.bufferBase); +} +function regexpCursor(spec, state, from, to) { + return new RegExpCursor(state.doc, spec.search, { + ignoreCase: !spec.caseSensitive, + test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined + }, from, to); +} +function charBefore(str, index) { + return str.slice(findClusterBreak(str, index, false), index); +} +function charAfter(str, index) { + return str.slice(index, findClusterBreak(str, index)); +} +function regexpWordTest(categorizer) { + return (_from, _to, match) => !match[0].length || + (categorizer(charBefore(match.input, match.index)) != CharCategory.Word || + categorizer(charAfter(match.input, match.index)) != CharCategory.Word) && + (categorizer(charAfter(match.input, match.index + match[0].length)) != CharCategory.Word || + categorizer(charBefore(match.input, match.index + match[0].length)) != CharCategory.Word); +} +class RegExpQuery extends QueryType { + nextMatch(state, curFrom, curTo) { + let cursor = regexpCursor(this.spec, state, curTo, state.doc.length).next(); + if (cursor.done) + cursor = regexpCursor(this.spec, state, 0, curFrom).next(); + return cursor.done ? null : cursor.value; } - maybeNext() { - let next = this.stack.parent; - if (next != null) { - this.index = this.stack.bufferBase - next.bufferBase; - this.stack = next; - this.buffer = next.buffer; + prevMatchInRange(state, from, to) { + for (let size = 1;; size++) { + let start = Math.max(from, to - size * 10000 /* FindPrev.ChunkSize */); + let cursor = regexpCursor(this.spec, state, start, to), range = null; + while (!cursor.next().done) + range = cursor.value; + if (range && (start == from || range.from > start + 10)) + return range; + if (start == from) + return null; } } - get id() { return this.buffer[this.index - 4]; } - get start() { return this.buffer[this.index - 3]; } - get end() { return this.buffer[this.index - 2]; } - get size() { return this.buffer[this.index - 1]; } - next() { - this.index -= 4; - this.pos -= 4; - if (this.index == 0) - this.maybeNext(); + prevMatch(state, curFrom, curTo) { + return this.prevMatchInRange(state, 0, curFrom) || + this.prevMatchInRange(state, curTo, state.doc.length); } - fork() { - return new StackBufferCursor(this.stack, this.pos, this.index); + getReplacement(result) { + return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$" + : i == "&" ? result.match[0] + : i != "0" && +i < result.match.length ? result.match[i] + : m); } -} - -// See lezer-generator/src/encode.ts for comments about the encoding -// used here -function decodeArray(input, Type = Uint16Array) { - if (typeof input != "string") - return input; - let array = null; - for (let pos = 0, out = 0; pos < input.length;) { - let value = 0; - for (;;) { - let next = input.charCodeAt(pos++), stop = false; - if (next == 126 /* Encode.BigValCode */) { - value = 65535 /* Encode.BigVal */; - break; - } - if (next >= 92 /* Encode.Gap2 */) - next--; - if (next >= 34 /* Encode.Gap1 */) - next--; - let digit = next - 32 /* Encode.Start */; - if (digit >= 46 /* Encode.Base */) { - digit -= 46 /* Encode.Base */; - stop = true; - } - value += digit; - if (stop) - break; - value *= 46 /* Encode.Base */; + matchAll(state, limit) { + let cursor = regexpCursor(this.spec, state, 0, state.doc.length), ranges = []; + while (!cursor.next().done) { + if (ranges.length >= limit) + return null; + ranges.push(cursor.value); } - if (array) - array[out++] = value; - else - array = new Type(value); + return ranges; } - return array; -} - -class CachedToken { - constructor() { - this.start = -1; - this.value = -1; - this.end = -1; - this.extended = -1; - this.lookAhead = 0; - this.mask = 0; - this.context = 0; + highlight(state, from, to, add) { + let cursor = regexpCursor(this.spec, state, Math.max(0, from - 250 /* RegExp.HighlightMargin */), Math.min(to + 250 /* RegExp.HighlightMargin */, state.doc.length)); + while (!cursor.next().done) + add(cursor.value.from, cursor.value.to); } } -const nullToken = new CachedToken; /** -[Tokenizers](#lr.ExternalTokenizer) interact with the input -through this interface. It presents the input as a stream of -characters, tracking lookahead and hiding the complexity of -[ranges](#common.Parser.parse^ranges) from tokenizer code. +A state effect that updates the current search query. Note that +this only has an effect if the search state has been initialized +(by including [`search`](https://codemirror.net/6/docs/ref/#search.search) in your configuration or +by running [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSearchPanel) at least +once). */ -class InputStream { - /** - @internal - */ - constructor( - /** - @internal - */ - input, - /** - @internal - */ - ranges) { - this.input = input; - this.ranges = ranges; - /** - @internal - */ - this.chunk = ""; - /** - @internal - */ - this.chunkOff = 0; - /** - Backup chunk - */ - this.chunk2 = ""; - this.chunk2Pos = 0; - /** - The character code of the next code unit in the input, or -1 - when the stream is at the end of the input. - */ - this.next = -1; - /** - @internal - */ - this.token = nullToken; - this.rangeIndex = 0; - this.pos = this.chunkPos = ranges[0].from; - this.range = ranges[0]; - this.end = ranges[ranges.length - 1].to; - this.readNext(); - } - /** - @internal - */ - resolveOffset(offset, assoc) { - let range = this.range, index = this.rangeIndex; - let pos = this.pos + offset; - while (pos < range.from) { - if (!index) - return null; - let next = this.ranges[--index]; - pos -= range.from - next.to; - range = next; - } - while (assoc < 0 ? pos > range.to : pos >= range.to) { - if (index == this.ranges.length - 1) - return null; - let next = this.ranges[++index]; - pos += next.from - range.to; - range = next; - } - return pos; - } - /** - @internal - */ - clipPos(pos) { - if (pos >= this.range.from && pos < this.range.to) - return pos; - for (let range of this.ranges) - if (range.to > pos) - return Math.max(pos, range.from); - return this.end; - } - /** - Look at a code unit near the stream position. `.peek(0)` equals - `.next`, `.peek(-1)` gives you the previous character, and so - on. - - Note that looking around during tokenizing creates dependencies - on potentially far-away content, which may reduce the - effectiveness incremental parsing—when looking forward—or even - cause invalid reparses when looking backward more than 25 code - units, since the library does not track lookbehind. - */ - peek(offset) { - let idx = this.chunkOff + offset, pos, result; - if (idx >= 0 && idx < this.chunk.length) { - pos = this.pos + offset; - result = this.chunk.charCodeAt(idx); - } - else { - let resolved = this.resolveOffset(offset, 1); - if (resolved == null) - return -1; - pos = resolved; - if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) { - result = this.chunk2.charCodeAt(pos - this.chunk2Pos); - } - else { - let i = this.rangeIndex, range = this.range; - while (range.to <= pos) - range = this.ranges[++i]; - this.chunk2 = this.input.chunk(this.chunk2Pos = pos); - if (pos + this.chunk2.length > range.to) - this.chunk2 = this.chunk2.slice(0, range.to - pos); - result = this.chunk2.charCodeAt(0); - } +const setSearchQuery = /*@__PURE__*/StateEffect.define(); +const togglePanel$1 = /*@__PURE__*/StateEffect.define(); +const searchState = /*@__PURE__*/StateField.define({ + create(state) { + return new SearchState(defaultQuery(state).create(), null); + }, + update(value, tr) { + for (let effect of tr.effects) { + if (effect.is(setSearchQuery)) + value = new SearchState(effect.value.create(), value.panel); + else if (effect.is(togglePanel$1)) + value = new SearchState(value.query, effect.value ? createSearchPanel : null); } - if (pos >= this.token.lookAhead) - this.token.lookAhead = pos + 1; - return result; + return value; + }, + provide: f => showPanel.from(f, val => val.panel) +}); +class SearchState { + constructor(query, panel) { + this.query = query; + this.panel = panel; } - /** - Accept a token. By default, the end of the token is set to the - current stream position, but you can pass an offset (relative to - the stream position) to change that. - */ - acceptToken(token, endOffset = 0) { - let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos; - if (end == null || end < this.token.start) - throw new RangeError("Token end out of bounds"); - this.token.value = token; - this.token.end = end; +} +const matchMark = /*@__PURE__*/Decoration.mark({ class: "cm-searchMatch" }), selectedMatchMark = /*@__PURE__*/Decoration.mark({ class: "cm-searchMatch cm-searchMatch-selected" }); +const searchHighlighter = /*@__PURE__*/ViewPlugin.fromClass(class { + constructor(view) { + this.view = view; + this.decorations = this.highlight(view.state.field(searchState)); } - /** - Accept a token ending at a specific given position. - */ - acceptTokenTo(token, endPos) { - this.token.value = token; - this.token.end = endPos; + update(update) { + let state = update.state.field(searchState); + if (state != update.startState.field(searchState) || update.docChanged || update.selectionSet || update.viewportChanged) + this.decorations = this.highlight(state); } - getChunk() { - if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) { - let { chunk, chunkPos } = this; - this.chunk = this.chunk2; - this.chunkPos = this.chunk2Pos; - this.chunk2 = chunk; - this.chunk2Pos = chunkPos; - this.chunkOff = this.pos - this.chunkPos; - } - else { - this.chunk2 = this.chunk; - this.chunk2Pos = this.chunkPos; - let nextChunk = this.input.chunk(this.pos); - let end = this.pos + nextChunk.length; - this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk; - this.chunkPos = this.pos; - this.chunkOff = 0; + highlight({ query, panel }) { + if (!panel || !query.spec.valid) + return Decoration.none; + let { view } = this; + let builder = new RangeSetBuilder(); + for (let i = 0, ranges = view.visibleRanges, l = ranges.length; i < l; i++) { + let { from, to } = ranges[i]; + while (i < l - 1 && to > ranges[i + 1].from - 2 * 250 /* RegExp.HighlightMargin */) + to = ranges[++i].to; + query.highlight(view.state, from, to, (from, to) => { + let selected = view.state.selection.ranges.some(r => r.from == from && r.to == to); + builder.add(from, to, selected ? selectedMatchMark : matchMark); + }); } + return builder.finish(); } - readNext() { - if (this.chunkOff >= this.chunk.length) { - this.getChunk(); - if (this.chunkOff == this.chunk.length) - return this.next = -1; - } - return this.next = this.chunk.charCodeAt(this.chunkOff); +}, { + decorations: v => v.decorations +}); +function searchCommand(f) { + return view => { + let state = view.state.field(searchState, false); + return state && state.query.spec.valid ? f(view, state) : openSearchPanel(view); + }; +} +/** +Open the search panel if it isn't already open, and move the +selection to the first match after the current main selection. +Will wrap around to the start of the document when it reaches the +end. +*/ +const findNext = /*@__PURE__*/searchCommand((view, { query }) => { + let { to } = view.state.selection.main; + let next = query.nextMatch(view.state, to, to); + if (!next) + return false; + let selection = EditorSelection.single(next.from, next.to); + let config = view.state.facet(searchConfigFacet); + view.dispatch({ + selection, + effects: [announceMatch(view, next), config.scrollToMatch(selection.main, view)], + userEvent: "select.search" + }); + selectSearchInput(view); + return true; +}); +/** +Move the selection to the previous instance of the search query, +before the current main selection. Will wrap past the start +of the document to start searching at the end again. +*/ +const findPrevious = /*@__PURE__*/searchCommand((view, { query }) => { + let { state } = view, { from } = state.selection.main; + let prev = query.prevMatch(state, from, from); + if (!prev) + return false; + let selection = EditorSelection.single(prev.from, prev.to); + let config = view.state.facet(searchConfigFacet); + view.dispatch({ + selection, + effects: [announceMatch(view, prev), config.scrollToMatch(selection.main, view)], + userEvent: "select.search" + }); + selectSearchInput(view); + return true; +}); +/** +Select all instances of the search query. +*/ +const selectMatches = /*@__PURE__*/searchCommand((view, { query }) => { + let ranges = query.matchAll(view.state, 1000); + if (!ranges || !ranges.length) + return false; + view.dispatch({ + selection: EditorSelection.create(ranges.map(r => EditorSelection.range(r.from, r.to))), + userEvent: "select.search.matches" + }); + return true; +}); +/** +Select all instances of the currently selected text. +*/ +const selectSelectionMatches = ({ state, dispatch }) => { + let sel = state.selection; + if (sel.ranges.length > 1 || sel.main.empty) + return false; + let { from, to } = sel.main; + let ranges = [], main = 0; + for (let cur = new SearchCursor(state.doc, state.sliceDoc(from, to)); !cur.next().done;) { + if (ranges.length > 1000) + return false; + if (cur.value.from == from) + main = ranges.length; + ranges.push(EditorSelection.range(cur.value.from, cur.value.to)); } - /** - Move the stream forward N (defaults to 1) code units. Returns - the new value of [`next`](#lr.InputStream.next). - */ - advance(n = 1) { - this.chunkOff += n; - while (this.pos + n >= this.range.to) { - if (this.rangeIndex == this.ranges.length - 1) - return this.setDone(); - n -= this.range.to - this.pos; - this.range = this.ranges[++this.rangeIndex]; - this.pos = this.range.from; - } - this.pos += n; - if (this.pos >= this.token.lookAhead) - this.token.lookAhead = this.pos + 1; - return this.readNext(); - } - setDone() { - this.pos = this.chunkPos = this.end; - this.range = this.ranges[this.rangeIndex = this.ranges.length - 1]; - this.chunk = ""; - return this.next = -1; - } - /** - @internal - */ - reset(pos, token) { - if (token) { - this.token = token; - token.start = pos; - token.lookAhead = pos + 1; - token.value = token.extended = -1; - } - else { - this.token = nullToken; - } - if (this.pos != pos) { - this.pos = pos; - if (pos == this.end) { - this.setDone(); - return this; - } - while (pos < this.range.from) - this.range = this.ranges[--this.rangeIndex]; - while (pos >= this.range.to) - this.range = this.ranges[++this.rangeIndex]; - if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) { - this.chunkOff = pos - this.chunkPos; - } - else { - this.chunk = ""; - this.chunkOff = 0; - } - this.readNext(); - } - return this; - } - /** - @internal - */ - read(from, to) { - if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length) - return this.chunk.slice(from - this.chunkPos, to - this.chunkPos); - if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length) - return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos); - if (from >= this.range.from && to <= this.range.to) - return this.input.read(from, to); - let result = ""; - for (let r of this.ranges) { - if (r.from >= to) - break; - if (r.to > from) - result += this.input.read(Math.max(r.from, from), Math.min(r.to, to)); - } - return result; - } -} + dispatch(state.update({ + selection: EditorSelection.create(ranges, main), + userEvent: "select.search.matches" + })); + return true; +}; /** -@internal +Replace the current match of the search query. */ -class TokenGroup { - constructor(data, id) { - this.data = data; - this.id = id; +const replaceNext = /*@__PURE__*/searchCommand((view, { query }) => { + let { state } = view, { from, to } = state.selection.main; + if (state.readOnly) + return false; + let next = query.nextMatch(state, from, from); + if (!next) + return false; + let changes = [], selection, replacement; + let effects = []; + if (next.from == from && next.to == to) { + replacement = state.toText(query.getReplacement(next)); + changes.push({ from: next.from, to: next.to, insert: replacement }); + next = query.nextMatch(state, next.from, next.to); + effects.push(EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + ".")); } - token(input, stack) { - let { parser } = stack.p; - readToken(this.data, input, stack, this.id, parser.data, parser.tokenPrecTable); + if (next) { + let off = changes.length == 0 || changes[0].from >= next.to ? 0 : next.to - next.from - replacement.length; + selection = EditorSelection.single(next.from - off, next.to - off); + effects.push(announceMatch(view, next)); + effects.push(state.facet(searchConfigFacet).scrollToMatch(selection.main, view)); } + view.dispatch({ + changes, selection, effects, + userEvent: "input.replace" + }); + return true; +}); +/** +Replace all instances of the search query with the given +replacement. +*/ +const replaceAll = /*@__PURE__*/searchCommand((view, { query }) => { + if (view.state.readOnly) + return false; + let changes = query.matchAll(view.state, 1e9).map(match => { + let { from, to } = match; + return { from, to, insert: query.getReplacement(match) }; + }); + if (!changes.length) + return false; + let announceText = view.state.phrase("replaced $ matches", changes.length) + "."; + view.dispatch({ + changes, + effects: EditorView.announce.of(announceText), + userEvent: "input.replace.all" + }); + return true; +}); +function createSearchPanel(view) { + return view.state.facet(searchConfigFacet).createPanel(view); +} +function defaultQuery(state, fallback) { + var _a, _b, _c, _d, _e; + let sel = state.selection.main; + let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to); + if (fallback && !selText) + return fallback; + let config = state.facet(searchConfigFacet); + return new SearchQuery({ + search: ((_a = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _a !== void 0 ? _a : config.literal) ? selText : selText.replace(/\n/g, "\\n"), + caseSensitive: (_b = fallback === null || fallback === void 0 ? void 0 : fallback.caseSensitive) !== null && _b !== void 0 ? _b : config.caseSensitive, + literal: (_c = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _c !== void 0 ? _c : config.literal, + regexp: (_d = fallback === null || fallback === void 0 ? void 0 : fallback.regexp) !== null && _d !== void 0 ? _d : config.regexp, + wholeWord: (_e = fallback === null || fallback === void 0 ? void 0 : fallback.wholeWord) !== null && _e !== void 0 ? _e : config.wholeWord + }); +} +function getSearchInput(view) { + let panel = getPanel(view, createSearchPanel); + return panel && panel.dom.querySelector("[main-field]"); +} +function selectSearchInput(view) { + let input = getSearchInput(view); + if (input && input == view.root.activeElement) + input.select(); } -TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false; /** -@hide +Make sure the search panel is open and focused. */ -class LocalTokenGroup { - constructor(data, precTable, elseToken) { - this.precTable = precTable; - this.elseToken = elseToken; - this.data = typeof data == "string" ? decodeArray(data) : data; - } - token(input, stack) { - let start = input.pos, skipped = 0; - for (;;) { - let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1); - readToken(this.data, input, stack, 0, this.data, this.precTable); - if (input.token.value > -1) - break; - if (this.elseToken == null) - return; - if (!atEof) - skipped++; - if (nextPos == null) - break; - input.reset(nextPos, input.token); - } - if (skipped) { - input.reset(start, input.token); - input.acceptToken(this.elseToken, skipped); +const openSearchPanel = view => { + let state = view.state.field(searchState, false); + if (state && state.panel) { + let searchInput = getSearchInput(view); + if (searchInput && searchInput != view.root.activeElement) { + let query = defaultQuery(view.state, state.query.spec); + if (query.valid) + view.dispatch({ effects: setSearchQuery.of(query) }); + searchInput.focus(); + searchInput.select(); } } -} -LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false; + else { + view.dispatch({ effects: [ + togglePanel$1.of(true), + state ? setSearchQuery.of(defaultQuery(view.state, state.query.spec)) : StateEffect.appendConfig.of(searchExtensions) + ] }); + } + return true; +}; /** -`@external tokens` declarations in the grammar should resolve to -an instance of this class. +Close the search panel. */ -class ExternalTokenizer { - /** - Create a tokenizer. The first argument is the function that, - given an input stream, scans for the types of tokens it - recognizes at the stream's position, and calls - [`acceptToken`](#lr.InputStream.acceptToken) when it finds - one. - */ - constructor( - /** - @internal - */ - token, options = {}) { - this.token = token; - this.contextual = !!options.contextual; - this.fallback = !!options.fallback; - this.extend = !!options.extend; - } -} -// Tokenizer data is stored a big uint16 array containing, for each -// state: -// -// - A group bitmask, indicating what token groups are reachable from -// this state, so that paths that can only lead to tokens not in -// any of the current groups can be cut off early. -// -// - The position of the end of the state's sequence of accepting -// tokens -// -// - The number of outgoing edges for the state -// -// - The accepting tokens, as (token id, group mask) pairs -// -// - The outgoing edges, as (start character, end character, state -// index) triples, with end character being exclusive -// -// This function interprets that data, running through a stream as -// long as new states with the a matching group mask can be reached, -// and updating `input.token` when it matches a token. -function readToken(data, input, stack, group, precTable, precOffset) { - let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser; - scan: for (;;) { - if ((groupMask & data[state]) == 0) - break; - let accEnd = data[state + 1]; - // Check whether this state can lead to a token in the current group - // Accept tokens in this state, possibly overwriting - // lower-precedence / shorter tokens - for (let i = state + 3; i < accEnd; i += 2) - if ((data[i + 1] & groupMask) > 0) { - let term = data[i]; - if (dialect.allows(term) && - (input.token.value == -1 || input.token.value == term || - overrides(term, input.token.value, precTable, precOffset))) { - input.acceptToken(term); - break; - } - } - let next = input.next, low = 0, high = data[state + 2]; - // Special case for EOF - if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535 /* Seq.End */) { - state = data[accEnd + high * 3 - 1]; - continue scan; +const closeSearchPanel = view => { + let state = view.state.field(searchState, false); + if (!state || !state.panel) + return false; + let panel = getPanel(view, createSearchPanel); + if (panel && panel.dom.contains(view.root.activeElement)) + view.focus(); + view.dispatch({ effects: togglePanel$1.of(false) }); + return true; +}; +/** +Default search-related key bindings. + + - Mod-f: [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSearchPanel) + - F3, Mod-g: [`findNext`](https://codemirror.net/6/docs/ref/#search.findNext) + - Shift-F3, Shift-Mod-g: [`findPrevious`](https://codemirror.net/6/docs/ref/#search.findPrevious) + - Mod-Alt-g: [`gotoLine`](https://codemirror.net/6/docs/ref/#search.gotoLine) + - Mod-d: [`selectNextOccurrence`](https://codemirror.net/6/docs/ref/#search.selectNextOccurrence) +*/ +const searchKeymap = [ + { key: "Mod-f", run: openSearchPanel, scope: "editor search-panel" }, + { key: "F3", run: findNext, shift: findPrevious, scope: "editor search-panel", preventDefault: true }, + { key: "Mod-g", run: findNext, shift: findPrevious, scope: "editor search-panel", preventDefault: true }, + { key: "Escape", run: closeSearchPanel, scope: "editor search-panel" }, + { key: "Mod-Shift-l", run: selectSelectionMatches }, + { key: "Mod-Alt-g", run: gotoLine }, + { key: "Mod-d", run: selectNextOccurrence, preventDefault: true }, +]; +class SearchPanel { + constructor(view) { + this.view = view; + let query = this.query = view.state.field(searchState).query.spec; + this.commit = this.commit.bind(this); + this.searchField = crelt("input", { + value: query.search, + placeholder: phrase(view, "Find"), + "aria-label": phrase(view, "Find"), + class: "cm-textfield", + name: "search", + form: "", + "main-field": "true", + onchange: this.commit, + onkeyup: this.commit + }); + this.replaceField = crelt("input", { + value: query.replace, + placeholder: phrase(view, "Replace"), + "aria-label": phrase(view, "Replace"), + class: "cm-textfield", + name: "replace", + form: "", + onchange: this.commit, + onkeyup: this.commit + }); + this.caseField = crelt("input", { + type: "checkbox", + name: "case", + form: "", + checked: query.caseSensitive, + onchange: this.commit + }); + this.reField = crelt("input", { + type: "checkbox", + name: "re", + form: "", + checked: query.regexp, + onchange: this.commit + }); + this.wordField = crelt("input", { + type: "checkbox", + name: "word", + form: "", + checked: query.wholeWord, + onchange: this.commit + }); + function button(name, onclick, content) { + return crelt("button", { class: "cm-button", name, onclick, type: "button" }, content); } - // Do a binary search on the state's edges - for (; low < high;) { - let mid = (low + high) >> 1; - let index = accEnd + mid + (mid << 1); - let from = data[index], to = data[index + 1] || 0x10000; - if (next < from) - high = mid; - else if (next >= to) - low = mid + 1; - else { - state = data[index + 2]; - input.advance(); - continue scan; - } + this.dom = crelt("div", { onkeydown: (e) => this.keydown(e), class: "cm-search" }, [ + this.searchField, + button("next", () => findNext(view), [phrase(view, "next")]), + button("prev", () => findPrevious(view), [phrase(view, "previous")]), + button("select", () => selectMatches(view), [phrase(view, "all")]), + crelt("label", null, [this.caseField, phrase(view, "match case")]), + crelt("label", null, [this.reField, phrase(view, "regexp")]), + crelt("label", null, [this.wordField, phrase(view, "by word")]), + ...view.state.readOnly ? [] : [ + crelt("br"), + this.replaceField, + button("replace", () => replaceNext(view), [phrase(view, "replace")]), + button("replaceAll", () => replaceAll(view), [phrase(view, "replace all")]) + ], + crelt("button", { + name: "close", + onclick: () => closeSearchPanel(view), + "aria-label": phrase(view, "close"), + type: "button" + }, ["×"]) + ]); + } + commit() { + let query = new SearchQuery({ + search: this.searchField.value, + caseSensitive: this.caseField.checked, + regexp: this.reField.checked, + wholeWord: this.wordField.checked, + replace: this.replaceField.value, + }); + if (!query.eq(this.query)) { + this.query = query; + this.view.dispatch({ effects: setSearchQuery.of(query) }); } - break; } -} -function findOffset(data, start, term) { - for (let i = start, next; (next = data[i]) != 65535 /* Seq.End */; i++) - if (next == term) - return i - start; - return -1; -} -function overrides(token, prev, tableData, tableOffset) { - let iPrev = findOffset(tableData, tableOffset, prev); - return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev; -} - -// Environment variable used to control console output -const verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG); -let stackIDs = null; -function cutAt(tree, pos, side) { - let cursor = tree.cursor(IterMode.IncludeAnonymous); - cursor.moveTo(pos); - for (;;) { - if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos))) - for (;;) { - if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError) - return side < 0 ? Math.max(0, Math.min(cursor.to - 1, pos - 25 /* Lookahead.Margin */)) - : Math.min(tree.length, Math.max(cursor.from + 1, pos + 25 /* Lookahead.Margin */)); - if (side < 0 ? cursor.prevSibling() : cursor.nextSibling()) - break; - if (!cursor.parent()) - return side < 0 ? 0 : tree.length; + keydown(e) { + if (runScopeHandlers(this.view, e, "search-panel")) { + e.preventDefault(); + } + else if (e.keyCode == 13 && e.target == this.searchField) { + e.preventDefault(); + (e.shiftKey ? findPrevious : findNext)(this.view); + } + else if (e.keyCode == 13 && e.target == this.replaceField) { + e.preventDefault(); + replaceNext(this.view); + } + } + update(update) { + for (let tr of update.transactions) + for (let effect of tr.effects) { + if (effect.is(setSearchQuery) && !effect.value.eq(this.query)) + this.setQuery(effect.value); } } + setQuery(query) { + this.query = query; + this.searchField.value = query.search; + this.replaceField.value = query.replace; + this.caseField.checked = query.caseSensitive; + this.reField.checked = query.regexp; + this.wordField.checked = query.wholeWord; + } + mount() { + this.searchField.select(); + } + get pos() { return 80; } + get top() { return this.view.state.facet(searchConfigFacet).top; } } -class FragmentCursor { - constructor(fragments, nodeSet) { - this.fragments = fragments; - this.nodeSet = nodeSet; - this.i = 0; - this.fragment = null; - this.safeFrom = -1; - this.safeTo = -1; - this.trees = []; - this.start = []; - this.index = []; - this.nextFragment(); +function phrase(view, phrase) { return view.state.phrase(phrase); } +const AnnounceMargin = 30; +const Break = /[\s\.,:;?!]/; +function announceMatch(view, { from, to }) { + let line = view.state.doc.lineAt(from), lineEnd = view.state.doc.lineAt(to).to; + let start = Math.max(line.from, from - AnnounceMargin), end = Math.min(lineEnd, to + AnnounceMargin); + let text = view.state.sliceDoc(start, end); + if (start != line.from) { + for (let i = 0; i < AnnounceMargin; i++) + if (!Break.test(text[i + 1]) && Break.test(text[i])) { + text = text.slice(i); + break; + } } - nextFragment() { - let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++]; - if (fr) { - this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from; - this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to; - while (this.trees.length) { - this.trees.pop(); - this.start.pop(); - this.index.pop(); + if (end != lineEnd) { + for (let i = text.length - 1; i > text.length - AnnounceMargin; i--) + if (!Break.test(text[i - 1]) && Break.test(text[i])) { + text = text.slice(0, i); + break; } - this.trees.push(fr.tree); - this.start.push(-fr.offset); - this.index.push(0); - this.nextStart = this.safeFrom; - } - else { - this.nextStart = 1e9; - } } - // `pos` must be >= any previously given `pos` for this cursor - nodeAt(pos) { - if (pos < this.nextStart) - return null; - while (this.fragment && this.safeTo <= pos) - this.nextFragment(); - if (!this.fragment) - return null; - for (;;) { - let last = this.trees.length - 1; - if (last < 0) { // End of tree - this.nextFragment(); - return null; - } - let top = this.trees[last], index = this.index[last]; - if (index == top.children.length) { - this.trees.pop(); - this.start.pop(); - this.index.pop(); - continue; - } - let next = top.children[index]; - let start = this.start[last] + top.positions[index]; - if (start > pos) { - this.nextStart = start; - return null; - } - if (next instanceof Tree) { - if (start == pos) { - if (start < this.safeFrom) - return null; - let end = start + next.length; - if (end <= this.safeTo) { - let lookAhead = next.prop(NodeProp.lookAhead); - if (!lookAhead || end + lookAhead < this.fragment.to) - return next; - } - } - this.index[last]++; - if (start + next.length >= Math.max(this.safeFrom, pos)) { // Enter this node - this.trees.push(next); - this.start.push(start); - this.index.push(0); - } - } - else { - this.index[last]++; - this.nextStart = start + next.length; - } + return EditorView.announce.of(`${view.state.phrase("current match")}. ${text} ${view.state.phrase("on line")} ${line.number}.`); +} +const baseTheme$2 = /*@__PURE__*/EditorView.baseTheme({ + ".cm-panel.cm-search": { + padding: "2px 6px 4px", + position: "relative", + "& [name=close]": { + position: "absolute", + top: "0", + right: "4px", + backgroundColor: "inherit", + border: "none", + font: "inherit", + padding: 0, + margin: 0 + }, + "& input, & button, & label": { + margin: ".2em .6em .2em 0" + }, + "& input[type=checkbox]": { + marginRight: ".2em" + }, + "& label": { + fontSize: "80%", + whiteSpace: "pre" } + }, + "&light .cm-searchMatch": { backgroundColor: "#ffff0054" }, + "&dark .cm-searchMatch": { backgroundColor: "#00ffff8a" }, + "&light .cm-searchMatch-selected": { backgroundColor: "#ff6a0054" }, + "&dark .cm-searchMatch-selected": { backgroundColor: "#ff00ff8a" } +}); +const searchExtensions = [ + searchState, + /*@__PURE__*/Prec.low(searchHighlighter), + baseTheme$2 +]; + +/** +A parse stack. These are used internally by the parser to track +parsing progress. They also provide some properties and methods +that external code such as a tokenizer can use to get information +about the parse state. +*/ +class Stack { + /** + @internal + */ + constructor( + /** + The parse that this stack is part of @internal + */ + p, + /** + Holds state, input pos, buffer index triplets for all but the + top state @internal + */ + stack, + /** + The current parse state @internal + */ + state, + // The position at which the next reduce should take place. This + // can be less than `this.pos` when skipped expressions have been + // added to the stack (which should be moved outside of the next + // reduction) + /** + @internal + */ + reducePos, + /** + The input position up to which this stack has parsed. + */ + pos, + /** + The dynamic score of the stack, including dynamic precedence + and error-recovery penalties + @internal + */ + score, + // The output buffer. Holds (type, start, end, size) quads + // representing nodes created by the parser, where `size` is + // amount of buffer array entries covered by this node. + /** + @internal + */ + buffer, + // The base offset of the buffer. When stacks are split, the split + // instance shared the buffer history with its parent up to + // `bufferBase`, which is the absolute offset (including the + // offset of previous splits) into the buffer at which this stack + // starts writing. + /** + @internal + */ + bufferBase, + /** + @internal + */ + curContext, + /** + @internal + */ + lookAhead = 0, + // A parent stack from which this was split off, if any. This is + // set up so that it always points to a stack that has some + // additional buffer content, never to a stack with an equal + // `bufferBase`. + /** + @internal + */ + parent) { + this.p = p; + this.stack = stack; + this.state = state; + this.reducePos = reducePos; + this.pos = pos; + this.score = score; + this.buffer = buffer; + this.bufferBase = bufferBase; + this.curContext = curContext; + this.lookAhead = lookAhead; + this.parent = parent; } -} -class TokenCache { - constructor(parser, stream) { - this.stream = stream; - this.tokens = []; - this.mainToken = null; - this.actions = []; - this.tokens = parser.tokenizers.map(_ => new CachedToken); + /** + @internal + */ + toString() { + return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`; } - getActions(stack) { - let actionIndex = 0; - let main = null; - let { parser } = stack.p, { tokenizers } = parser; - let mask = parser.stateSlot(stack.state, 3 /* ParseState.TokenizerMask */); - let context = stack.curContext ? stack.curContext.hash : 0; - let lookAhead = 0; - for (let i = 0; i < tokenizers.length; i++) { - if (((1 << i) & mask) == 0) - continue; - let tokenizer = tokenizers[i], token = this.tokens[i]; - if (main && !tokenizer.fallback) - continue; - if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) { - this.updateCachedToken(token, tokenizer, stack); - token.mask = mask; - token.context = context; - } - if (token.lookAhead > token.end + 25 /* Lookahead.Margin */) - lookAhead = Math.max(token.lookAhead, lookAhead); - if (token.value != 0 /* Term.Err */) { - let startIndex = actionIndex; - if (token.extended > -1) - actionIndex = this.addActions(stack, token.extended, token.end, actionIndex); - actionIndex = this.addActions(stack, token.value, token.end, actionIndex); - if (!tokenizer.extend) { - main = token; - if (actionIndex > startIndex) - break; - } - } - } - while (this.actions.length > actionIndex) - this.actions.pop(); - if (lookAhead) - stack.setLookAhead(lookAhead); - if (!main && stack.pos == this.stream.end) { - main = new CachedToken; - main.value = stack.p.parser.eofTerm; - main.start = main.end = stack.pos; - actionIndex = this.addActions(stack, main.value, main.end, actionIndex); - } - this.mainToken = main; - return this.actions; + // Start an empty stack + /** + @internal + */ + static start(p, state, pos = 0) { + let cx = p.parser.context; + return new Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null); } - getMainToken(stack) { - if (this.mainToken) - return this.mainToken; - let main = new CachedToken, { pos, p } = stack; - main.start = pos; - main.end = Math.min(pos + 1, p.stream.end); - main.value = pos == p.stream.end ? p.parser.eofTerm : 0 /* Term.Err */; - return main; + /** + The stack's current [context](#lr.ContextTracker) value, if + any. Its type will depend on the context tracker's type + parameter, or it will be `null` if there is no context + tracker. + */ + get context() { return this.curContext ? this.curContext.context : null; } + // Push a state onto the stack, tracking its start position as well + // as the buffer base at that point. + /** + @internal + */ + pushState(state, start) { + this.stack.push(this.state, start, this.bufferBase + this.buffer.length); + this.state = state; } - updateCachedToken(token, tokenizer, stack) { - let start = this.stream.clipPos(stack.pos); - tokenizer.token(this.stream.reset(start, token), stack); - if (token.value > -1) { - let { parser } = stack.p; - for (let i = 0; i < parser.specialized.length; i++) - if (parser.specialized[i] == token.value) { - let result = parser.specializers[i](this.stream.read(token.start, token.end), stack); - if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) { - if ((result & 1) == 0 /* Specialize.Specialize */) - token.value = result >> 1; - else - token.extended = result >> 1; - break; - } - } + // Apply a reduce action + /** + @internal + */ + reduce(action) { + var _a; + let depth = action >> 19 /* Action.ReduceDepthShift */, type = action & 65535 /* Action.ValueMask */; + let { parser } = this.p; + if (this.reducePos < this.pos - 25 /* Lookahead.Margin */) + this.setLookAhead(this.pos); + let dPrec = parser.dynamicPrecedence(type); + if (dPrec) + this.score += dPrec; + if (depth == 0) { + this.pushState(parser.getGoto(this.state, type, true), this.reducePos); + // Zero-depth reductions are a special case—they add stuff to + // the stack without popping anything off. + if (type < parser.minRepeatTerm) + this.storeNode(type, this.reducePos, this.reducePos, 4, true); + this.reduceContext(type, this.reducePos); + return; + } + // Find the base index into `this.stack`, content after which will + // be dropped. Note that with `StayFlag` reductions we need to + // consume two extra frames (the dummy parent node for the skipped + // expression and the state that we'll be staying in, which should + // be moved to `this.state`). + let base = this.stack.length - ((depth - 1) * 3) - (action & 262144 /* Action.StayFlag */ ? 6 : 0); + let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start; + // This is a kludge to try and detect overly deep left-associative + // trees, which will not increase the parse stack depth and thus + // won't be caught by the regular stack-depth limit check. + if (size >= 2000 /* Recover.MinBigReduction */ && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) { + if (start == this.p.lastBigReductionStart) { + this.p.bigReductionCount++; + this.p.lastBigReductionSize = size; + } + else if (this.p.lastBigReductionSize < size) { + this.p.bigReductionCount = 1; + this.p.lastBigReductionStart = start; + this.p.lastBigReductionSize = size; + } + } + let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase; + // Store normal terms or `R -> R R` repeat reductions + if (type < parser.minRepeatTerm || (action & 131072 /* Action.RepeatFlag */)) { + let pos = parser.stateFlag(this.state, 1 /* StateFlag.Skipped */) ? this.pos : this.reducePos; + this.storeNode(type, start, pos, count + 4, true); + } + if (action & 262144 /* Action.StayFlag */) { + this.state = this.stack[base]; } else { - token.value = 0 /* Term.Err */; - token.end = this.stream.clipPos(start + 1); + let baseStateID = this.stack[base - 3]; + this.state = parser.getGoto(baseStateID, type, true); } + while (this.stack.length > base) + this.stack.pop(); + this.reduceContext(type, start); } - putAction(action, token, end, index) { - // Don't add duplicate actions - for (let i = 0; i < index; i += 3) - if (this.actions[i] == action) - return index; - this.actions[index++] = action; - this.actions[index++] = token; - this.actions[index++] = end; - return index; - } - addActions(stack, token, end, index) { - let { state } = stack, { parser } = stack.p, { data } = parser; - for (let set = 0; set < 2; set++) { - for (let i = parser.stateSlot(state, set ? 2 /* ParseState.Skip */ : 1 /* ParseState.Actions */);; i += 3) { - if (data[i] == 65535 /* Seq.End */) { - if (data[i + 1] == 1 /* Seq.Next */) { - i = pair(data, i + 2); - } - else { - if (index == 0 && data[i + 1] == 2 /* Seq.Other */) - index = this.putAction(pair(data, i + 2), token, end, index); - break; - } + // Shift a value into the buffer + /** + @internal + */ + storeNode(term, start, end, size = 4, isReduce = false) { + if (term == 0 /* Term.Err */ && + (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) { + // Try to omit/merge adjacent error nodes + let cur = this, top = this.buffer.length; + if (top == 0 && cur.parent) { + top = cur.bufferBase - cur.parent.bufferBase; + cur = cur.parent; + } + if (top > 0 && cur.buffer[top - 4] == 0 /* Term.Err */ && cur.buffer[top - 1] > -1) { + if (start == end) + return; + if (cur.buffer[top - 2] >= start) { + cur.buffer[top - 2] = end; + return; } - if (data[i] == token) - index = this.putAction(pair(data, i + 1), token, end, index); } } - return index; - } -} -class Parse { - constructor(parser, input, fragments, ranges) { - this.parser = parser; - this.input = input; - this.ranges = ranges; - this.recovering = 0; - this.nextStackID = 0x2654; // ♔, ♕, ♖, ♗, ♘, ♙, ♠, ♡, ♢, ♣, ♤, ♥, ♦, ♧ - this.minStackPos = 0; - this.reused = []; - this.stoppedAt = null; - this.lastBigReductionStart = -1; - this.lastBigReductionSize = 0; - this.bigReductionCount = 0; - this.stream = new InputStream(input, ranges); - this.tokens = new TokenCache(parser, this.stream); - this.topTerm = parser.top[1]; - let { from } = ranges[0]; - this.stacks = [Stack.start(this, parser.top[0], from)]; - this.fragments = fragments.length && this.stream.end - from > parser.bufferLength * 4 - ? new FragmentCursor(fragments, parser.nodeSet) : null; - } - get parsedPos() { - return this.minStackPos; - } - // Move the parser forward. This will process all parse stacks at - // `this.pos` and try to advance them to a further position. If no - // stack for such a position is found, it'll start error-recovery. - // - // When the parse is finished, this will return a syntax tree. When - // not, it returns `null`. - advance() { - let stacks = this.stacks, pos = this.minStackPos; - // This will hold stacks beyond `pos`. - let newStacks = this.stacks = []; - let stopped, stoppedTokens; - // If a large amount of reductions happened with the same start - // position, force the stack out of that production in order to - // avoid creating a tree too deep to recurse through. - // (This is an ugly kludge, because unfortunately there is no - // straightforward, cheap way to check for this happening, due to - // the history of reductions only being available in an - // expensive-to-access format in the stack buffers.) - if (this.bigReductionCount > 300 /* Rec.MaxLeftAssociativeReductionCount */ && stacks.length == 1) { - let [s] = stacks; - while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) { } - this.bigReductionCount = this.lastBigReductionSize = 0; + if (!isReduce || this.pos == end) { // Simple case, just append + this.buffer.push(term, start, end, size); } - // Keep advancing any stacks at `pos` until they either move - // forward or can't be advanced. Gather stacks that can't be - // advanced further in `stopped`. - for (let i = 0; i < stacks.length; i++) { - let stack = stacks[i]; - for (;;) { - this.tokens.mainToken = null; - if (stack.pos > pos) { - newStacks.push(stack); - } - else if (this.advanceStack(stack, newStacks, stacks)) { - continue; - } - else { - if (!stopped) { - stopped = []; - stoppedTokens = []; - } - stopped.push(stack); - let tok = this.tokens.getMainToken(stack); - stoppedTokens.push(tok.value, tok.end); + else { // There may be skipped nodes that have to be moved forward + let index = this.buffer.length; + if (index > 0 && this.buffer[index - 4] != 0 /* Term.Err */) + while (index > 0 && this.buffer[index - 2] > end) { + // Move this record forward + this.buffer[index] = this.buffer[index - 4]; + this.buffer[index + 1] = this.buffer[index - 3]; + this.buffer[index + 2] = this.buffer[index - 2]; + this.buffer[index + 3] = this.buffer[index - 1]; + index -= 4; + if (size > 4) + size -= 4; } - break; - } - } - if (!newStacks.length) { - let finished = stopped && findFinished(stopped); - if (finished) { - if (verbose) - console.log("Finish with " + this.stackID(finished)); - return this.stackToTree(finished); - } - if (this.parser.strict) { - if (verbose && stopped) - console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none")); - throw new SyntaxError("No parse at " + pos); - } - if (!this.recovering) - this.recovering = 5 /* Rec.Distance */; + this.buffer[index] = term; + this.buffer[index + 1] = start; + this.buffer[index + 2] = end; + this.buffer[index + 3] = size; } - if (this.recovering && stopped) { - let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] - : this.runRecovery(stopped, stoppedTokens, newStacks); - if (finished) { - if (verbose) - console.log("Force-finish " + this.stackID(finished)); - return this.stackToTree(finished.forceAll()); - } + } + // Apply a shift action + /** + @internal + */ + shift(action, type, start, end) { + if (action & 131072 /* Action.GotoFlag */) { + this.pushState(action & 65535 /* Action.ValueMask */, this.pos); } - if (this.recovering) { - let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3 /* Rec.MaxRemainingPerStep */; - if (newStacks.length > maxRemaining) { - newStacks.sort((a, b) => b.score - a.score); - while (newStacks.length > maxRemaining) - newStacks.pop(); + else if ((action & 262144 /* Action.StayFlag */) == 0) { // Regular shift + let nextState = action, { parser } = this.p; + if (end > this.pos || type <= parser.maxNode) { + this.pos = end; + if (!parser.stateFlag(nextState, 1 /* StateFlag.Skipped */)) + this.reducePos = end; } - if (newStacks.some(s => s.reducePos > pos)) - this.recovering--; + this.pushState(nextState, start); + this.shiftContext(type, start); + if (type <= parser.maxNode) + this.buffer.push(type, start, end, 4); } - else if (newStacks.length > 1) { - // Prune stacks that are in the same state, or that have been - // running without splitting for a while, to avoid getting stuck - // with multiple successful stacks running endlessly on. - outer: for (let i = 0; i < newStacks.length - 1; i++) { - let stack = newStacks[i]; - for (let j = i + 1; j < newStacks.length; j++) { - let other = newStacks[j]; - if (stack.sameState(other) || - stack.buffer.length > 500 /* Rec.MinBufferLengthPrune */ && other.buffer.length > 500 /* Rec.MinBufferLengthPrune */) { - if (((stack.score - other.score) || (stack.buffer.length - other.buffer.length)) > 0) { - newStacks.splice(j--, 1); - } - else { - newStacks.splice(i--, 1); - continue outer; - } - } - } - } - if (newStacks.length > 12 /* Rec.MaxStackCount */) - newStacks.splice(12 /* Rec.MaxStackCount */, newStacks.length - 12 /* Rec.MaxStackCount */); + else { // Shift-and-stay, which means this is a skipped token + this.pos = end; + this.shiftContext(type, start); + if (type <= this.p.parser.maxNode) + this.buffer.push(type, start, end, 4); } - this.minStackPos = newStacks[0].pos; - for (let i = 1; i < newStacks.length; i++) - if (newStacks[i].pos < this.minStackPos) - this.minStackPos = newStacks[i].pos; - return null; } - stopAt(pos) { - if (this.stoppedAt != null && this.stoppedAt < pos) - throw new RangeError("Can't move stoppedAt forward"); - this.stoppedAt = pos; + // Apply an action + /** + @internal + */ + apply(action, next, nextStart, nextEnd) { + if (action & 65536 /* Action.ReduceFlag */) + this.reduce(action); + else + this.shift(action, next, nextStart, nextEnd); } - // Returns an updated version of the given stack, or null if the - // stack can't advance normally. When `split` and `stacks` are - // given, stacks split off by ambiguous operations will be pushed to - // `split`, or added to `stacks` if they move `pos` forward. - advanceStack(stack, stacks, split) { - let start = stack.pos, { parser } = this; - let base = verbose ? this.stackID(stack) + " -> " : ""; - if (this.stoppedAt != null && start > this.stoppedAt) - return stack.forceReduce() ? stack : null; - if (this.fragments) { - let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0; - for (let cached = this.fragments.nodeAt(start); cached;) { - let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser.getGoto(stack.state, cached.type.id) : -1; - if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) { - stack.useNode(cached, match); - if (verbose) - console.log(base + this.stackID(stack) + ` (via reuse of ${parser.getName(cached.type.id)})`); - return true; - } - if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0) - break; - let inner = cached.children[0]; - if (inner instanceof Tree && cached.positions[0] == 0) - cached = inner; - else - break; - } - } - let defaultReduce = parser.stateSlot(stack.state, 4 /* ParseState.DefaultReduce */); - if (defaultReduce > 0) { - stack.reduce(defaultReduce); - if (verbose) - console.log(base + this.stackID(stack) + ` (via always-reduce ${parser.getName(defaultReduce & 65535 /* Action.ValueMask */)})`); - return true; - } - if (stack.stack.length >= 8400 /* Rec.CutDepth */) { - while (stack.stack.length > 6000 /* Rec.CutTo */ && stack.forceReduce()) { } - } - let actions = this.tokens.getActions(stack); - for (let i = 0; i < actions.length;) { - let action = actions[i++], term = actions[i++], end = actions[i++]; - let last = i == actions.length || !split; - let localStack = last ? stack : stack.split(); - let main = this.tokens.mainToken; - localStack.apply(action, term, main ? main.start : localStack.pos, end); - if (verbose) - console.log(base + this.stackID(localStack) + ` (via ${(action & 65536 /* Action.ReduceFlag */) == 0 ? "shift" - : `reduce of ${parser.getName(action & 65535 /* Action.ValueMask */)}`} for ${parser.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`); - if (last) - return true; - else if (localStack.pos > start) - stacks.push(localStack); - else - split.push(localStack); + // Add a prebuilt (reused) node into the buffer. + /** + @internal + */ + useNode(value, next) { + let index = this.p.reused.length - 1; + if (index < 0 || this.p.reused[index] != value) { + this.p.reused.push(value); + index++; } - return false; + let start = this.pos; + this.reducePos = this.pos = start + value.length; + this.pushState(next, start); + this.buffer.push(index, start, this.reducePos, -1 /* size == -1 means this is a reused value */); + if (this.curContext) + this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length))); } - // Advance a given stack forward as far as it will go. Returns the - // (possibly updated) stack if it got stuck, or null if it moved - // forward and was given to `pushStackDedup`. - advanceFully(stack, newStacks) { - let pos = stack.pos; - for (;;) { - if (!this.advanceStack(stack, null, null)) + // Split the stack. Due to the buffer sharing and the fact + // that `this.stack` tends to stay quite shallow, this isn't very + // expensive. + /** + @internal + */ + split() { + let parent = this; + let off = parent.buffer.length; + // Because the top of the buffer (after this.pos) may be mutated + // to reorder reductions and skipped tokens, and shared buffers + // should be immutable, this copies any outstanding skipped tokens + // to the new buffer, and puts the base pointer before them. + while (off > 0 && parent.buffer[off - 2] > parent.reducePos) + off -= 4; + let buffer = parent.buffer.slice(off), base = parent.bufferBase + off; + // Make sure parent points to an actual parent with content, if there is such a parent. + while (parent && base == parent.bufferBase) + parent = parent.parent; + return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent); + } + // Try to recover from an error by 'deleting' (ignoring) one token. + /** + @internal + */ + recoverByDelete(next, nextEnd) { + let isNode = next <= this.p.parser.maxNode; + if (isNode) + this.storeNode(next, this.pos, nextEnd, 4); + this.storeNode(0 /* Term.Err */, this.pos, nextEnd, isNode ? 8 : 4); + this.pos = this.reducePos = nextEnd; + this.score -= 190 /* Recover.Delete */; + } + /** + Check if the given term would be able to be shifted (optionally + after some reductions) on this stack. This can be useful for + external tokenizers that want to make sure they only provide a + given token when it applies. + */ + canShift(term) { + for (let sim = new SimulatedStack(this);;) { + let action = this.p.parser.stateSlot(sim.state, 4 /* ParseState.DefaultReduce */) || this.p.parser.hasAction(sim.state, term); + if (action == 0) return false; - if (stack.pos > pos) { - pushStackDedup(stack, newStacks); + if ((action & 65536 /* Action.ReduceFlag */) == 0) return true; - } + sim.reduce(action); } } - runRecovery(stacks, tokens, newStacks) { - let finished = null, restarted = false; - for (let i = 0; i < stacks.length; i++) { - let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1]; - let base = verbose ? this.stackID(stack) + " -> " : ""; - if (stack.deadEnd) { - if (restarted) - continue; - restarted = true; - stack.restart(); - if (verbose) - console.log(base + this.stackID(stack) + " (restarted)"); - let done = this.advanceFully(stack, newStacks); - if (done) - continue; - } - let force = stack.split(), forceBase = base; - for (let j = 0; force.forceReduce() && j < 10 /* Rec.ForceReduceLimit */; j++) { - if (verbose) - console.log(forceBase + this.stackID(force) + " (via force-reduce)"); - let done = this.advanceFully(force, newStacks); - if (done) - break; - if (verbose) - forceBase = this.stackID(force) + " -> "; - } - for (let insert of stack.recoverByInsert(token)) { - if (verbose) - console.log(base + this.stackID(insert) + " (via recover-insert)"); - this.advanceFully(insert, newStacks); + // Apply up to Recover.MaxNext recovery actions that conceptually + // inserts some missing token or rule. + /** + @internal + */ + recoverByInsert(next) { + if (this.stack.length >= 300 /* Recover.MaxInsertStackDepth */) + return []; + let nextStates = this.p.parser.nextStates(this.state); + if (nextStates.length > 4 /* Recover.MaxNext */ << 1 || this.stack.length >= 120 /* Recover.DampenInsertStackDepth */) { + let best = []; + for (let i = 0, s; i < nextStates.length; i += 2) { + if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next)) + best.push(nextStates[i], s); } - if (this.stream.end > stack.pos) { - if (tokenEnd == stack.pos) { - tokenEnd++; - token = 0 /* Term.Err */; + if (this.stack.length < 120 /* Recover.DampenInsertStackDepth */) + for (let i = 0; best.length < 4 /* Recover.MaxNext */ << 1 && i < nextStates.length; i += 2) { + let s = nextStates[i + 1]; + if (!best.some((v, i) => (i & 1) && v == s)) + best.push(nextStates[i], s); } - stack.recoverByDelete(token, tokenEnd); - if (verbose) - console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`); - pushStackDedup(stack, newStacks); - } - else if (!finished || finished.score < stack.score) { - finished = stack; - } + nextStates = best; } - return finished; + let result = []; + for (let i = 0; i < nextStates.length && result.length < 4 /* Recover.MaxNext */; i += 2) { + let s = nextStates[i + 1]; + if (s == this.state) + continue; + let stack = this.split(); + stack.pushState(s, this.pos); + stack.storeNode(0 /* Term.Err */, stack.pos, stack.pos, 4, true); + stack.shiftContext(nextStates[i], this.pos); + stack.reducePos = this.pos; + stack.score -= 200 /* Recover.Insert */; + result.push(stack); + } + return result; } - // Convert the stack's buffer to a syntax tree. - stackToTree(stack) { - stack.close(); - return Tree.build({ buffer: StackBufferCursor.create(stack), - nodeSet: this.parser.nodeSet, - topID: this.topTerm, - maxBufferLength: this.parser.bufferLength, - reused: this.reused, - start: this.ranges[0].from, - length: stack.pos - this.ranges[0].from, - minRepeatType: this.parser.minRepeatTerm }); - } - stackID(stack) { - let id = (stackIDs || (stackIDs = new WeakMap)).get(stack); - if (!id) - stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++)); - return id + stack; - } -} -function pushStackDedup(stack, newStacks) { - for (let i = 0; i < newStacks.length; i++) { - let other = newStacks[i]; - if (other.pos == stack.pos && other.sameState(stack)) { - if (newStacks[i].score < stack.score) - newStacks[i] = stack; - return; - } - } - newStacks.push(stack); -} -class Dialect { - constructor(source, flags, disabled) { - this.source = source; - this.flags = flags; - this.disabled = disabled; - } - allows(term) { return !this.disabled || this.disabled[term] == 0; } -} -const id = x => x; -/** -Context trackers are used to track stateful context (such as -indentation in the Python grammar, or parent elements in the XML -grammar) needed by external tokenizers. You declare them in a -grammar file as `@context exportName from "module"`. - -Context values should be immutable, and can be updated (replaced) -on shift or reduce actions. - -The export used in a `@context` declaration should be of this -type. -*/ -class ContextTracker { + // Force a reduce, if possible. Return false if that can't + // be done. /** - Define a context tracker. + @internal */ - constructor(spec) { - this.start = spec.start; - this.shift = spec.shift || id; - this.reduce = spec.reduce || id; - this.reuse = spec.reuse || id; - this.hash = spec.hash || (() => 0); - this.strict = spec.strict !== false; + forceReduce() { + let { parser } = this.p; + let reduce = parser.stateSlot(this.state, 5 /* ParseState.ForcedReduce */); + if ((reduce & 65536 /* Action.ReduceFlag */) == 0) + return false; + if (!parser.validAction(this.state, reduce)) { + let depth = reduce >> 19 /* Action.ReduceDepthShift */, term = reduce & 65535 /* Action.ValueMask */; + let target = this.stack.length - depth * 3; + if (target < 0 || parser.getGoto(this.stack[target], term, false) < 0) { + let backup = this.findForcedReduction(); + if (backup == null) + return false; + reduce = backup; + } + this.storeNode(0 /* Term.Err */, this.pos, this.pos, 4, true); + this.score -= 100 /* Recover.Reduce */; + } + this.reducePos = this.pos; + this.reduce(reduce); + return true; } -} -/** -Holds the parse tables for a given grammar, as generated by -`lezer-generator`, and provides [methods](#common.Parser) to parse -content with. -*/ -class LRParser extends Parser { /** - @internal + Try to scan through the automaton to find some kind of reduction + that can be applied. Used when the regular ForcedReduce field + isn't a valid action. @internal */ - constructor(spec) { - super(); - /** - @internal - */ - this.wrappers = []; - if (spec.version != 14 /* File.Version */) - throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14 /* File.Version */})`); - let nodeNames = spec.nodeNames.split(" "); - this.minRepeatTerm = nodeNames.length; - for (let i = 0; i < spec.repeatNodeCount; i++) - nodeNames.push(""); - let topTerms = Object.keys(spec.topRules).map(r => spec.topRules[r][1]); - let nodeProps = []; - for (let i = 0; i < nodeNames.length; i++) - nodeProps.push([]); - function setProp(nodeID, prop, value) { - nodeProps[nodeID].push([prop, prop.deserialize(String(value))]); - } - if (spec.nodeProps) - for (let propSpec of spec.nodeProps) { - let prop = propSpec[0]; - if (typeof prop == "string") - prop = NodeProp[prop]; - for (let i = 1; i < propSpec.length;) { - let next = propSpec[i++]; - if (next >= 0) { - setProp(next, prop, propSpec[i++]); - } - else { - let value = propSpec[i + -next]; - for (let j = -next; j > 0; j--) - setProp(propSpec[i++], prop, value); - i++; + findForcedReduction() { + let { parser } = this.p, seen = []; + let explore = (state, depth) => { + if (seen.includes(state)) + return; + seen.push(state); + return parser.allActions(state, (action) => { + if (action & (262144 /* Action.StayFlag */ | 131072 /* Action.GotoFlag */)) ; + else if (action & 65536 /* Action.ReduceFlag */) { + let rDepth = (action >> 19 /* Action.ReduceDepthShift */) - depth; + if (rDepth > 1) { + let term = action & 65535 /* Action.ValueMask */, target = this.stack.length - rDepth * 3; + if (target >= 0 && parser.getGoto(this.stack[target], term, false) >= 0) + return (rDepth << 19 /* Action.ReduceDepthShift */) | 65536 /* Action.ReduceFlag */ | term; } } - } - this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({ - name: i >= this.minRepeatTerm ? undefined : name, - id: i, - props: nodeProps[i], - top: topTerms.indexOf(i) > -1, - error: i == 0, - skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1 - }))); - if (spec.propSources) - this.nodeSet = this.nodeSet.extend(...spec.propSources); - this.strict = false; - this.bufferLength = DefaultBufferLength; - let tokenArray = decodeArray(spec.tokenData); - this.context = spec.context; - this.specializerSpecs = spec.specialized || []; - this.specialized = new Uint16Array(this.specializerSpecs.length); - for (let i = 0; i < this.specializerSpecs.length; i++) - this.specialized[i] = this.specializerSpecs[i].term; - this.specializers = this.specializerSpecs.map(getSpecializer); - this.states = decodeArray(spec.states, Uint32Array); - this.data = decodeArray(spec.stateData); - this.goto = decodeArray(spec.goto); - this.maxTerm = spec.maxTerm; - this.tokenizers = spec.tokenizers.map(value => typeof value == "number" ? new TokenGroup(tokenArray, value) : value); - this.topRules = spec.topRules; - this.dialects = spec.dialects || {}; - this.dynamicPrecedences = spec.dynamicPrecedences || null; - this.tokenPrecTable = spec.tokenPrec; - this.termNames = spec.termNames || null; - this.maxNode = this.nodeSet.types.length - 1; - this.dialect = this.parseDialect(); - this.top = this.topRules[Object.keys(this.topRules)[0]]; - } - createParse(input, fragments, ranges) { - let parse = new Parse(this, input, fragments, ranges); - for (let w of this.wrappers) - parse = w(parse, input, fragments, ranges); - return parse; + else { + let found = explore(action, depth + 1); + if (found != null) + return found; + } + }); + }; + return explore(this.state, 0); } /** - Get a goto table entry @internal + @internal */ - getGoto(state, term, loose = false) { - let table = this.goto; - if (term >= table[0]) - return -1; - for (let pos = table[term + 1];;) { - let groupTag = table[pos++], last = groupTag & 1; - let target = table[pos++]; - if (last && loose) - return target; - for (let end = pos + (groupTag >> 1); pos < end; pos++) - if (table[pos] == state) - return target; - if (last) - return -1; + forceAll() { + while (!this.p.parser.stateFlag(this.state, 2 /* StateFlag.Accepting */)) { + if (!this.forceReduce()) { + this.storeNode(0 /* Term.Err */, this.pos, this.pos, 4, true); + break; + } } + return this; } /** - Check if this state has an action for a given terminal @internal + Check whether this state has no further actions (assumed to be a direct descendant of the + top state, since any other states must be able to continue + somehow). @internal */ - hasAction(state, terminal) { - let data = this.data; - for (let set = 0; set < 2; set++) { - for (let i = this.stateSlot(state, set ? 2 /* ParseState.Skip */ : 1 /* ParseState.Actions */), next;; i += 3) { - if ((next = data[i]) == 65535 /* Seq.End */) { - if (data[i + 1] == 1 /* Seq.Next */) - next = data[i = pair(data, i + 2)]; - else if (data[i + 1] == 2 /* Seq.Other */) - return pair(data, i + 2); - else - break; - } - if (next == terminal || next == 0 /* Term.Err */) - return pair(data, i + 1); - } - } - return 0; + get deadEnd() { + if (this.stack.length != 3) + return false; + let { parser } = this.p; + return parser.data[parser.stateSlot(this.state, 1 /* ParseState.Actions */)] == 65535 /* Seq.End */ && + !parser.stateSlot(this.state, 4 /* ParseState.DefaultReduce */); } /** - @internal + Restart the stack (put it back in its start state). Only safe + when this.stack.length == 3 (state is directly below the top + state). @internal */ - stateSlot(state, slot) { - return this.states[(state * 6 /* ParseState.Size */) + slot]; + restart() { + this.storeNode(0 /* Term.Err */, this.pos, this.pos, 4, true); + this.state = this.stack[0]; + this.stack.length = 0; } /** @internal */ - stateFlag(state, flag) { - return (this.stateSlot(state, 0 /* ParseState.Flags */) & flag) > 0; + sameState(other) { + if (this.state != other.state || this.stack.length != other.stack.length) + return false; + for (let i = 0; i < this.stack.length; i += 3) + if (this.stack[i] != other.stack[i]) + return false; + return true; } /** - @internal + Get the parser used by this stack. */ - validAction(state, action) { - return !!this.allActions(state, a => a == action ? true : null); - } + get parser() { return this.p.parser; } /** - @internal + Test whether a given dialect (by numeric ID, as exported from + the terms file) is enabled. */ - allActions(state, action) { - let deflt = this.stateSlot(state, 4 /* ParseState.DefaultReduce */); - let result = deflt ? action(deflt) : undefined; - for (let i = this.stateSlot(state, 1 /* ParseState.Actions */); result == null; i += 3) { - if (this.data[i] == 65535 /* Seq.End */) { - if (this.data[i + 1] == 1 /* Seq.Next */) - i = pair(this.data, i + 2); - else - break; - } - result = action(pair(this.data, i + 1)); - } - return result; + dialectEnabled(dialectID) { return this.p.parser.dialect.flags[dialectID]; } + shiftContext(term, start) { + if (this.curContext) + this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start))); } - /** - Get the states that can follow this one through shift actions or - goto jumps. @internal - */ - nextStates(state) { - let result = []; - for (let i = this.stateSlot(state, 1 /* ParseState.Actions */);; i += 3) { - if (this.data[i] == 65535 /* Seq.End */) { - if (this.data[i + 1] == 1 /* Seq.Next */) - i = pair(this.data, i + 2); - else - break; - } - if ((this.data[i + 2] & (65536 /* Action.ReduceFlag */ >> 16)) == 0) { - let value = this.data[i + 1]; - if (!result.some((v, i) => (i & 1) && v == value)) - result.push(this.data[i], value); - } - } - return result; + reduceContext(term, start) { + if (this.curContext) + this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start))); } /** - Configure the parser. Returns a new parser instance that has the - given settings modified. Settings not provided in `config` are - kept from the original parser. + @internal */ - configure(config) { - // Hideous reflection-based kludge to make it easy to create a - // slightly modified copy of a parser. - let copy = Object.assign(Object.create(LRParser.prototype), this); - if (config.props) - copy.nodeSet = this.nodeSet.extend(...config.props); - if (config.top) { - let info = this.topRules[config.top]; - if (!info) - throw new RangeError(`Invalid top rule name ${config.top}`); - copy.top = info; - } - if (config.tokenizers) - copy.tokenizers = this.tokenizers.map(t => { - let found = config.tokenizers.find(r => r.from == t); - return found ? found.to : t; - }); - if (config.specializers) { - copy.specializers = this.specializers.slice(); - copy.specializerSpecs = this.specializerSpecs.map((s, i) => { - let found = config.specializers.find(r => r.from == s.external); - if (!found) - return s; - let spec = Object.assign(Object.assign({}, s), { external: found.to }); - copy.specializers[i] = getSpecializer(spec); - return spec; - }); - } - if (config.contextTracker) - copy.context = config.contextTracker; - if (config.dialect) - copy.dialect = this.parseDialect(config.dialect); - if (config.strict != null) - copy.strict = config.strict; - if (config.wrap) - copy.wrappers = copy.wrappers.concat(config.wrap); - if (config.bufferLength != null) - copy.bufferLength = config.bufferLength; - return copy; + emitContext() { + let last = this.buffer.length - 1; + if (last < 0 || this.buffer[last] != -3) + this.buffer.push(this.curContext.hash, this.pos, this.pos, -3); } /** - Tells you whether any [parse wrappers](#lr.ParserConfig.wrap) - are registered for this parser. + @internal */ - hasWrappers() { - return this.wrappers.length > 0; + emitLookAhead() { + let last = this.buffer.length - 1; + if (last < 0 || this.buffer[last] != -4) + this.buffer.push(this.lookAhead, this.pos, this.pos, -4); } - /** - Returns the name associated with a given term. This will only - work for all terms when the parser was generated with the - `--names` option. By default, only the names of tagged terms are - stored. - */ - getName(term) { - return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term); + updateContext(context) { + if (context != this.curContext.context) { + let newCx = new StackContext(this.curContext.tracker, context); + if (newCx.hash != this.curContext.hash) + this.emitContext(); + this.curContext = newCx; + } } /** - The eof term id is always allocated directly after the node - types. @internal - */ - get eofTerm() { return this.maxNode + 1; } - /** - The type of top node produced by the parser. - */ - get topNode() { return this.nodeSet.types[this.top[1]]; } - /** @internal */ - dynamicPrecedence(term) { - let prec = this.dynamicPrecedences; - return prec == null ? 0 : prec[term] || 0; + setLookAhead(lookAhead) { + if (lookAhead > this.lookAhead) { + this.emitLookAhead(); + this.lookAhead = lookAhead; + } } /** @internal */ - parseDialect(dialect) { - let values = Object.keys(this.dialects), flags = values.map(() => false); - if (dialect) - for (let part of dialect.split(" ")) { - let id = values.indexOf(part); - if (id >= 0) - flags[id] = true; - } - let disabled = null; - for (let i = 0; i < values.length; i++) - if (!flags[i]) { - for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535 /* Seq.End */;) - (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1; - } - return new Dialect(dialect, flags, disabled); + close() { + if (this.curContext && this.curContext.tracker.strict) + this.emitContext(); + if (this.lookAhead > 0) + this.emitLookAhead(); } - /** - Used by the output of the parser generator. Not available to - user code. @hide - */ - static deserialize(spec) { - return new LRParser(spec); +} +class StackContext { + constructor(tracker, context) { + this.tracker = tracker; + this.context = context; + this.hash = tracker.strict ? tracker.hash(context) : 0; } } -function pair(data, off) { return data[off] | (data[off + 1] << 16); } -function findFinished(stacks) { - let best = null; - for (let stack of stacks) { - let stopped = stack.p.stoppedAt; - if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && - stack.p.parser.stateFlag(stack.state, 2 /* StateFlag.Accepting */) && - (!best || best.score < stack.score)) - best = stack; +// Used to cheaply run some reductions to scan ahead without mutating +// an entire stack +class SimulatedStack { + constructor(start) { + this.start = start; + this.state = start.state; + this.stack = start.stack; + this.base = this.stack.length; + } + reduce(action) { + let term = action & 65535 /* Action.ValueMask */, depth = action >> 19 /* Action.ReduceDepthShift */; + if (depth == 0) { + if (this.stack == this.start.stack) + this.stack = this.stack.slice(); + this.stack.push(this.state, 0, 0); + this.base += 3; + } + else { + this.base -= (depth - 1) * 3; + } + let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true); + this.state = goto; } - return best; } -function getSpecializer(spec) { - if (spec.external) { - let mask = spec.extend ? 1 /* Specialize.Extend */ : 0 /* Specialize.Specialize */; - return (value, stack) => (spec.external(value, stack) << 1) | mask; +// This is given to `Tree.build` to build a buffer, and encapsulates +// the parent-stack-walking necessary to read the nodes. +class StackBufferCursor { + constructor(stack, pos, index) { + this.stack = stack; + this.pos = pos; + this.index = index; + this.buffer = stack.buffer; + if (this.index == 0) + this.maybeNext(); + } + static create(stack, pos = stack.bufferBase + stack.buffer.length) { + return new StackBufferCursor(stack, pos, pos - stack.bufferBase); + } + maybeNext() { + let next = this.stack.parent; + if (next != null) { + this.index = this.stack.bufferBase - next.bufferBase; + this.stack = next; + this.buffer = next.buffer; + } + } + get id() { return this.buffer[this.index - 4]; } + get start() { return this.buffer[this.index - 3]; } + get end() { return this.buffer[this.index - 2]; } + get size() { return this.buffer[this.index - 1]; } + next() { + this.index -= 4; + this.pos -= 4; + if (this.index == 0) + this.maybeNext(); + } + fork() { + return new StackBufferCursor(this.stack, this.pos, this.index); } - return spec.get; } -// This file was generated by lezer-generator. You probably shouldn't edit it. -const noSemi = 312, - incdec = 1, - incdecPrefix = 2, - questionDot = 3, - JSXStartTag = 4, - insertSemi = 313, - spaces = 315, - newline = 316, - LineComment = 5, - BlockComment = 6, - Dialect_jsx = 0; - -/* Hand-written tokenizers for JavaScript tokens that can't be - expressed by lezer's built-in tokenizer. */ - -const space = [9, 10, 11, 12, 13, 32, 133, 160, 5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, - 8201, 8202, 8232, 8233, 8239, 8287, 12288]; - -const braceR = 125, semicolon = 59, slash = 47, star = 42, plus = 43, minus = 45, lt = 60, comma = 44, - question = 63, dot = 46; - -const trackNewline = new ContextTracker({ - start: false, - shift(context, term) { - return term == LineComment || term == BlockComment || term == spaces ? context : term == newline - }, - strict: false -}); - -const insertSemicolon = new ExternalTokenizer((input, stack) => { - let {next} = input; - if (next == braceR || next == -1 || stack.context) - input.acceptToken(insertSemi); -}, {contextual: true, fallback: true}); - -const noSemicolon = new ExternalTokenizer((input, stack) => { - let {next} = input, after; - if (space.indexOf(next) > -1) return - if (next == slash && ((after = input.peek(1)) == slash || after == star)) return - if (next != braceR && next != semicolon && next != -1 && !stack.context) - input.acceptToken(noSemi); -}, {contextual: true}); - -const operatorToken = new ExternalTokenizer((input, stack) => { - let {next} = input; - if (next == plus || next == minus) { - input.advance(); - if (next == input.next) { - input.advance(); - let mayPostfix = !stack.context && stack.canShift(incdec); - input.acceptToken(mayPostfix ? incdec : incdecPrefix); +// See lezer-generator/src/encode.ts for comments about the encoding +// used here +function decodeArray(input, Type = Uint16Array) { + if (typeof input != "string") + return input; + let array = null; + for (let pos = 0, out = 0; pos < input.length;) { + let value = 0; + for (;;) { + let next = input.charCodeAt(pos++), stop = false; + if (next == 126 /* Encode.BigValCode */) { + value = 65535 /* Encode.BigVal */; + break; + } + if (next >= 92 /* Encode.Gap2 */) + next--; + if (next >= 34 /* Encode.Gap1 */) + next--; + let digit = next - 32 /* Encode.Start */; + if (digit >= 46 /* Encode.Base */) { + digit -= 46 /* Encode.Base */; + stop = true; + } + value += digit; + if (stop) + break; + value *= 46 /* Encode.Base */; + } + if (array) + array[out++] = value; + else + array = new Type(value); } - } else if (next == question && input.peek(1) == dot) { - input.advance(); input.advance(); - if (input.next < 48 || input.next > 57) // No digit after - input.acceptToken(questionDot); - } -}, {contextual: true}); - -function identifierChar(ch, start) { - return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch == 95 || ch >= 192 || - !start && ch >= 48 && ch <= 57 + return array; } -const jsx = new ExternalTokenizer((input, stack) => { - if (input.next != lt || !stack.dialectEnabled(Dialect_jsx)) return - input.advance(); - if (input.next == slash) return - // Scan for an identifier followed by a comma or 'extends', don't - // treat this as a start tag if present. - let back = 0; - while (space.indexOf(input.next) > -1) { input.advance(); back++; } - if (identifierChar(input.next, true)) { - input.advance(); - back++; - while (identifierChar(input.next, false)) { input.advance(); back++; } - while (space.indexOf(input.next) > -1) { input.advance(); back++; } - if (input.next == comma) return - for (let i = 0;; i++) { - if (i == 7) { - if (!identifierChar(input.next, true)) return - break - } - if (input.next != "extends".charCodeAt(i)) break - input.advance(); - back++; +class CachedToken { + constructor() { + this.start = -1; + this.value = -1; + this.end = -1; + this.extended = -1; + this.lookAhead = 0; + this.mask = 0; + this.context = 0; } - } - input.acceptToken(JSXStartTag, -back); -}); - -const jsHighlight = styleTags({ - "get set async static": tags.modifier, - "for while do if else switch try catch finally return throw break continue default case": tags.controlKeyword, - "in of await yield void typeof delete instanceof": tags.operatorKeyword, - "let var const using function class extends": tags.definitionKeyword, - "import export from": tags.moduleKeyword, - "with debugger as new": tags.keyword, - TemplateString: tags.special(tags.string), - super: tags.atom, - BooleanLiteral: tags.bool, - this: tags.self, - null: tags.null, - Star: tags.modifier, - VariableName: tags.variableName, - "CallExpression/VariableName TaggedTemplateExpression/VariableName": tags.function(tags.variableName), - VariableDefinition: tags.definition(tags.variableName), - Label: tags.labelName, - PropertyName: tags.propertyName, - PrivatePropertyName: tags.special(tags.propertyName), - "CallExpression/MemberExpression/PropertyName": tags.function(tags.propertyName), - "FunctionDeclaration/VariableDefinition": tags.function(tags.definition(tags.variableName)), - "ClassDeclaration/VariableDefinition": tags.definition(tags.className), - PropertyDefinition: tags.definition(tags.propertyName), - PrivatePropertyDefinition: tags.definition(tags.special(tags.propertyName)), - UpdateOp: tags.updateOperator, - "LineComment Hashbang": tags.lineComment, - BlockComment: tags.blockComment, - Number: tags.number, - String: tags.string, - Escape: tags.escape, - ArithOp: tags.arithmeticOperator, - LogicOp: tags.logicOperator, - BitOp: tags.bitwiseOperator, - CompareOp: tags.compareOperator, - RegExp: tags.regexp, - Equals: tags.definitionOperator, - Arrow: tags.function(tags.punctuation), - ": Spread": tags.punctuation, - "( )": tags.paren, - "[ ]": tags.squareBracket, - "{ }": tags.brace, - "InterpolationStart InterpolationEnd": tags.special(tags.brace), - ".": tags.derefOperator, - ", ;": tags.separator, - "@": tags.meta, - - TypeName: tags.typeName, - TypeDefinition: tags.definition(tags.typeName), - "type enum interface implements namespace module declare": tags.definitionKeyword, - "abstract global Privacy readonly override": tags.modifier, - "is keyof unique infer": tags.operatorKeyword, - - JSXAttributeValue: tags.attributeValue, - JSXText: tags.content, - "JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag": tags.angleBracket, - "JSXIdentifier JSXNameSpacedName": tags.tagName, - "JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName": tags.attributeName, - "JSXBuiltin/JSXIdentifier": tags.standard(tags.tagName) -}); - -// This file was generated by lezer-generator. You probably shouldn't edit it. -const spec_identifier = {__proto__:null,export:20, as:25, from:33, default:36, async:41, function:42, extends:54, this:58, true:66, false:66, null:78, void:82, typeof:86, super:102, new:136, delete:148, yield:157, await:161, class:166, public:229, private:229, protected:229, readonly:231, instanceof:250, satisfies:253, in:254, const:256, import:290, keyof:345, unique:349, infer:355, is:391, abstract:411, implements:413, type:415, let:418, var:420, using:423, interface:429, enum:433, namespace:439, module:441, declare:445, global:449, for:468, of:477, while:480, with:484, do:488, if:492, else:494, switch:498, case:504, try:510, catch:514, finally:518, return:522, throw:526, break:530, continue:534, debugger:538}; -const spec_word = {__proto__:null,async:123, get:125, set:127, declare:189, public:191, private:191, protected:191, static:193, abstract:195, override:197, readonly:203, accessor:205, new:395}; -const spec_LessThan = {__proto__:null,"<":187}; -const parser = LRParser.deserialize({ - version: 14, - states: "$@QO%TQ^OOO%[Q^OOO'_Q`OOP(lOWOOO*zQ?NdO'#CiO+RO!bO'#CjO+aO#tO'#CjO+oO!0LbO'#D^O.QQ^O'#DdO.bQ^O'#DoO%[Q^O'#DwO0fQ^O'#EPOOQ?Mr'#EX'#EXO1PQWO'#EUOOQO'#Em'#EmOOQO'#Ih'#IhO1XQWO'#GpO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PP$!sP$!|$%t$,^$,a$,d$-P$-S$-Z$-cP$-i$-lP$.Y$.^$/U$0d$0i$1PPP$1U$1[$1`P$1c$1g$1k$2a$2x$3a$3e$3h$3k$3q$3t$3x$3|R!|RoqOXst!Z#d%k&o&q&r&t,k,p1|2PY!vQ']-]1a5eQ%rvQ%zyQ&R|Q&g!VS'T!e-TQ'c!iS'i!r!yU*e$|*V*jQ+i%{Q+v&TQ,[&aQ-Z'[Q-e'dQ-m'jQ0R*lQ1k,]R;v;T%QdOPWXYZstuvw!Z!`!g!o#S#W#Z#d#o#u#x#{$O$P$Q$R$S$T$U$V$W$X$_$a$e%k%r&P&h&k&o&q&r&t&x'Q'_'o(P(R(X(`(t(v(z)y+R+V,h,k,p-a-i-w-}.l.s/f0a0g0v1d1t1u1w1y1|2P2R2r2x3^5b5m5}6O6R6f8R8X8h8rS#q];Q!r)Z$Z$n'U)o,|-P.}2b3u5`6]9h9y;P;S;T;W;X;Y;Z;[;];^;_;`;a;b;c;d;f;i;v;x;y;{ < TypeParamList TypeDefinition extends ThisType this LiteralType ArithOp Number BooleanLiteral TemplateType InterpolationEnd Interpolation InterpolationStart NullType null VoidType void TypeofType typeof MemberExpression . PropertyName [ TemplateString Escape Interpolation super RegExp ] ArrayExpression Spread , } { ObjectExpression Property async get set PropertyDefinition Block : NewTarget new NewExpression ) ( ArgList UnaryExpression delete LogicOp BitOp YieldExpression yield AwaitExpression await ParenthesizedExpression ClassExpression class ClassBody MethodDeclaration Decorator @ MemberExpression PrivatePropertyName CallExpression TypeArgList CompareOp < declare Privacy static abstract override PrivatePropertyDefinition PropertyDeclaration readonly accessor Optional TypeAnnotation Equals StaticBlock FunctionExpression ArrowFunction ParamList ParamList ArrayPattern ObjectPattern PatternProperty Privacy readonly Arrow MemberExpression BinaryExpression ArithOp ArithOp ArithOp ArithOp BitOp CompareOp instanceof satisfies in const CompareOp BitOp BitOp BitOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression UpdateOp PostfixExpression CallExpression InstantiationExpression TaggedTemplateExpression DynamicImport import ImportMeta JSXElement JSXSelfCloseEndTag JSXSelfClosingTag JSXIdentifier JSXBuiltin JSXIdentifier JSXNamespacedName JSXMemberExpression JSXSpreadAttribute JSXAttribute JSXAttributeValue JSXEscape JSXEndTag JSXOpenTag JSXFragmentTag JSXText JSXEscape JSXStartCloseTag JSXCloseTag PrefixCast ArrowFunction TypeParamList SequenceExpression InstantiationExpression KeyofType keyof UniqueType unique ImportType InferredType infer TypeName ParenthesizedType FunctionSignature ParamList NewSignature IndexedType TupleType Label ArrayType ReadonlyType ObjectType MethodType PropertyType IndexSignature PropertyDefinition CallSignature TypePredicate is NewSignature new UnionType LogicOp IntersectionType LogicOp ConditionalType ParameterizedType ClassDeclaration abstract implements type VariableDeclaration let var using TypeAliasDeclaration InterfaceDeclaration interface EnumDeclaration enum EnumBody NamespaceDeclaration namespace module AmbientDeclaration declare GlobalDeclaration global ClassDeclaration ClassBody AmbientFunctionDeclaration ExportGroup VariableName VariableName ImportDeclaration ImportGroup ForStatement for ForSpec ForInSpec ForOfSpec of WhileStatement while WithStatement with DoStatement do IfStatement if else SwitchStatement switch SwitchBody CaseLabel case DefaultLabel TryStatement try CatchClause catch FinallyClause finally ReturnStatement return ThrowStatement throw BreakStatement break ContinueStatement continue DebuggerStatement debugger LabeledStatement ExpressionStatement SingleExpression SingleClassItem", - maxTerm: 376, - context: trackNewline, - nodeProps: [ - ["isolate", -8,5,6,14,34,36,48,50,52,""], - ["group", -26,9,17,19,65,204,208,212,213,215,218,221,231,233,239,241,243,245,248,254,260,262,264,266,268,270,271,"Statement",-34,13,14,29,32,33,39,48,51,52,54,59,67,69,73,77,79,81,82,107,108,117,118,135,138,140,141,142,143,144,146,147,166,167,169,"Expression",-23,28,30,34,38,40,42,171,173,175,176,178,179,180,182,183,184,186,187,188,198,200,202,203,"Type",-3,85,100,106,"ClassItem"], - ["openedBy", 23,"<",35,"InterpolationStart",53,"[",57,"{",70,"(",159,"JS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#Ge#S#T%Z#T#Z#Ge#Z#o%Z#o#p*g#p;'S%Z;'S;=`+a<%lO%Z'Ad#Gpi$h&j(Rp(U!bp'9tOY%ZYZ&cZr%Zrs&}sw%Zwx(rx!Q%Z!Q![#Ge![!^%Z!^!_*g!_!c%Z!c!i#Ge!i#O%Z#O#P&c#P#R%Z#R#S#Ge#S#T%Z#T#Z#Ge#Z#b%Z#b#c#>_#c#o%Z#o#p*g#p;'S%Z;'S;=`+a<%lO%Z*)x#Il_!d$b$h&j#})Lv(Rp(U!bOY%ZYZ&cZr%Zrs&}sw%Zwx(rx!^%Z!^!_*g!_#O%Z#O#P&c#P#o%Z#o#p*g#p;'S%Z;'S;=`+a<%lO%Z)[#Jv_al$h&j(Rp(U!bOY%ZYZ&cZr%Zrs&}sw%Zwx(rx!^%Z!^!_*g!_#O%Z#O#P&c#P#o%Z#o#p*g#p;'S%Z;'S;=`+a<%lO%Z04f#LS^h#)`#O- spec_identifier[value] || -1},{term: 338, get: (value) => spec_word[value] || -1},{term: 92, get: (value) => spec_LessThan[value] || -1}], - tokenPrec: 14749 -}); - +} +const nullToken = new CachedToken; /** -An instance of this is passed to completion source functions. +[Tokenizers](#lr.ExternalTokenizer) interact with the input +through this interface. It presents the input as a stream of +characters, tracking lookahead and hiding the complexity of +[ranges](#common.Parser.parse^ranges) from tokenizer code. */ -class CompletionContext { +class InputStream { /** - Create a new completion context. (Mostly useful for testing - completion sources—in the editor, the extension will create - these for you.) + @internal */ constructor( /** - The editor state that the completion happens in. - */ - state, - /** - The position at which the completion is happening. + @internal */ - pos, + input, /** - Indicates whether completion was activated explicitly, or - implicitly by typing. The usual way to respond to this is to - only return completions when either there is part of a - completable entity before the cursor, or `explicit` is true. + @internal */ - explicit) { - this.state = state; - this.pos = pos; - this.explicit = explicit; + ranges) { + this.input = input; + this.ranges = ranges; /** @internal */ - this.abortListeners = []; + this.chunk = ""; + /** + @internal + */ + this.chunkOff = 0; + /** + Backup chunk + */ + this.chunk2 = ""; + this.chunk2Pos = 0; + /** + The character code of the next code unit in the input, or -1 + when the stream is at the end of the input. + */ + this.next = -1; + /** + @internal + */ + this.token = nullToken; + this.rangeIndex = 0; + this.pos = this.chunkPos = ranges[0].from; + this.range = ranges[0]; + this.end = ranges[ranges.length - 1].to; + this.readNext(); } /** - Get the extent, content, and (if there is a token) type of the - token before `this.pos`. + @internal */ - tokenBefore(types) { - let token = syntaxTree(this.state).resolveInner(this.pos, -1); - while (token && types.indexOf(token.name) < 0) - token = token.parent; - return token ? { from: token.from, to: this.pos, - text: this.state.sliceDoc(token.from, this.pos), - type: token.type } : null; + resolveOffset(offset, assoc) { + let range = this.range, index = this.rangeIndex; + let pos = this.pos + offset; + while (pos < range.from) { + if (!index) + return null; + let next = this.ranges[--index]; + pos -= range.from - next.to; + range = next; + } + while (assoc < 0 ? pos > range.to : pos >= range.to) { + if (index == this.ranges.length - 1) + return null; + let next = this.ranges[++index]; + pos += next.from - range.to; + range = next; + } + return pos; } /** - Get the match of the given expression directly before the - cursor. + @internal */ - matchBefore(expr) { - let line = this.state.doc.lineAt(this.pos); - let start = Math.max(line.from, this.pos - 250); - let str = line.text.slice(start - line.from, this.pos - line.from); - let found = str.search(ensureAnchor(expr, false)); - return found < 0 ? null : { from: start + found, to: this.pos, text: str.slice(found) }; + clipPos(pos) { + if (pos >= this.range.from && pos < this.range.to) + return pos; + for (let range of this.ranges) + if (range.to > pos) + return Math.max(pos, range.from); + return this.end; } /** - Yields true when the query has been aborted. Can be useful in - asynchronous queries to avoid doing work that will be ignored. + Look at a code unit near the stream position. `.peek(0)` equals + `.next`, `.peek(-1)` gives you the previous character, and so + on. + + Note that looking around during tokenizing creates dependencies + on potentially far-away content, which may reduce the + effectiveness incremental parsing—when looking forward—or even + cause invalid reparses when looking backward more than 25 code + units, since the library does not track lookbehind. */ - get aborted() { return this.abortListeners == null; } + peek(offset) { + let idx = this.chunkOff + offset, pos, result; + if (idx >= 0 && idx < this.chunk.length) { + pos = this.pos + offset; + result = this.chunk.charCodeAt(idx); + } + else { + let resolved = this.resolveOffset(offset, 1); + if (resolved == null) + return -1; + pos = resolved; + if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) { + result = this.chunk2.charCodeAt(pos - this.chunk2Pos); + } + else { + let i = this.rangeIndex, range = this.range; + while (range.to <= pos) + range = this.ranges[++i]; + this.chunk2 = this.input.chunk(this.chunk2Pos = pos); + if (pos + this.chunk2.length > range.to) + this.chunk2 = this.chunk2.slice(0, range.to - pos); + result = this.chunk2.charCodeAt(0); + } + } + if (pos >= this.token.lookAhead) + this.token.lookAhead = pos + 1; + return result; + } /** - Allows you to register abort handlers, which will be called when - the query is - [aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted). + Accept a token. By default, the end of the token is set to the + current stream position, but you can pass an offset (relative to + the stream position) to change that. */ - addEventListener(type, listener) { - if (type == "abort" && this.abortListeners) - this.abortListeners.push(listener); + acceptToken(token, endOffset = 0) { + let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos; + if (end == null || end < this.token.start) + throw new RangeError("Token end out of bounds"); + this.token.value = token; + this.token.end = end; } -} -function toSet(chars) { - let flat = Object.keys(chars).join(""); - let words = /\w/.test(flat); - if (words) - flat = flat.replace(/\w/g, ""); - return `[${words ? "\\w" : ""}${flat.replace(/[^\w\s]/g, "\\$&")}]`; -} -function prefixMatch(options) { - let first = Object.create(null), rest = Object.create(null); - for (let { label } of options) { - first[label[0]] = true; - for (let i = 1; i < label.length; i++) - rest[label[i]] = true; + /** + Accept a token ending at a specific given position. + */ + acceptTokenTo(token, endPos) { + this.token.value = token; + this.token.end = endPos; + } + getChunk() { + if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) { + let { chunk, chunkPos } = this; + this.chunk = this.chunk2; + this.chunkPos = this.chunk2Pos; + this.chunk2 = chunk; + this.chunk2Pos = chunkPos; + this.chunkOff = this.pos - this.chunkPos; + } + else { + this.chunk2 = this.chunk; + this.chunk2Pos = this.chunkPos; + let nextChunk = this.input.chunk(this.pos); + let end = this.pos + nextChunk.length; + this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk; + this.chunkPos = this.pos; + this.chunkOff = 0; + } + } + readNext() { + if (this.chunkOff >= this.chunk.length) { + this.getChunk(); + if (this.chunkOff == this.chunk.length) + return this.next = -1; + } + return this.next = this.chunk.charCodeAt(this.chunkOff); + } + /** + Move the stream forward N (defaults to 1) code units. Returns + the new value of [`next`](#lr.InputStream.next). + */ + advance(n = 1) { + this.chunkOff += n; + while (this.pos + n >= this.range.to) { + if (this.rangeIndex == this.ranges.length - 1) + return this.setDone(); + n -= this.range.to - this.pos; + this.range = this.ranges[++this.rangeIndex]; + this.pos = this.range.from; + } + this.pos += n; + if (this.pos >= this.token.lookAhead) + this.token.lookAhead = this.pos + 1; + return this.readNext(); + } + setDone() { + this.pos = this.chunkPos = this.end; + this.range = this.ranges[this.rangeIndex = this.ranges.length - 1]; + this.chunk = ""; + return this.next = -1; + } + /** + @internal + */ + reset(pos, token) { + if (token) { + this.token = token; + token.start = pos; + token.lookAhead = pos + 1; + token.value = token.extended = -1; + } + else { + this.token = nullToken; + } + if (this.pos != pos) { + this.pos = pos; + if (pos == this.end) { + this.setDone(); + return this; + } + while (pos < this.range.from) + this.range = this.ranges[--this.rangeIndex]; + while (pos >= this.range.to) + this.range = this.ranges[++this.rangeIndex]; + if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) { + this.chunkOff = pos - this.chunkPos; + } + else { + this.chunk = ""; + this.chunkOff = 0; + } + this.readNext(); + } + return this; + } + /** + @internal + */ + read(from, to) { + if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length) + return this.chunk.slice(from - this.chunkPos, to - this.chunkPos); + if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length) + return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos); + if (from >= this.range.from && to <= this.range.to) + return this.input.read(from, to); + let result = ""; + for (let r of this.ranges) { + if (r.from >= to) + break; + if (r.to > from) + result += this.input.read(Math.max(r.from, from), Math.min(r.to, to)); + } + return result; } - let source = toSet(first) + toSet(rest) + "*$"; - return [new RegExp("^" + source), new RegExp(source)]; } /** -Given a a fixed array of options, return an autocompleter that -completes them. +@internal */ -function completeFromList(list) { - let options = list.map(o => typeof o == "string" ? { label: o } : o); - let [validFor, match] = options.every(o => /^\w+$/.test(o.label)) ? [/\w*$/, /\w+$/] : prefixMatch(options); - return (context) => { - let token = context.matchBefore(match); - return token || context.explicit ? { from: token ? token.from : context.pos, options, validFor } : null; - }; +class TokenGroup { + constructor(data, id) { + this.data = data; + this.id = id; + } + token(input, stack) { + let { parser } = stack.p; + readToken(this.data, input, stack, this.id, parser.data, parser.tokenPrecTable); + } } +TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false; /** -Wrap the given completion source so that it will not fire when the -cursor is in a syntax node with one of the given names. +@hide */ -function ifNotIn(nodes, source) { - return (context) => { - for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) { - if (nodes.indexOf(pos.name) > -1) - return null; - if (pos.type.isTop) - break; - } - return source(context); - }; -} -class Option { - constructor(completion, source, match, score) { - this.completion = completion; - this.source = source; - this.match = match; - this.score = score; +class LocalTokenGroup { + constructor(data, precTable, elseToken) { + this.precTable = precTable; + this.elseToken = elseToken; + this.data = typeof data == "string" ? decodeArray(data) : data; + } + token(input, stack) { + let start = input.pos, skipped = 0; + for (;;) { + let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1); + readToken(this.data, input, stack, 0, this.data, this.precTable); + if (input.token.value > -1) + break; + if (this.elseToken == null) + return; + if (!atEof) + skipped++; + if (nextPos == null) + break; + input.reset(nextPos, input.token); + } + if (skipped) { + input.reset(start, input.token); + input.acceptToken(this.elseToken, skipped); + } } } -function cur(state) { return state.selection.main.from; } -// Make sure the given regexp has a $ at its end and, if `start` is -// true, a ^ at its start. -function ensureAnchor(expr, start) { - var _a; - let { source } = expr; - let addStart = start && source[0] != "^", addEnd = source[source.length - 1] != "$"; - if (!addStart && !addEnd) - return expr; - return new RegExp(`${addStart ? "^" : ""}(?:${source})${addEnd ? "$" : ""}`, (_a = expr.flags) !== null && _a !== void 0 ? _a : (expr.ignoreCase ? "i" : "")); -} -/** -This annotation is added to transactions that are produced by -picking a completion. -*/ -const pickedCompletion = /*@__PURE__*/Annotation.define(); +LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false; /** -Helper function that returns a transaction spec which inserts a -completion's text in the main selection range, and any other -selection range that has the same text in front of it. +`@external tokens` declarations in the grammar should resolve to +an instance of this class. */ -function insertCompletionText(state, text, from, to) { - let { main } = state.selection, fromOff = from - main.from, toOff = to - main.from; - return Object.assign(Object.assign({}, state.changeByRange(range => { - if (range != main && from != to && - state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to)) - return { range }; - return { - changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: text }, - range: EditorSelection.cursor(range.from + fromOff + text.length) - }; - })), { scrollIntoView: true, userEvent: "input.complete" }); +class ExternalTokenizer { + /** + Create a tokenizer. The first argument is the function that, + given an input stream, scans for the types of tokens it + recognizes at the stream's position, and calls + [`acceptToken`](#lr.InputStream.acceptToken) when it finds + one. + */ + constructor( + /** + @internal + */ + token, options = {}) { + this.token = token; + this.contextual = !!options.contextual; + this.fallback = !!options.fallback; + this.extend = !!options.extend; + } } -const SourceCache = /*@__PURE__*/new WeakMap(); -function asSource(source) { - if (!Array.isArray(source)) - return source; - let known = SourceCache.get(source); - if (!known) - SourceCache.set(source, known = completeFromList(source)); - return known; +// Tokenizer data is stored a big uint16 array containing, for each +// state: +// +// - A group bitmask, indicating what token groups are reachable from +// this state, so that paths that can only lead to tokens not in +// any of the current groups can be cut off early. +// +// - The position of the end of the state's sequence of accepting +// tokens +// +// - The number of outgoing edges for the state +// +// - The accepting tokens, as (token id, group mask) pairs +// +// - The outgoing edges, as (start character, end character, state +// index) triples, with end character being exclusive +// +// This function interprets that data, running through a stream as +// long as new states with the a matching group mask can be reached, +// and updating `input.token` when it matches a token. +function readToken(data, input, stack, group, precTable, precOffset) { + let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser; + scan: for (;;) { + if ((groupMask & data[state]) == 0) + break; + let accEnd = data[state + 1]; + // Check whether this state can lead to a token in the current group + // Accept tokens in this state, possibly overwriting + // lower-precedence / shorter tokens + for (let i = state + 3; i < accEnd; i += 2) + if ((data[i + 1] & groupMask) > 0) { + let term = data[i]; + if (dialect.allows(term) && + (input.token.value == -1 || input.token.value == term || + overrides(term, input.token.value, precTable, precOffset))) { + input.acceptToken(term); + break; + } + } + let next = input.next, low = 0, high = data[state + 2]; + // Special case for EOF + if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535 /* Seq.End */) { + state = data[accEnd + high * 3 - 1]; + continue scan; + } + // Do a binary search on the state's edges + for (; low < high;) { + let mid = (low + high) >> 1; + let index = accEnd + mid + (mid << 1); + let from = data[index], to = data[index + 1] || 0x10000; + if (next < from) + high = mid; + else if (next >= to) + low = mid + 1; + else { + state = data[index + 2]; + input.advance(); + continue scan; + } + } + break; + } +} +function findOffset(data, start, term) { + for (let i = start, next; (next = data[i]) != 65535 /* Seq.End */; i++) + if (next == term) + return i - start; + return -1; +} +function overrides(token, prev, tableData, tableOffset) { + let iPrev = findOffset(tableData, tableOffset, prev); + return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev; } -const startCompletionEffect = /*@__PURE__*/StateEffect.define(); -const closeCompletionEffect = /*@__PURE__*/StateEffect.define(); -// A pattern matcher for fuzzy completion matching. Create an instance -// once for a pattern, and then use that to match any number of -// completions. -class FuzzyMatcher { - constructor(pattern) { - this.pattern = pattern; - this.chars = []; - this.folded = []; - // Buffers reused by calls to `match` to track matched character - // positions. - this.any = []; - this.precise = []; - this.byWord = []; - this.score = 0; - this.matched = []; - for (let p = 0; p < pattern.length;) { - let char = codePointAt(pattern, p), size = codePointSize(char); - this.chars.push(char); - let part = pattern.slice(p, p + size), upper = part.toUpperCase(); - this.folded.push(codePointAt(upper == part ? part.toLowerCase() : upper, 0)); - p += size; - } - this.astral = pattern.length != this.chars.length; +// Environment variable used to control console output +const verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG); +let stackIDs = null; +function cutAt(tree, pos, side) { + let cursor = tree.cursor(IterMode.IncludeAnonymous); + cursor.moveTo(pos); + for (;;) { + if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos))) + for (;;) { + if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError) + return side < 0 ? Math.max(0, Math.min(cursor.to - 1, pos - 25 /* Lookahead.Margin */)) + : Math.min(tree.length, Math.max(cursor.from + 1, pos + 25 /* Lookahead.Margin */)); + if (side < 0 ? cursor.prevSibling() : cursor.nextSibling()) + break; + if (!cursor.parent()) + return side < 0 ? 0 : tree.length; + } } - ret(score, matched) { - this.score = score; - this.matched = matched; - return this; +} +class FragmentCursor { + constructor(fragments, nodeSet) { + this.fragments = fragments; + this.nodeSet = nodeSet; + this.i = 0; + this.fragment = null; + this.safeFrom = -1; + this.safeTo = -1; + this.trees = []; + this.start = []; + this.index = []; + this.nextFragment(); } - // Matches a given word (completion) against the pattern (input). - // Will return a boolean indicating whether there was a match and, - // on success, set `this.score` to the score, `this.matched` to an - // array of `from, to` pairs indicating the matched parts of `word`. - // - // The score is a number that is more negative the worse the match - // is. See `Penalty` above. - match(word) { - if (this.pattern.length == 0) - return this.ret(-100 /* Penalty.NotFull */, []); - if (word.length < this.pattern.length) + nextFragment() { + let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++]; + if (fr) { + this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from; + this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to; + while (this.trees.length) { + this.trees.pop(); + this.start.pop(); + this.index.pop(); + } + this.trees.push(fr.tree); + this.start.push(-fr.offset); + this.index.push(0); + this.nextStart = this.safeFrom; + } + else { + this.nextStart = 1e9; + } + } + // `pos` must be >= any previously given `pos` for this cursor + nodeAt(pos) { + if (pos < this.nextStart) return null; - let { chars, folded, any, precise, byWord } = this; - // For single-character queries, only match when they occur right - // at the start - if (chars.length == 1) { - let first = codePointAt(word, 0), firstSize = codePointSize(first); - let score = firstSize == word.length ? 0 : -100 /* Penalty.NotFull */; - if (first == chars[0]) ; - else if (first == folded[0]) - score += -200 /* Penalty.CaseFold */; - else + while (this.fragment && this.safeTo <= pos) + this.nextFragment(); + if (!this.fragment) + return null; + for (;;) { + let last = this.trees.length - 1; + if (last < 0) { // End of tree + this.nextFragment(); return null; - return this.ret(score, [0, firstSize]); - } - let direct = word.indexOf(this.pattern); - if (direct == 0) - return this.ret(word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */, [0, this.pattern.length]); - let len = chars.length, anyTo = 0; - if (direct < 0) { - for (let i = 0, e = Math.min(word.length, 200); i < e && anyTo < len;) { - let next = codePointAt(word, i); - if (next == chars[anyTo] || next == folded[anyTo]) - any[anyTo++] = i; - i += codePointSize(next); } - // No match, exit immediately - if (anyTo < len) + let top = this.trees[last], index = this.index[last]; + if (index == top.children.length) { + this.trees.pop(); + this.start.pop(); + this.index.pop(); + continue; + } + let next = top.children[index]; + let start = this.start[last] + top.positions[index]; + if (start > pos) { + this.nextStart = start; return null; - } - // This tracks the extent of the precise (non-folded, not - // necessarily adjacent) match - let preciseTo = 0; - // Tracks whether there is a match that hits only characters that - // appear to be starting words. `byWordFolded` is set to true when - // a case folded character is encountered in such a match - let byWordTo = 0, byWordFolded = false; - // If we've found a partial adjacent match, these track its state - let adjacentTo = 0, adjacentStart = -1, adjacentEnd = -1; - let hasLower = /[a-z]/.test(word), wordAdjacent = true; - // Go over the option's text, scanning for the various kinds of matches - for (let i = 0, e = Math.min(word.length, 200), prevType = 0 /* Tp.NonWord */; i < e && byWordTo < len;) { - let next = codePointAt(word, i); - if (direct < 0) { - if (preciseTo < len && next == chars[preciseTo]) - precise[preciseTo++] = i; - if (adjacentTo < len) { - if (next == chars[adjacentTo] || next == folded[adjacentTo]) { - if (adjacentTo == 0) - adjacentStart = i; - adjacentEnd = i + 1; - adjacentTo++; - } - else { - adjacentTo = 0; + } + if (next instanceof Tree) { + if (start == pos) { + if (start < this.safeFrom) + return null; + let end = start + next.length; + if (end <= this.safeTo) { + let lookAhead = next.prop(NodeProp.lookAhead); + if (!lookAhead || end + lookAhead < this.fragment.to) + return next; } } + this.index[last]++; + if (start + next.length >= Math.max(this.safeFrom, pos)) { // Enter this node + this.trees.push(next); + this.start.push(start); + this.index.push(0); + } } - let ch, type = next < 0xff - ? (next >= 48 && next <= 57 || next >= 97 && next <= 122 ? 2 /* Tp.Lower */ : next >= 65 && next <= 90 ? 1 /* Tp.Upper */ : 0 /* Tp.NonWord */) - : ((ch = fromCodePoint(next)) != ch.toLowerCase() ? 1 /* Tp.Upper */ : ch != ch.toUpperCase() ? 2 /* Tp.Lower */ : 0 /* Tp.NonWord */); - if (!i || type == 1 /* Tp.Upper */ && hasLower || prevType == 0 /* Tp.NonWord */ && type != 0 /* Tp.NonWord */) { - if (chars[byWordTo] == next || (folded[byWordTo] == next && (byWordFolded = true))) - byWord[byWordTo++] = i; - else if (byWord.length) - wordAdjacent = false; - } - prevType = type; - i += codePointSize(next); - } - if (byWordTo == len && byWord[0] == 0 && wordAdjacent) - return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0), byWord, word); - if (adjacentTo == len && adjacentStart == 0) - return this.ret(-200 /* Penalty.CaseFold */ - word.length + (adjacentEnd == word.length ? 0 : -100 /* Penalty.NotFull */), [0, adjacentEnd]); - if (direct > -1) - return this.ret(-700 /* Penalty.NotStart */ - word.length, [direct, direct + this.pattern.length]); - if (adjacentTo == len) - return this.ret(-200 /* Penalty.CaseFold */ + -700 /* Penalty.NotStart */ - word.length, [adjacentStart, adjacentEnd]); - if (byWordTo == len) - return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0) + -700 /* Penalty.NotStart */ + - (wordAdjacent ? 0 : -1100 /* Penalty.Gap */), byWord, word); - return chars.length == 2 ? null - : this.result((any[0] ? -700 /* Penalty.NotStart */ : 0) + -200 /* Penalty.CaseFold */ + -1100 /* Penalty.Gap */, any, word); - } - result(score, positions, word) { - let result = [], i = 0; - for (let pos of positions) { - let to = pos + (this.astral ? codePointSize(codePointAt(word, pos)) : 1); - if (i && result[i - 1] == pos) - result[i - 1] = to; else { - result[i++] = pos; - result[i++] = to; + this.index[last]++; + this.nextStart = start + next.length; } } - return this.ret(score - word.length, result); - } -} -class StrictMatcher { - constructor(pattern) { - this.pattern = pattern; - this.matched = []; - this.score = 0; - this.folded = pattern.toLowerCase(); } - match(word) { - if (word.length < this.pattern.length) - return null; - let start = word.slice(0, this.pattern.length); - let match = start == this.pattern ? 0 : start.toLowerCase() == this.folded ? -200 /* Penalty.CaseFold */ : null; - if (match == null) - return null; - this.matched = [0, start.length]; - this.score = match + (word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */); - return this; - } -} - -const completionConfig = /*@__PURE__*/Facet.define({ - combine(configs) { - return combineConfig(configs, { - activateOnTyping: true, - activateOnCompletion: () => false, - activateOnTypingDelay: 100, - selectOnOpen: true, - override: null, - closeOnBlur: true, - maxRenderedOptions: 100, - defaultKeymap: true, - tooltipClass: () => "", - optionClass: () => "", - aboveCursor: false, - icons: true, - addToOptions: [], - positionInfo: defaultPositionInfo, - filterStrict: false, - compareCompletions: (a, b) => a.label.localeCompare(b.label), - interactionDelay: 75, - updateSyncTime: 100 - }, { - defaultKeymap: (a, b) => a && b, - closeOnBlur: (a, b) => a && b, - icons: (a, b) => a && b, - tooltipClass: (a, b) => c => joinClass(a(c), b(c)), - optionClass: (a, b) => c => joinClass(a(c), b(c)), - addToOptions: (a, b) => a.concat(b), - filterStrict: (a, b) => a || b, - }); - } -}); -function joinClass(a, b) { - return a ? b ? a + " " + b : a : b; } -function defaultPositionInfo(view, list, option, info, space, tooltip) { - let rtl = view.textDirection == Direction.RTL, left = rtl, narrow = false; - let side = "top", offset, maxWidth; - let spaceLeft = list.left - space.left, spaceRight = space.right - list.right; - let infoWidth = info.right - info.left, infoHeight = info.bottom - info.top; - if (left && spaceLeft < Math.min(infoWidth, spaceRight)) - left = false; - else if (!left && spaceRight < Math.min(infoWidth, spaceLeft)) - left = true; - if (infoWidth <= (left ? spaceLeft : spaceRight)) { - offset = Math.max(space.top, Math.min(option.top, space.bottom - infoHeight)) - list.top; - maxWidth = Math.min(400 /* Info.Width */, left ? spaceLeft : spaceRight); +class TokenCache { + constructor(parser, stream) { + this.stream = stream; + this.tokens = []; + this.mainToken = null; + this.actions = []; + this.tokens = parser.tokenizers.map(_ => new CachedToken); } - else { - narrow = true; - maxWidth = Math.min(400 /* Info.Width */, (rtl ? list.right : space.right - list.left) - 30 /* Info.Margin */); - let spaceBelow = space.bottom - list.bottom; - if (spaceBelow >= infoHeight || spaceBelow > list.top) { // Below the completion - offset = option.bottom - list.top; + getActions(stack) { + let actionIndex = 0; + let main = null; + let { parser } = stack.p, { tokenizers } = parser; + let mask = parser.stateSlot(stack.state, 3 /* ParseState.TokenizerMask */); + let context = stack.curContext ? stack.curContext.hash : 0; + let lookAhead = 0; + for (let i = 0; i < tokenizers.length; i++) { + if (((1 << i) & mask) == 0) + continue; + let tokenizer = tokenizers[i], token = this.tokens[i]; + if (main && !tokenizer.fallback) + continue; + if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) { + this.updateCachedToken(token, tokenizer, stack); + token.mask = mask; + token.context = context; + } + if (token.lookAhead > token.end + 25 /* Lookahead.Margin */) + lookAhead = Math.max(token.lookAhead, lookAhead); + if (token.value != 0 /* Term.Err */) { + let startIndex = actionIndex; + if (token.extended > -1) + actionIndex = this.addActions(stack, token.extended, token.end, actionIndex); + actionIndex = this.addActions(stack, token.value, token.end, actionIndex); + if (!tokenizer.extend) { + main = token; + if (actionIndex > startIndex) + break; + } + } } - else { // Above it - side = "bottom"; - offset = list.bottom - option.top; + while (this.actions.length > actionIndex) + this.actions.pop(); + if (lookAhead) + stack.setLookAhead(lookAhead); + if (!main && stack.pos == this.stream.end) { + main = new CachedToken; + main.value = stack.p.parser.eofTerm; + main.start = main.end = stack.pos; + actionIndex = this.addActions(stack, main.value, main.end, actionIndex); } + this.mainToken = main; + return this.actions; } - let scaleY = (list.bottom - list.top) / tooltip.offsetHeight; - let scaleX = (list.right - list.left) / tooltip.offsetWidth; - return { - style: `${side}: ${offset / scaleY}px; max-width: ${maxWidth / scaleX}px`, - class: "cm-completionInfo-" + (narrow ? (rtl ? "left-narrow" : "right-narrow") : left ? "left" : "right") - }; -} - -function optionContent(config) { - let content = config.addToOptions.slice(); - if (config.icons) - content.push({ - render(completion) { - let icon = document.createElement("div"); - icon.classList.add("cm-completionIcon"); - if (completion.type) - icon.classList.add(...completion.type.split(/\s+/g).map(cls => "cm-completionIcon-" + cls)); - icon.setAttribute("aria-hidden", "true"); - return icon; - }, - position: 20 - }); - content.push({ - render(completion, _s, _v, match) { - let labelElt = document.createElement("span"); - labelElt.className = "cm-completionLabel"; - let label = completion.displayLabel || completion.label, off = 0; - for (let j = 0; j < match.length;) { - let from = match[j++], to = match[j++]; - if (from > off) - labelElt.appendChild(document.createTextNode(label.slice(off, from))); - let span = labelElt.appendChild(document.createElement("span")); - span.appendChild(document.createTextNode(label.slice(from, to))); - span.className = "cm-completionMatchedText"; - off = to; - } - if (off < label.length) - labelElt.appendChild(document.createTextNode(label.slice(off))); - return labelElt; - }, - position: 50 - }, { - render(completion) { - if (!completion.detail) - return null; - let detailElt = document.createElement("span"); - detailElt.className = "cm-completionDetail"; - detailElt.textContent = completion.detail; - return detailElt; - }, - position: 80 - }); - return content.sort((a, b) => a.position - b.position).map(a => a.render); -} -function rangeAroundSelected(total, selected, max) { - if (total <= max) - return { from: 0, to: total }; - if (selected < 0) - selected = 0; - if (selected <= (total >> 1)) { - let off = Math.floor(selected / max); - return { from: off * max, to: (off + 1) * max }; + getMainToken(stack) { + if (this.mainToken) + return this.mainToken; + let main = new CachedToken, { pos, p } = stack; + main.start = pos; + main.end = Math.min(pos + 1, p.stream.end); + main.value = pos == p.stream.end ? p.parser.eofTerm : 0 /* Term.Err */; + return main; } - let off = Math.floor((total - selected) / max); - return { from: total - (off + 1) * max, to: total - off * max }; -} -class CompletionTooltip { - constructor(view, stateField, applyCompletion) { - this.view = view; - this.stateField = stateField; - this.applyCompletion = applyCompletion; - this.info = null; - this.infoDestroy = null; - this.placeInfoReq = { - read: () => this.measureInfo(), - write: (pos) => this.placeInfo(pos), - key: this - }; - this.space = null; - this.currentClass = ""; - let cState = view.state.field(stateField); - let { options, selected } = cState.open; - let config = view.state.facet(completionConfig); - this.optionContent = optionContent(config); - this.optionClass = config.optionClass; - this.tooltipClass = config.tooltipClass; - this.range = rangeAroundSelected(options.length, selected, config.maxRenderedOptions); - this.dom = document.createElement("div"); - this.dom.className = "cm-tooltip-autocomplete"; - this.updateTooltipClass(view.state); - this.dom.addEventListener("mousedown", (e) => { - let { options } = view.state.field(stateField).open; - for (let dom = e.target, match; dom && dom != this.dom; dom = dom.parentNode) { - if (dom.nodeName == "LI" && (match = /-(\d+)$/.exec(dom.id)) && +match[1] < options.length) { - this.applyCompletion(view, options[+match[1]]); - e.preventDefault(); - return; + updateCachedToken(token, tokenizer, stack) { + let start = this.stream.clipPos(stack.pos); + tokenizer.token(this.stream.reset(start, token), stack); + if (token.value > -1) { + let { parser } = stack.p; + for (let i = 0; i < parser.specialized.length; i++) + if (parser.specialized[i] == token.value) { + let result = parser.specializers[i](this.stream.read(token.start, token.end), stack); + if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) { + if ((result & 1) == 0 /* Specialize.Specialize */) + token.value = result >> 1; + else + token.extended = result >> 1; + break; + } } - } - }); - this.dom.addEventListener("focusout", (e) => { - let state = view.state.field(this.stateField, false); - if (state && state.tooltip && view.state.facet(completionConfig).closeOnBlur && - e.relatedTarget != view.contentDOM) - view.dispatch({ effects: closeCompletionEffect.of(null) }); - }); - this.showOptions(options, cState.id); - } - mount() { this.updateSel(); } - showOptions(options, id) { - if (this.list) - this.list.remove(); - this.list = this.dom.appendChild(this.createListBox(options, id, this.range)); - this.list.addEventListener("scroll", () => { - if (this.info) - this.view.requestMeasure(this.placeInfoReq); - }); - } - update(update) { - var _a; - let cState = update.state.field(this.stateField); - let prevState = update.startState.field(this.stateField); - this.updateTooltipClass(update.state); - if (cState != prevState) { - let { options, selected, disabled } = cState.open; - if (!prevState.open || prevState.open.options != options) { - this.range = rangeAroundSelected(options.length, selected, update.state.facet(completionConfig).maxRenderedOptions); - this.showOptions(options, cState.id); - } - this.updateSel(); - if (disabled != ((_a = prevState.open) === null || _a === void 0 ? void 0 : _a.disabled)) - this.dom.classList.toggle("cm-tooltip-autocomplete-disabled", !!disabled); - } - } - updateTooltipClass(state) { - let cls = this.tooltipClass(state); - if (cls != this.currentClass) { - for (let c of this.currentClass.split(" ")) - if (c) - this.dom.classList.remove(c); - for (let c of cls.split(" ")) - if (c) - this.dom.classList.add(c); - this.currentClass = cls; - } - } - positioned(space) { - this.space = space; - if (this.info) - this.view.requestMeasure(this.placeInfoReq); - } - updateSel() { - let cState = this.view.state.field(this.stateField), open = cState.open; - if (open.selected > -1 && open.selected < this.range.from || open.selected >= this.range.to) { - this.range = rangeAroundSelected(open.options.length, open.selected, this.view.state.facet(completionConfig).maxRenderedOptions); - this.showOptions(open.options, cState.id); - } - if (this.updateSelectedOption(open.selected)) { - this.destroyInfo(); - let { completion } = open.options[open.selected]; - let { info } = completion; - if (!info) - return; - let infoResult = typeof info === "string" ? document.createTextNode(info) : info(completion); - if (!infoResult) - return; - if ("then" in infoResult) { - infoResult.then(obj => { - if (obj && this.view.state.field(this.stateField, false) == cState) - this.addInfoPane(obj, completion); - }).catch(e => logException(this.view.state, e, "completion info")); - } - else { - this.addInfoPane(infoResult, completion); - } - } - } - addInfoPane(content, completion) { - this.destroyInfo(); - let wrap = this.info = document.createElement("div"); - wrap.className = "cm-tooltip cm-completionInfo"; - if (content.nodeType != null) { - wrap.appendChild(content); - this.infoDestroy = null; } else { - let { dom, destroy } = content; - wrap.appendChild(dom); - this.infoDestroy = destroy || null; + token.value = 0 /* Term.Err */; + token.end = this.stream.clipPos(start + 1); } - this.dom.appendChild(wrap); - this.view.requestMeasure(this.placeInfoReq); } - updateSelectedOption(selected) { - let set = null; - for (let opt = this.list.firstChild, i = this.range.from; opt; opt = opt.nextSibling, i++) { - if (opt.nodeName != "LI" || !opt.id) { - i--; // A section header - } - else if (i == selected) { - if (!opt.hasAttribute("aria-selected")) { - opt.setAttribute("aria-selected", "true"); - set = opt; + putAction(action, token, end, index) { + // Don't add duplicate actions + for (let i = 0; i < index; i += 3) + if (this.actions[i] == action) + return index; + this.actions[index++] = action; + this.actions[index++] = token; + this.actions[index++] = end; + return index; + } + addActions(stack, token, end, index) { + let { state } = stack, { parser } = stack.p, { data } = parser; + for (let set = 0; set < 2; set++) { + for (let i = parser.stateSlot(state, set ? 2 /* ParseState.Skip */ : 1 /* ParseState.Actions */);; i += 3) { + if (data[i] == 65535 /* Seq.End */) { + if (data[i + 1] == 1 /* Seq.Next */) { + i = pair(data, i + 2); + } + else { + if (index == 0 && data[i + 1] == 2 /* Seq.Other */) + index = this.putAction(pair(data, i + 2), token, end, index); + break; + } } - } - else { - if (opt.hasAttribute("aria-selected")) - opt.removeAttribute("aria-selected"); + if (data[i] == token) + index = this.putAction(pair(data, i + 1), token, end, index); } } - if (set) - scrollIntoView(this.list, set); - return set; + return index; } - measureInfo() { - let sel = this.dom.querySelector("[aria-selected]"); - if (!sel || !this.info) - return null; - let listRect = this.dom.getBoundingClientRect(); - let infoRect = this.info.getBoundingClientRect(); - let selRect = sel.getBoundingClientRect(); - let space = this.space; - if (!space) { - let win = this.dom.ownerDocument.defaultView || window; - space = { left: 0, top: 0, right: win.innerWidth, bottom: win.innerHeight }; - } - if (selRect.top > Math.min(space.bottom, listRect.bottom) - 10 || - selRect.bottom < Math.max(space.top, listRect.top) + 10) - return null; - return this.view.state.facet(completionConfig).positionInfo(this.view, listRect, selRect, infoRect, space, this.dom); +} +class Parse { + constructor(parser, input, fragments, ranges) { + this.parser = parser; + this.input = input; + this.ranges = ranges; + this.recovering = 0; + this.nextStackID = 0x2654; // ♔, ♕, ♖, ♗, ♘, ♙, ♠, ♡, ♢, ♣, ♤, ♥, ♦, ♧ + this.minStackPos = 0; + this.reused = []; + this.stoppedAt = null; + this.lastBigReductionStart = -1; + this.lastBigReductionSize = 0; + this.bigReductionCount = 0; + this.stream = new InputStream(input, ranges); + this.tokens = new TokenCache(parser, this.stream); + this.topTerm = parser.top[1]; + let { from } = ranges[0]; + this.stacks = [Stack.start(this, parser.top[0], from)]; + this.fragments = fragments.length && this.stream.end - from > parser.bufferLength * 4 + ? new FragmentCursor(fragments, parser.nodeSet) : null; } - placeInfo(pos) { - if (this.info) { - if (pos) { - if (pos.style) - this.info.style.cssText = pos.style; - this.info.className = "cm-tooltip cm-completionInfo " + (pos.class || ""); - } - else { - this.info.style.cssText = "top: -1e6px"; - } - } + get parsedPos() { + return this.minStackPos; } - createListBox(options, id, range) { - const ul = document.createElement("ul"); - ul.id = id; - ul.setAttribute("role", "listbox"); - ul.setAttribute("aria-expanded", "true"); - ul.setAttribute("aria-label", this.view.state.phrase("Completions")); - let curSection = null; - for (let i = range.from; i < range.to; i++) { - let { completion, match } = options[i], { section } = completion; - if (section) { - let name = typeof section == "string" ? section : section.name; - if (name != curSection && (i > range.from || range.from == 0)) { - curSection = name; - if (typeof section != "string" && section.header) { - ul.appendChild(section.header(section)); - } - else { - let header = ul.appendChild(document.createElement("completion-section")); - header.textContent = name; + // Move the parser forward. This will process all parse stacks at + // `this.pos` and try to advance them to a further position. If no + // stack for such a position is found, it'll start error-recovery. + // + // When the parse is finished, this will return a syntax tree. When + // not, it returns `null`. + advance() { + let stacks = this.stacks, pos = this.minStackPos; + // This will hold stacks beyond `pos`. + let newStacks = this.stacks = []; + let stopped, stoppedTokens; + // If a large amount of reductions happened with the same start + // position, force the stack out of that production in order to + // avoid creating a tree too deep to recurse through. + // (This is an ugly kludge, because unfortunately there is no + // straightforward, cheap way to check for this happening, due to + // the history of reductions only being available in an + // expensive-to-access format in the stack buffers.) + if (this.bigReductionCount > 300 /* Rec.MaxLeftAssociativeReductionCount */ && stacks.length == 1) { + let [s] = stacks; + while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) { } + this.bigReductionCount = this.lastBigReductionSize = 0; + } + // Keep advancing any stacks at `pos` until they either move + // forward or can't be advanced. Gather stacks that can't be + // advanced further in `stopped`. + for (let i = 0; i < stacks.length; i++) { + let stack = stacks[i]; + for (;;) { + this.tokens.mainToken = null; + if (stack.pos > pos) { + newStacks.push(stack); + } + else if (this.advanceStack(stack, newStacks, stacks)) { + continue; + } + else { + if (!stopped) { + stopped = []; + stoppedTokens = []; } + stopped.push(stack); + let tok = this.tokens.getMainToken(stack); + stoppedTokens.push(tok.value, tok.end); } - } - const li = ul.appendChild(document.createElement("li")); - li.id = id + "-" + i; - li.setAttribute("role", "option"); - let cls = this.optionClass(completion); - if (cls) - li.className = cls; - for (let source of this.optionContent) { - let node = source(completion, this.view.state, this.view, match); - if (node) - li.appendChild(node); + break; } } - if (range.from) - ul.classList.add("cm-completionListIncompleteTop"); - if (range.to < options.length) - ul.classList.add("cm-completionListIncompleteBottom"); - return ul; - } - destroyInfo() { - if (this.info) { - if (this.infoDestroy) - this.infoDestroy(); - this.info.remove(); - this.info = null; + if (!newStacks.length) { + let finished = stopped && findFinished(stopped); + if (finished) { + if (verbose) + console.log("Finish with " + this.stackID(finished)); + return this.stackToTree(finished); + } + if (this.parser.strict) { + if (verbose && stopped) + console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none")); + throw new SyntaxError("No parse at " + pos); + } + if (!this.recovering) + this.recovering = 5 /* Rec.Distance */; } - } - destroy() { - this.destroyInfo(); - } -} -function completionTooltip(stateField, applyCompletion) { - return (view) => new CompletionTooltip(view, stateField, applyCompletion); -} -function scrollIntoView(container, element) { - let parent = container.getBoundingClientRect(); - let self = element.getBoundingClientRect(); - let scaleY = parent.height / container.offsetHeight; - if (self.top < parent.top) - container.scrollTop -= (parent.top - self.top) / scaleY; - else if (self.bottom > parent.bottom) - container.scrollTop += (self.bottom - parent.bottom) / scaleY; -} - -// Used to pick a preferred option when two options with the same -// label occur in the result. -function score(option) { - return (option.boost || 0) * 100 + (option.apply ? 10 : 0) + (option.info ? 5 : 0) + - (option.type ? 1 : 0); -} -function sortOptions(active, state) { - let options = []; - let sections = null; - let addOption = (option) => { - options.push(option); - let { section } = option.completion; - if (section) { - if (!sections) - sections = []; - let name = typeof section == "string" ? section : section.name; - if (!sections.some(s => s.name == name)) - sections.push(typeof section == "string" ? { name } : section); + if (this.recovering && stopped) { + let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] + : this.runRecovery(stopped, stoppedTokens, newStacks); + if (finished) { + if (verbose) + console.log("Force-finish " + this.stackID(finished)); + return this.stackToTree(finished.forceAll()); + } } - }; - let conf = state.facet(completionConfig); - for (let a of active) - if (a.hasResult()) { - let getMatch = a.result.getMatch; - if (a.result.filter === false) { - for (let option of a.result.options) { - addOption(new Option(option, a.source, getMatch ? getMatch(option) : [], 1e9 - options.length)); - } + if (this.recovering) { + let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3 /* Rec.MaxRemainingPerStep */; + if (newStacks.length > maxRemaining) { + newStacks.sort((a, b) => b.score - a.score); + while (newStacks.length > maxRemaining) + newStacks.pop(); } - else { - let pattern = state.sliceDoc(a.from, a.to), match; - let matcher = conf.filterStrict ? new StrictMatcher(pattern) : new FuzzyMatcher(pattern); - for (let option of a.result.options) - if (match = matcher.match(option.label)) { - let matched = !option.displayLabel ? match.matched : getMatch ? getMatch(option, match.matched) : []; - addOption(new Option(option, a.source, matched, match.score + (option.boost || 0))); + if (newStacks.some(s => s.reducePos > pos)) + this.recovering--; + } + else if (newStacks.length > 1) { + // Prune stacks that are in the same state, or that have been + // running without splitting for a while, to avoid getting stuck + // with multiple successful stacks running endlessly on. + outer: for (let i = 0; i < newStacks.length - 1; i++) { + let stack = newStacks[i]; + for (let j = i + 1; j < newStacks.length; j++) { + let other = newStacks[j]; + if (stack.sameState(other) || + stack.buffer.length > 500 /* Rec.MinBufferLengthPrune */ && other.buffer.length > 500 /* Rec.MinBufferLengthPrune */) { + if (((stack.score - other.score) || (stack.buffer.length - other.buffer.length)) > 0) { + newStacks.splice(j--, 1); + } + else { + newStacks.splice(i--, 1); + continue outer; + } } + } } + if (newStacks.length > 12 /* Rec.MaxStackCount */) + newStacks.splice(12 /* Rec.MaxStackCount */, newStacks.length - 12 /* Rec.MaxStackCount */); } - if (sections) { - let sectionOrder = Object.create(null), pos = 0; - let cmp = (a, b) => { var _a, _b; return ((_a = a.rank) !== null && _a !== void 0 ? _a : 1e9) - ((_b = b.rank) !== null && _b !== void 0 ? _b : 1e9) || (a.name < b.name ? -1 : 1); }; - for (let s of sections.sort(cmp)) { - pos -= 1e5; - sectionOrder[s.name] = pos; - } - for (let option of options) { - let { section } = option.completion; - if (section) - option.score += sectionOrder[typeof section == "string" ? section : section.name]; - } - } - let result = [], prev = null; - let compare = conf.compareCompletions; - for (let opt of options.sort((a, b) => (b.score - a.score) || compare(a.completion, b.completion))) { - let cur = opt.completion; - if (!prev || prev.label != cur.label || prev.detail != cur.detail || - (prev.type != null && cur.type != null && prev.type != cur.type) || - prev.apply != cur.apply || prev.boost != cur.boost) - result.push(opt); - else if (score(opt.completion) > score(prev)) - result[result.length - 1] = opt; - prev = opt.completion; + this.minStackPos = newStacks[0].pos; + for (let i = 1; i < newStacks.length; i++) + if (newStacks[i].pos < this.minStackPos) + this.minStackPos = newStacks[i].pos; + return null; } - return result; -} -class CompletionDialog { - constructor(options, attrs, tooltip, timestamp, selected, disabled) { - this.options = options; - this.attrs = attrs; - this.tooltip = tooltip; - this.timestamp = timestamp; - this.selected = selected; - this.disabled = disabled; + stopAt(pos) { + if (this.stoppedAt != null && this.stoppedAt < pos) + throw new RangeError("Can't move stoppedAt forward"); + this.stoppedAt = pos; } - setSelected(selected, id) { - return selected == this.selected || selected >= this.options.length ? this - : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled); + // Returns an updated version of the given stack, or null if the + // stack can't advance normally. When `split` and `stacks` are + // given, stacks split off by ambiguous operations will be pushed to + // `split`, or added to `stacks` if they move `pos` forward. + advanceStack(stack, stacks, split) { + let start = stack.pos, { parser } = this; + let base = verbose ? this.stackID(stack) + " -> " : ""; + if (this.stoppedAt != null && start > this.stoppedAt) + return stack.forceReduce() ? stack : null; + if (this.fragments) { + let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0; + for (let cached = this.fragments.nodeAt(start); cached;) { + let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser.getGoto(stack.state, cached.type.id) : -1; + if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) { + stack.useNode(cached, match); + if (verbose) + console.log(base + this.stackID(stack) + ` (via reuse of ${parser.getName(cached.type.id)})`); + return true; + } + if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0) + break; + let inner = cached.children[0]; + if (inner instanceof Tree && cached.positions[0] == 0) + cached = inner; + else + break; + } + } + let defaultReduce = parser.stateSlot(stack.state, 4 /* ParseState.DefaultReduce */); + if (defaultReduce > 0) { + stack.reduce(defaultReduce); + if (verbose) + console.log(base + this.stackID(stack) + ` (via always-reduce ${parser.getName(defaultReduce & 65535 /* Action.ValueMask */)})`); + return true; + } + if (stack.stack.length >= 8400 /* Rec.CutDepth */) { + while (stack.stack.length > 6000 /* Rec.CutTo */ && stack.forceReduce()) { } + } + let actions = this.tokens.getActions(stack); + for (let i = 0; i < actions.length;) { + let action = actions[i++], term = actions[i++], end = actions[i++]; + let last = i == actions.length || !split; + let localStack = last ? stack : stack.split(); + let main = this.tokens.mainToken; + localStack.apply(action, term, main ? main.start : localStack.pos, end); + if (verbose) + console.log(base + this.stackID(localStack) + ` (via ${(action & 65536 /* Action.ReduceFlag */) == 0 ? "shift" + : `reduce of ${parser.getName(action & 65535 /* Action.ValueMask */)}`} for ${parser.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`); + if (last) + return true; + else if (localStack.pos > start) + stacks.push(localStack); + else + split.push(localStack); + } + return false; } - static build(active, state, id, prev, conf) { - let options = sortOptions(active, state); - if (!options.length) { - return prev && active.some(a => a.state == 1 /* State.Pending */) ? - new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null; + // Advance a given stack forward as far as it will go. Returns the + // (possibly updated) stack if it got stuck, or null if it moved + // forward and was given to `pushStackDedup`. + advanceFully(stack, newStacks) { + let pos = stack.pos; + for (;;) { + if (!this.advanceStack(stack, null, null)) + return false; + if (stack.pos > pos) { + pushStackDedup(stack, newStacks); + return true; + } } - let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1; - if (prev && prev.selected != selected && prev.selected != -1) { - let selectedValue = prev.options[prev.selected].completion; - for (let i = 0; i < options.length; i++) - if (options[i].completion == selectedValue) { - selected = i; + } + runRecovery(stacks, tokens, newStacks) { + let finished = null, restarted = false; + for (let i = 0; i < stacks.length; i++) { + let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1]; + let base = verbose ? this.stackID(stack) + " -> " : ""; + if (stack.deadEnd) { + if (restarted) + continue; + restarted = true; + stack.restart(); + if (verbose) + console.log(base + this.stackID(stack) + " (restarted)"); + let done = this.advanceFully(stack, newStacks); + if (done) + continue; + } + let force = stack.split(), forceBase = base; + for (let j = 0; force.forceReduce() && j < 10 /* Rec.ForceReduceLimit */; j++) { + if (verbose) + console.log(forceBase + this.stackID(force) + " (via force-reduce)"); + let done = this.advanceFully(force, newStacks); + if (done) break; + if (verbose) + forceBase = this.stackID(force) + " -> "; + } + for (let insert of stack.recoverByInsert(token)) { + if (verbose) + console.log(base + this.stackID(insert) + " (via recover-insert)"); + this.advanceFully(insert, newStacks); + } + if (this.stream.end > stack.pos) { + if (tokenEnd == stack.pos) { + tokenEnd++; + token = 0 /* Term.Err */; } + stack.recoverByDelete(token, tokenEnd); + if (verbose) + console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`); + pushStackDedup(stack, newStacks); + } + else if (!finished || finished.score < stack.score) { + finished = stack; + } } - return new CompletionDialog(options, makeAttrs(id, selected), { - pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8), - create: createTooltip, - above: conf.aboveCursor, - }, prev ? prev.timestamp : Date.now(), selected, false); - } - map(changes) { - return new CompletionDialog(this.options, this.attrs, Object.assign(Object.assign({}, this.tooltip), { pos: changes.mapPos(this.tooltip.pos) }), this.timestamp, this.selected, this.disabled); - } -} -class CompletionState { - constructor(active, id, open) { - this.active = active; - this.id = id; - this.open = open; - } - static start() { - return new CompletionState(none$1, "cm-ac-" + Math.floor(Math.random() * 2e6).toString(36), null); + return finished; } - update(tr) { - let { state } = tr, conf = state.facet(completionConfig); - let sources = conf.override || - state.languageDataAt("autocomplete", cur(state)).map(asSource); - let active = sources.map(source => { - let value = this.active.find(s => s.source == source) || - new ActiveSource(source, this.active.some(a => a.state != 0 /* State.Inactive */) ? 1 /* State.Pending */ : 0 /* State.Inactive */); - return value.update(tr, conf); - }); - if (active.length == this.active.length && active.every((a, i) => a == this.active[i])) - active = this.active; - let open = this.open; - if (open && tr.docChanged) - open = open.map(tr.changes); - if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) || - !sameResults(active, this.active)) - open = CompletionDialog.build(active, state, this.id, open, conf); - else if (open && open.disabled && !active.some(a => a.state == 1 /* State.Pending */)) - open = null; - if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult())) - active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a); - for (let effect of tr.effects) - if (effect.is(setSelectedEffect)) - open = open && open.setSelected(effect.value, this.id); - return active == this.active && open == this.open ? this : new CompletionState(active, this.id, open); + // Convert the stack's buffer to a syntax tree. + stackToTree(stack) { + stack.close(); + return Tree.build({ buffer: StackBufferCursor.create(stack), + nodeSet: this.parser.nodeSet, + topID: this.topTerm, + maxBufferLength: this.parser.bufferLength, + reused: this.reused, + start: this.ranges[0].from, + length: stack.pos - this.ranges[0].from, + minRepeatType: this.parser.minRepeatTerm }); } - get tooltip() { return this.open ? this.open.tooltip : null; } - get attrs() { return this.open ? this.open.attrs : baseAttrs; } -} -function sameResults(a, b) { - if (a == b) - return true; - for (let iA = 0, iB = 0;;) { - while (iA < a.length && !a[iA].hasResult) - iA++; - while (iB < b.length && !b[iB].hasResult) - iB++; - let endA = iA == a.length, endB = iB == b.length; - if (endA || endB) - return endA == endB; - if (a[iA++].result != b[iB++].result) - return false; + stackID(stack) { + let id = (stackIDs || (stackIDs = new WeakMap)).get(stack); + if (!id) + stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++)); + return id + stack; } } -const baseAttrs = { - "aria-autocomplete": "list" -}; -function makeAttrs(id, selected) { - let result = { - "aria-autocomplete": "list", - "aria-haspopup": "listbox", - "aria-controls": id - }; - if (selected > -1) - result["aria-activedescendant"] = id + "-" + selected; - return result; -} -const none$1 = []; -function getUserEvent(tr, conf) { - if (tr.isUserEvent("input.complete")) { - let completion = tr.annotation(pickedCompletion); - if (completion && conf.activateOnCompletion(completion)) - return "input"; +function pushStackDedup(stack, newStacks) { + for (let i = 0; i < newStacks.length; i++) { + let other = newStacks[i]; + if (other.pos == stack.pos && other.sameState(stack)) { + if (newStacks[i].score < stack.score) + newStacks[i] = stack; + return; + } } - return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null; + newStacks.push(stack); } -class ActiveSource { - constructor(source, state, explicitPos = -1) { +class Dialect { + constructor(source, flags, disabled) { this.source = source; - this.state = state; - this.explicitPos = explicitPos; + this.flags = flags; + this.disabled = disabled; } - hasResult() { return false; } - update(tr, conf) { - let event = getUserEvent(tr, conf), value = this; - if (event) - value = value.handleUserEvent(tr, event, conf); - else if (tr.docChanged) - value = value.handleChange(tr); - else if (tr.selection && value.state != 0 /* State.Inactive */) - value = new ActiveSource(value.source, 0 /* State.Inactive */); - for (let effect of tr.effects) { - if (effect.is(startCompletionEffect)) - value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value ? cur(tr.state) : -1); - else if (effect.is(closeCompletionEffect)) - value = new ActiveSource(value.source, 0 /* State.Inactive */); - else if (effect.is(setActiveEffect)) - for (let active of effect.value) - if (active.source == value.source) - value = active; - } - return value; - } - handleUserEvent(tr, type, conf) { - return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(this.source, 1 /* State.Pending */); - } - handleChange(tr) { - return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes); - } - map(changes) { - return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos)); - } -} -class ActiveResult extends ActiveSource { - constructor(source, explicitPos, result, from, to) { - super(source, 2 /* State.Result */, explicitPos); - this.result = result; - this.from = from; - this.to = to; - } - hasResult() { return true; } - handleUserEvent(tr, type, conf) { - var _a; - let result = this.result; - if (result.map && !tr.changes.empty) - result = result.map(result, tr.changes); - let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1); - let pos = cur(tr.state); - if ((this.explicitPos < 0 ? pos <= from : pos < this.from) || - pos > to || !result || - type == "delete" && cur(tr.startState) == this.from) - return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* State.Pending */ : 0 /* State.Inactive */); - let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos); - if (checkValid(result.validFor, tr.state, from, to)) - return new ActiveResult(this.source, explicitPos, result, from, to); - if (result.update && - (result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0)))) - return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state)); - return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos); - } - handleChange(tr) { - return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes); - } - map(mapping) { - if (mapping.empty) - return this; - let result = this.result.map ? this.result.map(this.result, mapping) : this.result; - if (!result) - return new ActiveSource(this.source, 0 /* State.Inactive */); - return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1)); - } -} -function checkValid(validFor, state, from, to) { - if (!validFor) - return false; - let text = state.sliceDoc(from, to); - return typeof validFor == "function" ? validFor(text, from, to, state) : ensureAnchor(validFor, true).test(text); -} -const setActiveEffect = /*@__PURE__*/StateEffect.define({ - map(sources, mapping) { return sources.map(s => s.map(mapping)); } -}); -const setSelectedEffect = /*@__PURE__*/StateEffect.define(); -const completionState = /*@__PURE__*/StateField.define({ - create() { return CompletionState.start(); }, - update(value, tr) { return value.update(tr); }, - provide: f => [ - showTooltip.from(f, val => val.tooltip), - EditorView.contentAttributes.from(f, state => state.attrs) - ] -}); -function applyCompletion(view, option) { - const apply = option.completion.apply || option.completion.label; - let result = view.state.field(completionState).active.find(a => a.source == option.source); - if (!(result instanceof ActiveResult)) - return false; - if (typeof apply == "string") - view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) })); - else - apply(view, option.completion, result.from, result.to); - return true; + allows(term) { return !this.disabled || this.disabled[term] == 0; } } -const createTooltip = /*@__PURE__*/completionTooltip(completionState, applyCompletion); - +const id = x => x; /** -Returns a command that moves the completion selection forward or -backward by the given amount. +Context trackers are used to track stateful context (such as +indentation in the Python grammar, or parent elements in the XML +grammar) needed by external tokenizers. You declare them in a +grammar file as `@context exportName from "module"`. + +Context values should be immutable, and can be updated (replaced) +on shift or reduce actions. + +The export used in a `@context` declaration should be of this +type. */ -function moveCompletionSelection(forward, by = "option") { - return (view) => { - let cState = view.state.field(completionState, false); - if (!cState || !cState.open || cState.open.disabled || - Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) - return false; - let step = 1, tooltip; - if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip))) - step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / - tooltip.dom.querySelector("li").offsetHeight) - 1); - let { length } = cState.open.options; - let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length - 1; - if (selected < 0) - selected = by == "page" ? 0 : length - 1; - else if (selected >= length) - selected = by == "page" ? length - 1 : 0; - view.dispatch({ effects: setSelectedEffect.of(selected) }); - return true; - }; +class ContextTracker { + /** + Define a context tracker. + */ + constructor(spec) { + this.start = spec.start; + this.shift = spec.shift || id; + this.reduce = spec.reduce || id; + this.reuse = spec.reuse || id; + this.hash = spec.hash || (() => 0); + this.strict = spec.strict !== false; + } } /** -Accept the current completion. -*/ -const acceptCompletion = (view) => { - let cState = view.state.field(completionState, false); - if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || cState.open.disabled || - Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) - return false; - return applyCompletion(view, cState.open.options[cState.open.selected]); -}; -/** -Explicitly start autocompletion. -*/ -const startCompletion = (view) => { - let cState = view.state.field(completionState, false); - if (!cState) - return false; - view.dispatch({ effects: startCompletionEffect.of(true) }); - return true; -}; -/** -Close the currently active completion. +Holds the parse tables for a given grammar, as generated by +`lezer-generator`, and provides [methods](#common.Parser) to parse +content with. */ -const closeCompletion = (view) => { - let cState = view.state.field(completionState, false); - if (!cState || !cState.active.some(a => a.state != 0 /* State.Inactive */)) - return false; - view.dispatch({ effects: closeCompletionEffect.of(null) }); - return true; -}; -class RunningQuery { - constructor(active, context) { - this.active = active; - this.context = context; - this.time = Date.now(); - this.updates = []; - // Note that 'undefined' means 'not done yet', whereas 'null' means - // 'query returned null'. - this.done = undefined; - } -} -const MaxUpdateCount = 50, MinAbortTime = 1000; -const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class { - constructor(view) { - this.view = view; - this.debounceUpdate = -1; - this.running = []; - this.debounceAccept = -1; - this.pendingStart = false; - this.composing = 0 /* CompositionState.None */; - for (let active of view.state.field(completionState).active) - if (active.state == 1 /* State.Pending */) - this.startQuery(active); - } - update(update) { - let cState = update.state.field(completionState); - let conf = update.state.facet(completionConfig); - if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState) - return; - let doesReset = update.transactions.some(tr => { - return (tr.selection || tr.docChanged) && !getUserEvent(tr, conf); - }); - for (let i = 0; i < this.running.length; i++) { - let query = this.running[i]; - if (doesReset || - query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) { - for (let handler of query.context.abortListeners) { - try { - handler(); +class LRParser extends Parser { + /** + @internal + */ + constructor(spec) { + super(); + /** + @internal + */ + this.wrappers = []; + if (spec.version != 14 /* File.Version */) + throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14 /* File.Version */})`); + let nodeNames = spec.nodeNames.split(" "); + this.minRepeatTerm = nodeNames.length; + for (let i = 0; i < spec.repeatNodeCount; i++) + nodeNames.push(""); + let topTerms = Object.keys(spec.topRules).map(r => spec.topRules[r][1]); + let nodeProps = []; + for (let i = 0; i < nodeNames.length; i++) + nodeProps.push([]); + function setProp(nodeID, prop, value) { + nodeProps[nodeID].push([prop, prop.deserialize(String(value))]); + } + if (spec.nodeProps) + for (let propSpec of spec.nodeProps) { + let prop = propSpec[0]; + if (typeof prop == "string") + prop = NodeProp[prop]; + for (let i = 1; i < propSpec.length;) { + let next = propSpec[i++]; + if (next >= 0) { + setProp(next, prop, propSpec[i++]); } - catch (e) { - logException(this.view.state, e); + else { + let value = propSpec[i + -next]; + for (let j = -next; j > 0; j--) + setProp(propSpec[i++], prop, value); + i++; } } - query.context.abortListeners = null; - this.running.splice(i--, 1); - } - else { - query.updates.push(...update.transactions); - } - } - if (this.debounceUpdate > -1) - clearTimeout(this.debounceUpdate); - if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect)))) - this.pendingStart = true; - let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay; - this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source)) - ? setTimeout(() => this.startUpdate(), delay) : -1; - if (this.composing != 0 /* CompositionState.None */) - for (let tr of update.transactions) { - if (getUserEvent(tr, conf) == "input") - this.composing = 2 /* CompositionState.Changed */; - else if (this.composing == 2 /* CompositionState.Changed */ && tr.selection) - this.composing = 3 /* CompositionState.ChangedAndMoved */; } + this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({ + name: i >= this.minRepeatTerm ? undefined : name, + id: i, + props: nodeProps[i], + top: topTerms.indexOf(i) > -1, + error: i == 0, + skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1 + }))); + if (spec.propSources) + this.nodeSet = this.nodeSet.extend(...spec.propSources); + this.strict = false; + this.bufferLength = DefaultBufferLength; + let tokenArray = decodeArray(spec.tokenData); + this.context = spec.context; + this.specializerSpecs = spec.specialized || []; + this.specialized = new Uint16Array(this.specializerSpecs.length); + for (let i = 0; i < this.specializerSpecs.length; i++) + this.specialized[i] = this.specializerSpecs[i].term; + this.specializers = this.specializerSpecs.map(getSpecializer); + this.states = decodeArray(spec.states, Uint32Array); + this.data = decodeArray(spec.stateData); + this.goto = decodeArray(spec.goto); + this.maxTerm = spec.maxTerm; + this.tokenizers = spec.tokenizers.map(value => typeof value == "number" ? new TokenGroup(tokenArray, value) : value); + this.topRules = spec.topRules; + this.dialects = spec.dialects || {}; + this.dynamicPrecedences = spec.dynamicPrecedences || null; + this.tokenPrecTable = spec.tokenPrec; + this.termNames = spec.termNames || null; + this.maxNode = this.nodeSet.types.length - 1; + this.dialect = this.parseDialect(); + this.top = this.topRules[Object.keys(this.topRules)[0]]; } - startUpdate() { - this.debounceUpdate = -1; - this.pendingStart = false; - let { state } = this.view, cState = state.field(completionState); - for (let active of cState.active) { - if (active.state == 1 /* State.Pending */ && !this.running.some(r => r.active.source == active.source)) - this.startQuery(active); + createParse(input, fragments, ranges) { + let parse = new Parse(this, input, fragments, ranges); + for (let w of this.wrappers) + parse = w(parse, input, fragments, ranges); + return parse; + } + /** + Get a goto table entry @internal + */ + getGoto(state, term, loose = false) { + let table = this.goto; + if (term >= table[0]) + return -1; + for (let pos = table[term + 1];;) { + let groupTag = table[pos++], last = groupTag & 1; + let target = table[pos++]; + if (last && loose) + return target; + for (let end = pos + (groupTag >> 1); pos < end; pos++) + if (table[pos] == state) + return target; + if (last) + return -1; } } - startQuery(active) { - let { state } = this.view, pos = cur(state); - let context = new CompletionContext(state, pos, active.explicitPos == pos); - let pending = new RunningQuery(active, context); - this.running.push(pending); - Promise.resolve(active.source(context)).then(result => { - if (!pending.context.aborted) { - pending.done = result || null; - this.scheduleAccept(); + /** + Check if this state has an action for a given terminal @internal + */ + hasAction(state, terminal) { + let data = this.data; + for (let set = 0; set < 2; set++) { + for (let i = this.stateSlot(state, set ? 2 /* ParseState.Skip */ : 1 /* ParseState.Actions */), next;; i += 3) { + if ((next = data[i]) == 65535 /* Seq.End */) { + if (data[i + 1] == 1 /* Seq.Next */) + next = data[i = pair(data, i + 2)]; + else if (data[i + 1] == 2 /* Seq.Other */) + return pair(data, i + 2); + else + break; + } + if (next == terminal || next == 0 /* Term.Err */) + return pair(data, i + 1); } - }, err => { - this.view.dispatch({ effects: closeCompletionEffect.of(null) }); - logException(this.view.state, err); - }); + } + return 0; } - scheduleAccept() { - if (this.running.every(q => q.done !== undefined)) - this.accept(); - else if (this.debounceAccept < 0) - this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(completionConfig).updateSyncTime); + /** + @internal + */ + stateSlot(state, slot) { + return this.states[(state * 6 /* ParseState.Size */) + slot]; } - // For each finished query in this.running, try to create a result - // or, if appropriate, restart the query. - accept() { - var _a; - if (this.debounceAccept > -1) - clearTimeout(this.debounceAccept); - this.debounceAccept = -1; - let updated = []; - let conf = this.view.state.facet(completionConfig); - for (let i = 0; i < this.running.length; i++) { - let query = this.running[i]; - if (query.done === undefined) - continue; - this.running.splice(i--, 1); - if (query.done) { - let active = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : cur(query.updates.length ? query.updates[0].startState : this.view.state)); - // Replay the transactions that happened since the start of - // the request and see if that preserves the result - for (let tr of query.updates) - active = active.update(tr, conf); - if (active.hasResult()) { - updated.push(active); - continue; - } - } - let current = this.view.state.field(completionState).active.find(a => a.source == query.active.source); - if (current && current.state == 1 /* State.Pending */) { - if (query.done == null) { - // Explicitly failed. Should clear the pending status if it - // hasn't been re-set in the meantime. - let active = new ActiveSource(query.active.source, 0 /* State.Inactive */); - for (let tr of query.updates) - active = active.update(tr, conf); - if (active.state != 1 /* State.Pending */) - updated.push(active); - } - else { - // Cleared by subsequent transactions. Restart. - this.startQuery(current); - } + /** + @internal + */ + stateFlag(state, flag) { + return (this.stateSlot(state, 0 /* ParseState.Flags */) & flag) > 0; + } + /** + @internal + */ + validAction(state, action) { + return !!this.allActions(state, a => a == action ? true : null); + } + /** + @internal + */ + allActions(state, action) { + let deflt = this.stateSlot(state, 4 /* ParseState.DefaultReduce */); + let result = deflt ? action(deflt) : undefined; + for (let i = this.stateSlot(state, 1 /* ParseState.Actions */); result == null; i += 3) { + if (this.data[i] == 65535 /* Seq.End */) { + if (this.data[i + 1] == 1 /* Seq.Next */) + i = pair(this.data, i + 2); + else + break; } + result = action(pair(this.data, i + 1)); } - if (updated.length) - this.view.dispatch({ effects: setActiveEffect.of(updated) }); + return result; } -}, { - eventHandlers: { - blur(event) { - let state = this.view.state.field(completionState, false); - if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) { - let dialog = state.open && getTooltip(this.view, state.open.tooltip); - if (!dialog || !dialog.dom.contains(event.relatedTarget)) - setTimeout(() => this.view.dispatch({ effects: closeCompletionEffect.of(null) }), 10); + /** + Get the states that can follow this one through shift actions or + goto jumps. @internal + */ + nextStates(state) { + let result = []; + for (let i = this.stateSlot(state, 1 /* ParseState.Actions */);; i += 3) { + if (this.data[i] == 65535 /* Seq.End */) { + if (this.data[i + 1] == 1 /* Seq.Next */) + i = pair(this.data, i + 2); + else + break; } - }, - compositionstart() { - this.composing = 1 /* CompositionState.Started */; - }, - compositionend() { - if (this.composing == 3 /* CompositionState.ChangedAndMoved */) { - // Safari fires compositionend events synchronously, possibly - // from inside an update, so dispatch asynchronously to avoid reentrancy - setTimeout(() => this.view.dispatch({ effects: startCompletionEffect.of(false) }), 20); + if ((this.data[i + 2] & (65536 /* Action.ReduceFlag */ >> 16)) == 0) { + let value = this.data[i + 1]; + if (!result.some((v, i) => (i & 1) && v == value)) + result.push(this.data[i], value); } - this.composing = 0 /* CompositionState.None */; } + return result; } -}); -const windows = typeof navigator == "object" && /*@__PURE__*//Win/.test(navigator.platform); -const commitCharacters = /*@__PURE__*/Prec.highest(/*@__PURE__*/EditorView.domEventHandlers({ - keydown(event, view) { - let field = view.state.field(completionState, false); - if (!field || !field.open || field.open.disabled || field.open.selected < 0 || - event.key.length > 1 || event.ctrlKey && !(windows && event.altKey) || event.metaKey) - return false; - let option = field.open.options[field.open.selected]; - let result = field.active.find(a => a.source == option.source); - let commitChars = option.completion.commitCharacters || result.result.commitCharacters; - if (commitChars && commitChars.indexOf(event.key) > -1) - applyCompletion(view, option); - return false; - } -})); - -const baseTheme$3 = /*@__PURE__*/EditorView.baseTheme({ - ".cm-tooltip.cm-tooltip-autocomplete": { - "& > ul": { - fontFamily: "monospace", - whiteSpace: "nowrap", - overflow: "hidden auto", - maxWidth_fallback: "700px", - maxWidth: "min(700px, 95vw)", - minWidth: "250px", - maxHeight: "10em", - height: "100%", - listStyle: "none", - margin: 0, - padding: 0, - "& > li, & > completion-section": { - padding: "1px 3px", - lineHeight: 1.2 - }, - "& > li": { - overflowX: "hidden", - textOverflow: "ellipsis", - cursor: "pointer" - }, - "& > completion-section": { - display: "list-item", - borderBottom: "1px solid silver", - paddingLeft: "0.5em", - opacity: 0.7 - } + /** + Configure the parser. Returns a new parser instance that has the + given settings modified. Settings not provided in `config` are + kept from the original parser. + */ + configure(config) { + // Hideous reflection-based kludge to make it easy to create a + // slightly modified copy of a parser. + let copy = Object.assign(Object.create(LRParser.prototype), this); + if (config.props) + copy.nodeSet = this.nodeSet.extend(...config.props); + if (config.top) { + let info = this.topRules[config.top]; + if (!info) + throw new RangeError(`Invalid top rule name ${config.top}`); + copy.top = info; } - }, - "&light .cm-tooltip-autocomplete ul li[aria-selected]": { - background: "#17c", - color: "white", - }, - "&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]": { - background: "#777", - }, - "&dark .cm-tooltip-autocomplete ul li[aria-selected]": { - background: "#347", - color: "white", - }, - "&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]": { - background: "#444", - }, - ".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": { - content: '"···"', - opacity: 0.5, - display: "block", - textAlign: "center" - }, - ".cm-tooltip.cm-completionInfo": { - position: "absolute", - padding: "3px 9px", - width: "max-content", - maxWidth: `${400 /* Info.Width */}px`, - boxSizing: "border-box" - }, - ".cm-completionInfo.cm-completionInfo-left": { right: "100%" }, - ".cm-completionInfo.cm-completionInfo-right": { left: "100%" }, - ".cm-completionInfo.cm-completionInfo-left-narrow": { right: `${30 /* Info.Margin */}px` }, - ".cm-completionInfo.cm-completionInfo-right-narrow": { left: `${30 /* Info.Margin */}px` }, - "&light .cm-snippetField": { backgroundColor: "#00000022" }, - "&dark .cm-snippetField": { backgroundColor: "#ffffff22" }, - ".cm-snippetFieldPosition": { - verticalAlign: "text-top", - width: 0, - height: "1.15em", - display: "inline-block", - margin: "0 -0.7px -.7em", - borderLeft: "1.4px dotted #888" - }, - ".cm-completionMatchedText": { - textDecoration: "underline" - }, - ".cm-completionDetail": { - marginLeft: "0.5em", - fontStyle: "italic" - }, - ".cm-completionIcon": { - fontSize: "90%", - width: ".8em", - display: "inline-block", - textAlign: "center", - paddingRight: ".6em", - opacity: "0.6", - boxSizing: "content-box" - }, - ".cm-completionIcon-function, .cm-completionIcon-method": { - "&:after": { content: "'ƒ'" } - }, - ".cm-completionIcon-class": { - "&:after": { content: "'○'" } - }, - ".cm-completionIcon-interface": { - "&:after": { content: "'◌'" } - }, - ".cm-completionIcon-variable": { - "&:after": { content: "'𝑥'" } - }, - ".cm-completionIcon-constant": { - "&:after": { content: "'𝐶'" } - }, - ".cm-completionIcon-type": { - "&:after": { content: "'𝑡'" } - }, - ".cm-completionIcon-enum": { - "&:after": { content: "'∪'" } - }, - ".cm-completionIcon-property": { - "&:after": { content: "'□'" } - }, - ".cm-completionIcon-keyword": { - "&:after": { content: "'🔑\uFE0E'" } // Disable emoji rendering - }, - ".cm-completionIcon-namespace": { - "&:after": { content: "'▢'" } - }, - ".cm-completionIcon-text": { - "&:after": { content: "'abc'", fontSize: "50%", verticalAlign: "middle" } + if (config.tokenizers) + copy.tokenizers = this.tokenizers.map(t => { + let found = config.tokenizers.find(r => r.from == t); + return found ? found.to : t; + }); + if (config.specializers) { + copy.specializers = this.specializers.slice(); + copy.specializerSpecs = this.specializerSpecs.map((s, i) => { + let found = config.specializers.find(r => r.from == s.external); + if (!found) + return s; + let spec = Object.assign(Object.assign({}, s), { external: found.to }); + copy.specializers[i] = getSpecializer(spec); + return spec; + }); + } + if (config.contextTracker) + copy.context = config.contextTracker; + if (config.dialect) + copy.dialect = this.parseDialect(config.dialect); + if (config.strict != null) + copy.strict = config.strict; + if (config.wrap) + copy.wrappers = copy.wrappers.concat(config.wrap); + if (config.bufferLength != null) + copy.bufferLength = config.bufferLength; + return copy; } -}); - -class FieldPos { - constructor(field, line, from, to) { - this.field = field; - this.line = line; - this.from = from; - this.to = to; + /** + Tells you whether any [parse wrappers](#lr.ParserConfig.wrap) + are registered for this parser. + */ + hasWrappers() { + return this.wrappers.length > 0; } -} -class FieldRange { - constructor(field, from, to) { - this.field = field; - this.from = from; - this.to = to; + /** + Returns the name associated with a given term. This will only + work for all terms when the parser was generated with the + `--names` option. By default, only the names of tagged terms are + stored. + */ + getName(term) { + return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term); } - map(changes) { - let from = changes.mapPos(this.from, -1, MapMode.TrackDel); - let to = changes.mapPos(this.to, 1, MapMode.TrackDel); - return from == null || to == null ? null : new FieldRange(this.field, from, to); + /** + The eof term id is always allocated directly after the node + types. @internal + */ + get eofTerm() { return this.maxNode + 1; } + /** + The type of top node produced by the parser. + */ + get topNode() { return this.nodeSet.types[this.top[1]]; } + /** + @internal + */ + dynamicPrecedence(term) { + let prec = this.dynamicPrecedences; + return prec == null ? 0 : prec[term] || 0; + } + /** + @internal + */ + parseDialect(dialect) { + let values = Object.keys(this.dialects), flags = values.map(() => false); + if (dialect) + for (let part of dialect.split(" ")) { + let id = values.indexOf(part); + if (id >= 0) + flags[id] = true; + } + let disabled = null; + for (let i = 0; i < values.length; i++) + if (!flags[i]) { + for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535 /* Seq.End */;) + (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1; + } + return new Dialect(dialect, flags, disabled); + } + /** + Used by the output of the parser generator. Not available to + user code. @hide + */ + static deserialize(spec) { + return new LRParser(spec); } } -class Snippet { - constructor(lines, fieldPositions) { - this.lines = lines; - this.fieldPositions = fieldPositions; +function pair(data, off) { return data[off] | (data[off + 1] << 16); } +function findFinished(stacks) { + let best = null; + for (let stack of stacks) { + let stopped = stack.p.stoppedAt; + if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && + stack.p.parser.stateFlag(stack.state, 2 /* StateFlag.Accepting */) && + (!best || best.score < stack.score)) + best = stack; } - instantiate(state, pos) { - let text = [], lineStart = [pos]; - let lineObj = state.doc.lineAt(pos), baseIndent = /^\s*/.exec(lineObj.text)[0]; - for (let line of this.lines) { - if (text.length) { - let indent = baseIndent, tabs = /^\t*/.exec(line)[0].length; - for (let i = 0; i < tabs; i++) - indent += state.facet(indentUnit); - lineStart.push(pos + indent.length - tabs); - line = indent + line.slice(tabs); - } - text.push(line); - pos += line.length + 1; - } - let ranges = this.fieldPositions.map(pos => new FieldRange(pos.field, lineStart[pos.line] + pos.from, lineStart[pos.line] + pos.to)); - return { text, ranges }; + return best; +} +function getSpecializer(spec) { + if (spec.external) { + let mask = spec.extend ? 1 /* Specialize.Extend */ : 0 /* Specialize.Specialize */; + return (value, stack) => (spec.external(value, stack) << 1) | mask; } - static parse(template) { - let fields = []; - let lines = [], positions = [], m; - for (let line of template.split(/\r\n?|\n/)) { - while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(line)) { - let seq = m[1] ? +m[1] : null, rawName = m[2] || m[3] || "", found = -1; - let name = rawName.replace(/\\[{}]/g, m => m[1]); - for (let i = 0; i < fields.length; i++) { - if (seq != null ? fields[i].seq == seq : name ? fields[i].name == name : false) - found = i; - } - if (found < 0) { - let i = 0; - while (i < fields.length && (seq == null || (fields[i].seq != null && fields[i].seq < seq))) - i++; - fields.splice(i, 0, { seq, name }); - found = i; - for (let pos of positions) - if (pos.field >= found) - pos.field++; - } - positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length)); - line = line.slice(0, m.index) + rawName + line.slice(m.index + m[0].length); - } - line = line.replace(/\\([{}])/g, (_, brace, index) => { - for (let pos of positions) - if (pos.line == lines.length && pos.from > index) { - pos.from--; - pos.to--; - } - return brace; - }); - lines.push(line); - } - return new Snippet(lines, positions); - } -} -let fieldMarker = /*@__PURE__*/Decoration.widget({ widget: /*@__PURE__*/new class extends WidgetType { - toDOM() { - let span = document.createElement("span"); - span.className = "cm-snippetFieldPosition"; - return span; - } - ignoreEvent() { return false; } - } }); -let fieldRange = /*@__PURE__*/Decoration.mark({ class: "cm-snippetField" }); -class ActiveSnippet { - constructor(ranges, active) { - this.ranges = ranges; - this.active = active; - this.deco = Decoration.set(ranges.map(r => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to))); - } - map(changes) { - let ranges = []; - for (let r of this.ranges) { - let mapped = r.map(changes); - if (!mapped) - return null; - ranges.push(mapped); - } - return new ActiveSnippet(ranges, this.active); - } - selectionInsideField(sel) { - return sel.ranges.every(range => this.ranges.some(r => r.field == this.active && r.from <= range.from && r.to >= range.to)); - } -} -const setActive = /*@__PURE__*/StateEffect.define({ - map(value, changes) { return value && value.map(changes); } -}); -const moveToField = /*@__PURE__*/StateEffect.define(); -const snippetState = /*@__PURE__*/StateField.define({ - create() { return null; }, - update(value, tr) { - for (let effect of tr.effects) { - if (effect.is(setActive)) - return effect.value; - if (effect.is(moveToField) && value) - return new ActiveSnippet(value.ranges, effect.value); - } - if (value && tr.docChanged) - value = value.map(tr.changes); - if (value && tr.selection && !value.selectionInsideField(tr.selection)) - value = null; - return value; - }, - provide: f => EditorView.decorations.from(f, val => val ? val.deco : Decoration.none) -}); -function fieldSelection(ranges, field) { - return EditorSelection.create(ranges.filter(r => r.field == field).map(r => EditorSelection.range(r.from, r.to))); + return spec.get; } -/** -Convert a snippet template to a function that can -[apply](https://codemirror.net/6/docs/ref/#autocomplete.Completion.apply) it. Snippets are written -using syntax like this: - - "for (let ${index} = 0; ${index} < ${end}; ${index}++) {\n\t${}\n}" -Each `${}` placeholder (you may also use `#{}`) indicates a field -that the user can fill in. Its name, if any, will be the default -content for the field. +// This file was generated by lezer-generator. You probably shouldn't edit it. +const noSemi = 312, + incdec = 1, + incdecPrefix = 2, + questionDot = 3, + JSXStartTag = 4, + insertSemi = 313, + spaces = 315, + newline = 316, + LineComment = 5, + BlockComment = 6, + Dialect_jsx = 0; -When the snippet is activated by calling the returned function, -the code is inserted at the given position. Newlines in the -template are indented by the indentation of the start line, plus -one [indent unit](https://codemirror.net/6/docs/ref/#language.indentUnit) per tab character after -the newline. +/* Hand-written tokenizers for JavaScript tokens that can't be + expressed by lezer's built-in tokenizer. */ -On activation, (all instances of) the first field are selected. -The user can move between fields with Tab and Shift-Tab as long as -the fields are active. Moving to the last field or moving the -cursor out of the current field deactivates the fields. +const space = [9, 10, 11, 12, 13, 32, 133, 160, 5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, + 8201, 8202, 8232, 8233, 8239, 8287, 12288]; -The order of fields defaults to textual order, but you can add -numbers to placeholders (`${1}` or `${1:defaultText}`) to provide -a custom order. +const braceR = 125, semicolon = 59, slash = 47, star = 42, plus = 43, minus = 45, lt = 60, comma = 44, + question = 63, dot = 46; -To include a literal `{` or `}` in your template, put a backslash -in front of it. This will be removed and the brace will not be -interpreted as indicating a placeholder. -*/ -function snippet(template) { - let snippet = Snippet.parse(template); - return (editor, completion, from, to) => { - let { text, ranges } = snippet.instantiate(editor.state, from); - let spec = { - changes: { from, to, insert: Text.of(text) }, - scrollIntoView: true, - annotations: completion ? [pickedCompletion.of(completion), Transaction.userEvent.of("input.complete")] : undefined - }; - if (ranges.length) - spec.selection = fieldSelection(ranges, 0); - if (ranges.some(r => r.field > 0)) { - let active = new ActiveSnippet(ranges, 0); - let effects = spec.effects = [setActive.of(active)]; - if (editor.state.field(snippetState, false) === undefined) - effects.push(StateEffect.appendConfig.of([snippetState, addSnippetKeymap, snippetPointerHandler, baseTheme$3])); - } - editor.dispatch(editor.state.update(spec)); - }; -} -function moveField(dir) { - return ({ state, dispatch }) => { - let active = state.field(snippetState, false); - if (!active || dir < 0 && active.active == 0) - return false; - let next = active.active + dir, last = dir > 0 && !active.ranges.some(r => r.field == next + dir); - dispatch(state.update({ - selection: fieldSelection(active.ranges, next), - effects: setActive.of(last ? null : new ActiveSnippet(active.ranges, next)), - scrollIntoView: true - })); - return true; - }; -} -/** -A command that clears the active snippet, if any. -*/ -const clearSnippet = ({ state, dispatch }) => { - let active = state.field(snippetState, false); - if (!active) - return false; - dispatch(state.update({ effects: setActive.of(null) })); - return true; -}; -/** -Move to the next snippet field, if available. -*/ -const nextSnippetField = /*@__PURE__*/moveField(1); -/** -Move to the previous snippet field, if available. -*/ -const prevSnippetField = /*@__PURE__*/moveField(-1); -const defaultSnippetKeymap = [ - { key: "Tab", run: nextSnippetField, shift: prevSnippetField }, - { key: "Escape", run: clearSnippet } -]; -/** -A facet that can be used to configure the key bindings used by -snippets. The default binds Tab to -[`nextSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.nextSnippetField), Shift-Tab to -[`prevSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.prevSnippetField), and Escape -to [`clearSnippet`](https://codemirror.net/6/docs/ref/#autocomplete.clearSnippet). -*/ -const snippetKeymap = /*@__PURE__*/Facet.define({ - combine(maps) { return maps.length ? maps[0] : defaultSnippetKeymap; } -}); -const addSnippetKeymap = /*@__PURE__*/Prec.highest(/*@__PURE__*/keymap.compute([snippetKeymap], state => state.facet(snippetKeymap))); -/** -Create a completion from a snippet. Returns an object with the -properties from `completion`, plus an `apply` function that -applies the snippet. -*/ -function snippetCompletion(template, completion) { - return Object.assign(Object.assign({}, completion), { apply: snippet(template) }); -} -const snippetPointerHandler = /*@__PURE__*/EditorView.domEventHandlers({ - mousedown(event, view) { - let active = view.state.field(snippetState, false), pos; - if (!active || (pos = view.posAtCoords({ x: event.clientX, y: event.clientY })) == null) - return false; - let match = active.ranges.find(r => r.from <= pos && r.to >= pos); - if (!match || match.field == active.active) - return false; - view.dispatch({ - selection: fieldSelection(active.ranges, match.field), - effects: setActive.of(active.ranges.some(r => r.field > match.field) - ? new ActiveSnippet(active.ranges, match.field) : null), - scrollIntoView: true - }); - return true; - } +const trackNewline = new ContextTracker({ + start: false, + shift(context, term) { + return term == LineComment || term == BlockComment || term == spaces ? context : term == newline + }, + strict: false }); -const defaults = { - brackets: ["(", "[", "{", "'", '"'], - before: ")]}:;>", - stringPrefixes: [] -}; -const closeBracketEffect = /*@__PURE__*/StateEffect.define({ - map(value, mapping) { - let mapped = mapping.mapPos(value, -1, MapMode.TrackAfter); - return mapped == null ? undefined : mapped; +const insertSemicolon = new ExternalTokenizer((input, stack) => { + let {next} = input; + if (next == braceR || next == -1 || stack.context) + input.acceptToken(insertSemi); +}, {contextual: true, fallback: true}); + +const noSemicolon = new ExternalTokenizer((input, stack) => { + let {next} = input, after; + if (space.indexOf(next) > -1) return + if (next == slash && ((after = input.peek(1)) == slash || after == star)) return + if (next != braceR && next != semicolon && next != -1 && !stack.context) + input.acceptToken(noSemi); +}, {contextual: true}); + +const operatorToken = new ExternalTokenizer((input, stack) => { + let {next} = input; + if (next == plus || next == minus) { + input.advance(); + if (next == input.next) { + input.advance(); + let mayPostfix = !stack.context && stack.canShift(incdec); + input.acceptToken(mayPostfix ? incdec : incdecPrefix); } -}); -const closedBracket = /*@__PURE__*/new class extends RangeValue { -}; -closedBracket.startSide = 1; -closedBracket.endSide = -1; -const bracketState = /*@__PURE__*/StateField.define({ - create() { return RangeSet.empty; }, - update(value, tr) { - value = value.map(tr.changes); - if (tr.selection) { - let line = tr.state.doc.lineAt(tr.selection.main.head); - value = value.update({ filter: from => from >= line.from && from <= line.to }); - } - for (let effect of tr.effects) - if (effect.is(closeBracketEffect)) - value = value.update({ add: [closedBracket.range(effect.value, effect.value + 1)] }); - return value; + } else if (next == question && input.peek(1) == dot) { + input.advance(); input.advance(); + if (input.next < 48 || input.next > 57) // No digit after + input.acceptToken(questionDot); + } +}, {contextual: true}); + +function identifierChar(ch, start) { + return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch == 95 || ch >= 192 || + !start && ch >= 48 && ch <= 57 +} + +const jsx = new ExternalTokenizer((input, stack) => { + if (input.next != lt || !stack.dialectEnabled(Dialect_jsx)) return + input.advance(); + if (input.next == slash) return + // Scan for an identifier followed by a comma or 'extends', don't + // treat this as a start tag if present. + let back = 0; + while (space.indexOf(input.next) > -1) { input.advance(); back++; } + if (identifierChar(input.next, true)) { + input.advance(); + back++; + while (identifierChar(input.next, false)) { input.advance(); back++; } + while (space.indexOf(input.next) > -1) { input.advance(); back++; } + if (input.next == comma) return + for (let i = 0;; i++) { + if (i == 7) { + if (!identifierChar(input.next, true)) return + break + } + if (input.next != "extends".charCodeAt(i)) break + input.advance(); + back++; } + } + input.acceptToken(JSXStartTag, -back); +}); + +const jsHighlight = styleTags({ + "get set async static": tags.modifier, + "for while do if else switch try catch finally return throw break continue default case": tags.controlKeyword, + "in of await yield void typeof delete instanceof": tags.operatorKeyword, + "let var const using function class extends": tags.definitionKeyword, + "import export from": tags.moduleKeyword, + "with debugger as new": tags.keyword, + TemplateString: tags.special(tags.string), + super: tags.atom, + BooleanLiteral: tags.bool, + this: tags.self, + null: tags.null, + Star: tags.modifier, + VariableName: tags.variableName, + "CallExpression/VariableName TaggedTemplateExpression/VariableName": tags.function(tags.variableName), + VariableDefinition: tags.definition(tags.variableName), + Label: tags.labelName, + PropertyName: tags.propertyName, + PrivatePropertyName: tags.special(tags.propertyName), + "CallExpression/MemberExpression/PropertyName": tags.function(tags.propertyName), + "FunctionDeclaration/VariableDefinition": tags.function(tags.definition(tags.variableName)), + "ClassDeclaration/VariableDefinition": tags.definition(tags.className), + PropertyDefinition: tags.definition(tags.propertyName), + PrivatePropertyDefinition: tags.definition(tags.special(tags.propertyName)), + UpdateOp: tags.updateOperator, + "LineComment Hashbang": tags.lineComment, + BlockComment: tags.blockComment, + Number: tags.number, + String: tags.string, + Escape: tags.escape, + ArithOp: tags.arithmeticOperator, + LogicOp: tags.logicOperator, + BitOp: tags.bitwiseOperator, + CompareOp: tags.compareOperator, + RegExp: tags.regexp, + Equals: tags.definitionOperator, + Arrow: tags.function(tags.punctuation), + ": Spread": tags.punctuation, + "( )": tags.paren, + "[ ]": tags.squareBracket, + "{ }": tags.brace, + "InterpolationStart InterpolationEnd": tags.special(tags.brace), + ".": tags.derefOperator, + ", ;": tags.separator, + "@": tags.meta, + + TypeName: tags.typeName, + TypeDefinition: tags.definition(tags.typeName), + "type enum interface implements namespace module declare": tags.definitionKeyword, + "abstract global Privacy readonly override": tags.modifier, + "is keyof unique infer": tags.operatorKeyword, + + JSXAttributeValue: tags.attributeValue, + JSXText: tags.content, + "JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag": tags.angleBracket, + "JSXIdentifier JSXNameSpacedName": tags.tagName, + "JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName": tags.attributeName, + "JSXBuiltin/JSXIdentifier": tags.standard(tags.tagName) +}); + +// This file was generated by lezer-generator. You probably shouldn't edit it. +const spec_identifier = {__proto__:null,export:20, as:25, from:33, default:36, async:41, function:42, extends:54, this:58, true:66, false:66, null:78, void:82, typeof:86, super:102, new:136, delete:148, yield:157, await:161, class:166, public:229, private:229, protected:229, readonly:231, instanceof:250, satisfies:253, in:254, const:256, import:290, keyof:345, unique:349, infer:355, is:391, abstract:411, implements:413, type:415, let:418, var:420, using:423, interface:429, enum:433, namespace:439, module:441, declare:445, global:449, for:468, of:477, while:480, with:484, do:488, if:492, else:494, switch:498, case:504, try:510, catch:514, finally:518, return:522, throw:526, break:530, continue:534, debugger:538}; +const spec_word = {__proto__:null,async:123, get:125, set:127, declare:189, public:191, private:191, protected:191, static:193, abstract:195, override:197, readonly:203, accessor:205, new:395}; +const spec_LessThan = {__proto__:null,"<":187}; +const parser = LRParser.deserialize({ + version: 14, + states: "$@QO%TQ^OOO%[Q^OOO'_Q`OOP(lOWOOO*zQ?NdO'#CiO+RO!bO'#CjO+aO#tO'#CjO+oO!0LbO'#D^O.QQ^O'#DdO.bQ^O'#DoO%[Q^O'#DwO0fQ^O'#EPOOQ?Mr'#EX'#EXO1PQWO'#EUOOQO'#Em'#EmOOQO'#Ih'#IhO1XQWO'#GpO1dQWO'#ElO1iQWO'#ElO3hQ?NdO'#JmO6[Q?NdO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P$.Y$.^$/U$0d$0i$1PPP$1U$1[$1`P$1c$1g$1k$2a$2x$3a$3e$3h$3k$3q$3t$3x$3|R!|RoqOXst!Z#d%k&o&q&r&t,k,p1|2PY!vQ']-]1a5eQ%rvQ%zyQ&R|Q&g!VS'T!e-TQ'c!iS'i!r!yU*e$|*V*jQ+i%{Q+v&TQ,[&aQ-Z'[Q-e'dQ-m'jQ0R*lQ1k,]R;v;T%QdOPWXYZstuvw!Z!`!g!o#S#W#Z#d#o#u#x#{$O$P$Q$R$S$T$U$V$W$X$_$a$e%k%r&P&h&k&o&q&r&t&x'Q'_'o(P(R(X(`(t(v(z)y+R+V,h,k,p-a-i-w-}.l.s/f0a0g0v1d1t1u1w1y1|2P2R2r2x3^5b5m5}6O6R6f8R8X8h8rS#q];Q!r)Z$Z$n'U)o,|-P.}2b3u5`6]9h9y;P;S;T;W;X;Y;Z;[;];^;_;`;a;b;c;d;f;i;v;x;y;{ < TypeParamList TypeDefinition extends ThisType this LiteralType ArithOp Number BooleanLiteral TemplateType InterpolationEnd Interpolation InterpolationStart NullType null VoidType void TypeofType typeof MemberExpression . PropertyName [ TemplateString Escape Interpolation super RegExp ] ArrayExpression Spread , } { ObjectExpression Property async get set PropertyDefinition Block : NewTarget new NewExpression ) ( ArgList UnaryExpression delete LogicOp BitOp YieldExpression yield AwaitExpression await ParenthesizedExpression ClassExpression class ClassBody MethodDeclaration Decorator @ MemberExpression PrivatePropertyName CallExpression TypeArgList CompareOp < declare Privacy static abstract override PrivatePropertyDefinition PropertyDeclaration readonly accessor Optional TypeAnnotation Equals StaticBlock FunctionExpression ArrowFunction ParamList ParamList ArrayPattern ObjectPattern PatternProperty Privacy readonly Arrow MemberExpression BinaryExpression ArithOp ArithOp ArithOp ArithOp BitOp CompareOp instanceof satisfies in const CompareOp BitOp BitOp BitOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression UpdateOp PostfixExpression CallExpression InstantiationExpression TaggedTemplateExpression DynamicImport import ImportMeta JSXElement JSXSelfCloseEndTag JSXSelfClosingTag JSXIdentifier JSXBuiltin JSXIdentifier JSXNamespacedName JSXMemberExpression JSXSpreadAttribute JSXAttribute JSXAttributeValue JSXEscape JSXEndTag JSXOpenTag JSXFragmentTag JSXText JSXEscape JSXStartCloseTag JSXCloseTag PrefixCast ArrowFunction TypeParamList SequenceExpression InstantiationExpression KeyofType keyof UniqueType unique ImportType InferredType infer TypeName ParenthesizedType FunctionSignature ParamList NewSignature IndexedType TupleType Label ArrayType ReadonlyType ObjectType MethodType PropertyType IndexSignature PropertyDefinition CallSignature TypePredicate is NewSignature new UnionType LogicOp IntersectionType LogicOp ConditionalType ParameterizedType ClassDeclaration abstract implements type VariableDeclaration let var using TypeAliasDeclaration InterfaceDeclaration interface EnumDeclaration enum EnumBody NamespaceDeclaration namespace module AmbientDeclaration declare GlobalDeclaration global ClassDeclaration ClassBody AmbientFunctionDeclaration ExportGroup VariableName VariableName ImportDeclaration ImportGroup ForStatement for ForSpec ForInSpec ForOfSpec of WhileStatement while WithStatement with DoStatement do IfStatement if else SwitchStatement switch SwitchBody CaseLabel case DefaultLabel TryStatement try CatchClause catch FinallyClause finally ReturnStatement return ThrowStatement throw BreakStatement break ContinueStatement continue DebuggerStatement debugger LabeledStatement ExpressionStatement SingleExpression SingleClassItem", + maxTerm: 376, + context: trackNewline, + nodeProps: [ + ["isolate", -8,5,6,14,34,36,48,50,52,""], + ["group", -26,9,17,19,65,204,208,212,213,215,218,221,231,233,239,241,243,245,248,254,260,262,264,266,268,270,271,"Statement",-34,13,14,29,32,33,39,48,51,52,54,59,67,69,73,77,79,81,82,107,108,117,118,135,138,140,141,142,143,144,146,147,166,167,169,"Expression",-23,28,30,34,38,40,42,171,173,175,176,178,179,180,182,183,184,186,187,188,198,200,202,203,"Type",-3,85,100,106,"ClassItem"], + ["openedBy", 23,"<",35,"InterpolationStart",53,"[",57,"{",70,"(",159,"JSXStartCloseTag"], + ["closedBy", 24,">",37,"InterpolationEnd",47,"]",58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z;'S;=`+a<%lO%Z'Ad#Gpi$h&j(Rp(U!bp'9tOY%ZYZ&cZr%Zrs&}sw%Zwx(rx!Q%Z!Q![#Ge![!^%Z!^!_*g!_!c%Z!c!i#Ge!i#O%Z#O#P&c#P#R%Z#R#S#Ge#S#T%Z#T#Z#Ge#Z#b%Z#b#c#>_#c#o%Z#o#p*g#p;'S%Z;'S;=`+a<%lO%Z*)x#Il_!d$b$h&j#})Lv(Rp(U!bOY%ZYZ&cZr%Zrs&}sw%Zwx(rx!^%Z!^!_*g!_#O%Z#O#P&c#P#o%Z#o#p*g#p;'S%Z;'S;=`+a<%lO%Z)[#Jv_al$h&j(Rp(U!bOY%ZYZ&cZr%Zrs&}sw%Zwx(rx!^%Z!^!_*g!_#O%Z#O#P&c#P#o%Z#o#p*g#p;'S%Z;'S;=`+a<%lO%Z04f#LS^h#)`#O- spec_identifier[value] || -1},{term: 338, get: (value) => spec_word[value] || -1},{term: 92, get: (value) => spec_LessThan[value] || -1}], + tokenPrec: 14749 }); + /** -Extension to enable bracket-closing behavior. When a closeable -bracket is typed, its closing bracket is immediately inserted -after the cursor. When closing a bracket directly in front of a -closing bracket inserted by the extension, the cursor moves over -that bracket. +An instance of this is passed to completion source functions. */ -function closeBrackets() { - return [inputHandler, bracketState]; +class CompletionContext { + /** + Create a new completion context. (Mostly useful for testing + completion sources—in the editor, the extension will create + these for you.) + */ + constructor( + /** + The editor state that the completion happens in. + */ + state, + /** + The position at which the completion is happening. + */ + pos, + /** + Indicates whether completion was activated explicitly, or + implicitly by typing. The usual way to respond to this is to + only return completions when either there is part of a + completable entity before the cursor, or `explicit` is true. + */ + explicit) { + this.state = state; + this.pos = pos; + this.explicit = explicit; + /** + @internal + */ + this.abortListeners = []; + } + /** + Get the extent, content, and (if there is a token) type of the + token before `this.pos`. + */ + tokenBefore(types) { + let token = syntaxTree(this.state).resolveInner(this.pos, -1); + while (token && types.indexOf(token.name) < 0) + token = token.parent; + return token ? { from: token.from, to: this.pos, + text: this.state.sliceDoc(token.from, this.pos), + type: token.type } : null; + } + /** + Get the match of the given expression directly before the + cursor. + */ + matchBefore(expr) { + let line = this.state.doc.lineAt(this.pos); + let start = Math.max(line.from, this.pos - 250); + let str = line.text.slice(start - line.from, this.pos - line.from); + let found = str.search(ensureAnchor(expr, false)); + return found < 0 ? null : { from: start + found, to: this.pos, text: str.slice(found) }; + } + /** + Yields true when the query has been aborted. Can be useful in + asynchronous queries to avoid doing work that will be ignored. + */ + get aborted() { return this.abortListeners == null; } + /** + Allows you to register abort handlers, which will be called when + the query is + [aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted). + */ + addEventListener(type, listener) { + if (type == "abort" && this.abortListeners) + this.abortListeners.push(listener); + } } -const definedClosing = "()[]{}<>"; -function closing(ch) { - for (let i = 0; i < definedClosing.length; i += 2) - if (definedClosing.charCodeAt(i) == ch) - return definedClosing.charAt(i + 1); - return fromCodePoint(ch < 128 ? ch : ch + 1); +function toSet(chars) { + let flat = Object.keys(chars).join(""); + let words = /\w/.test(flat); + if (words) + flat = flat.replace(/\w/g, ""); + return `[${words ? "\\w" : ""}${flat.replace(/[^\w\s]/g, "\\$&")}]`; } -function config(state, pos) { - return state.languageDataAt("closeBrackets", pos)[0] || defaults; +function prefixMatch(options) { + let first = Object.create(null), rest = Object.create(null); + for (let { label } of options) { + first[label[0]] = true; + for (let i = 1; i < label.length; i++) + rest[label[i]] = true; + } + let source = toSet(first) + toSet(rest) + "*$"; + return [new RegExp("^" + source), new RegExp(source)]; } -const android$1 = typeof navigator == "object" && /*@__PURE__*//Android\b/.test(navigator.userAgent); -const inputHandler = /*@__PURE__*/EditorView.inputHandler.of((view, from, to, insert) => { - if ((android$1 ? view.composing : view.compositionStarted) || view.state.readOnly) - return false; - let sel = view.state.selection.main; - if (insert.length > 2 || insert.length == 2 && codePointSize(codePointAt(insert, 0)) == 1 || - from != sel.from || to != sel.to) - return false; - let tr = insertBracket(view.state, insert); - if (!tr) - return false; - view.dispatch(tr); - return true; -}); /** -Command that implements deleting a pair of matching brackets when -the cursor is between them. -*/ -const deleteBracketPair = ({ state, dispatch }) => { - if (state.readOnly) - return false; - let conf = config(state, state.selection.main.head); - let tokens = conf.brackets || defaults.brackets; - let dont = null, changes = state.changeByRange(range => { - if (range.empty) { - let before = prevChar(state.doc, range.head); - for (let token of tokens) { - if (token == before && nextChar(state.doc, range.head) == closing(codePointAt(token, 0))) - return { changes: { from: range.head - token.length, to: range.head + token.length }, - range: EditorSelection.cursor(range.head - token.length) }; - } - } - return { range: dont = range }; - }); - if (!dont) - dispatch(state.update(changes, { scrollIntoView: true, userEvent: "delete.backward" })); - return !dont; -}; -/** -Close-brackets related key bindings. Binds Backspace to -[`deleteBracketPair`](https://codemirror.net/6/docs/ref/#autocomplete.deleteBracketPair). +Given a a fixed array of options, return an autocompleter that +completes them. */ -const closeBracketsKeymap = [ - { key: "Backspace", run: deleteBracketPair } -]; +function completeFromList(list) { + let options = list.map(o => typeof o == "string" ? { label: o } : o); + let [validFor, match] = options.every(o => /^\w+$/.test(o.label)) ? [/\w*$/, /\w+$/] : prefixMatch(options); + return (context) => { + let token = context.matchBefore(match); + return token || context.explicit ? { from: token ? token.from : context.pos, options, validFor } : null; + }; +} /** -Implements the extension's behavior on text insertion. If the -given string counts as a bracket in the language around the -selection, and replacing the selection with it requires custom -behavior (inserting a closing version or skipping past a -previously-closed bracket), this function returns a transaction -representing that custom behavior. (You only need this if you want -to programmatically insert brackets—the -[`closeBrackets`](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets) extension will -take care of running this for user input.) +Wrap the given completion source so that it will not fire when the +cursor is in a syntax node with one of the given names. */ -function insertBracket(state, bracket) { - let conf = config(state, state.selection.main.head); - let tokens = conf.brackets || defaults.brackets; - for (let tok of tokens) { - let closed = closing(codePointAt(tok, 0)); - if (bracket == tok) - return closed == tok ? handleSame(state, tok, tokens.indexOf(tok + tok + tok) > -1, conf) - : handleOpen(state, tok, closed, conf.before || defaults.before); - if (bracket == closed && closedBracketAt(state, state.selection.main.from)) - return handleClose(state, tok, closed); - } - return null; -} -function closedBracketAt(state, pos) { - let found = false; - state.field(bracketState).between(0, state.doc.length, from => { - if (from == pos) - found = true; - }); - return found; -} -function nextChar(doc, pos) { - let next = doc.sliceString(pos, pos + 2); - return next.slice(0, codePointSize(codePointAt(next, 0))); -} -function prevChar(doc, pos) { - let prev = doc.sliceString(pos - 2, pos); - return codePointSize(codePointAt(prev, 0)) == prev.length ? prev : prev.slice(1); -} -function handleOpen(state, open, close, closeBefore) { - let dont = null, changes = state.changeByRange(range => { - if (!range.empty) - return { changes: [{ insert: open, from: range.from }, { insert: close, from: range.to }], - effects: closeBracketEffect.of(range.to + open.length), - range: EditorSelection.range(range.anchor + open.length, range.head + open.length) }; - let next = nextChar(state.doc, range.head); - if (!next || /\s/.test(next) || closeBefore.indexOf(next) > -1) - return { changes: { insert: open + close, from: range.head }, - effects: closeBracketEffect.of(range.head + open.length), - range: EditorSelection.cursor(range.head + open.length) }; - return { range: dont = range }; - }); - return dont ? null : state.update(changes, { - scrollIntoView: true, - userEvent: "input.type" - }); -} -function handleClose(state, _open, close) { - let dont = null, changes = state.changeByRange(range => { - if (range.empty && nextChar(state.doc, range.head) == close) - return { changes: { from: range.head, to: range.head + close.length, insert: close }, - range: EditorSelection.cursor(range.head + close.length) }; - return dont = { range }; - }); - return dont ? null : state.update(changes, { - scrollIntoView: true, - userEvent: "input.type" - }); -} -// Handles cases where the open and close token are the same, and -// possibly triple quotes (as in `"""abc"""`-style quoting). -function handleSame(state, token, allowTriple, config) { - let stringPrefixes = config.stringPrefixes || defaults.stringPrefixes; - let dont = null, changes = state.changeByRange(range => { - if (!range.empty) - return { changes: [{ insert: token, from: range.from }, { insert: token, from: range.to }], - effects: closeBracketEffect.of(range.to + token.length), - range: EditorSelection.range(range.anchor + token.length, range.head + token.length) }; - let pos = range.head, next = nextChar(state.doc, pos), start; - if (next == token) { - if (nodeStart(state, pos)) { - return { changes: { insert: token + token, from: pos }, - effects: closeBracketEffect.of(pos + token.length), - range: EditorSelection.cursor(pos + token.length) }; - } - else if (closedBracketAt(state, pos)) { - let isTriple = allowTriple && state.sliceDoc(pos, pos + token.length * 3) == token + token + token; - let content = isTriple ? token + token + token : token; - return { changes: { from: pos, to: pos + content.length, insert: content }, - range: EditorSelection.cursor(pos + content.length) }; - } - } - else if (allowTriple && state.sliceDoc(pos - 2 * token.length, pos) == token + token && - (start = canStartStringAt(state, pos - 2 * token.length, stringPrefixes)) > -1 && - nodeStart(state, start)) { - return { changes: { insert: token + token + token + token, from: pos }, - effects: closeBracketEffect.of(pos + token.length), - range: EditorSelection.cursor(pos + token.length) }; - } - else if (state.charCategorizer(pos)(next) != CharCategory.Word) { - if (canStartStringAt(state, pos, stringPrefixes) > -1 && !probablyInString(state, pos, token, stringPrefixes)) - return { changes: { insert: token + token, from: pos }, - effects: closeBracketEffect.of(pos + token.length), - range: EditorSelection.cursor(pos + token.length) }; - } - return { range: dont = range }; - }); - return dont ? null : state.update(changes, { - scrollIntoView: true, - userEvent: "input.type" - }); -} -function nodeStart(state, pos) { - let tree = syntaxTree(state).resolveInner(pos + 1); - return tree.parent && tree.from == pos; -} -function probablyInString(state, pos, quoteToken, prefixes) { - let node = syntaxTree(state).resolveInner(pos, -1); - let maxPrefix = prefixes.reduce((m, p) => Math.max(m, p.length), 0); - for (let i = 0; i < 5; i++) { - let start = state.sliceDoc(node.from, Math.min(node.to, node.from + quoteToken.length + maxPrefix)); - let quotePos = start.indexOf(quoteToken); - if (!quotePos || quotePos > -1 && prefixes.indexOf(start.slice(0, quotePos)) > -1) { - let first = node.firstChild; - while (first && first.from == node.from && first.to - first.from > quoteToken.length + quotePos) { - if (state.sliceDoc(first.to - quoteToken.length, first.to) == quoteToken) - return false; - first = first.firstChild; - } - return true; +function ifNotIn(nodes, source) { + return (context) => { + for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) { + if (nodes.indexOf(pos.name) > -1) + return null; + if (pos.type.isTop) + break; } - let parent = node.to == pos && node.parent; - if (!parent) - break; - node = parent; - } - return false; + return source(context); + }; } -function canStartStringAt(state, pos, prefixes) { - let charCat = state.charCategorizer(pos); - if (charCat(state.sliceDoc(pos - 1, pos)) != CharCategory.Word) - return pos; - for (let prefix of prefixes) { - let start = pos - prefix.length; - if (state.sliceDoc(start, pos) == prefix && charCat(state.sliceDoc(start - 1, start)) != CharCategory.Word) - return start; +class Option { + constructor(completion, source, match, score) { + this.completion = completion; + this.source = source; + this.match = match; + this.score = score; } - return -1; } - -/** -Returns an extension that enables autocompletion. -*/ -function autocompletion(config = {}) { - return [ - commitCharacters, - completionState, - completionConfig.of(config), - completionPlugin, - completionKeymapExt, - baseTheme$3 - ]; +function cur(state) { return state.selection.main.from; } +// Make sure the given regexp has a $ at its end and, if `start` is +// true, a ^ at its start. +function ensureAnchor(expr, start) { + var _a; + let { source } = expr; + let addStart = start && source[0] != "^", addEnd = source[source.length - 1] != "$"; + if (!addStart && !addEnd) + return expr; + return new RegExp(`${addStart ? "^" : ""}(?:${source})${addEnd ? "$" : ""}`, (_a = expr.flags) !== null && _a !== void 0 ? _a : (expr.ignoreCase ? "i" : "")); } /** -Basic keybindings for autocompletion. - - - Ctrl-Space: [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion) - - Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion) - - ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)` - - ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)` - - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")` - - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")` - - Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion) +This annotation is added to transactions that are produced by +picking a completion. */ -const completionKeymap = [ - { key: "Ctrl-Space", run: startCompletion }, - { key: "Escape", run: closeCompletion }, - { key: "ArrowDown", run: /*@__PURE__*/moveCompletionSelection(true) }, - { key: "ArrowUp", run: /*@__PURE__*/moveCompletionSelection(false) }, - { key: "PageDown", run: /*@__PURE__*/moveCompletionSelection(true, "page") }, - { key: "PageUp", run: /*@__PURE__*/moveCompletionSelection(false, "page") }, - { key: "Enter", run: acceptCompletion } -]; -const completionKeymapExt = /*@__PURE__*/Prec.highest(/*@__PURE__*/keymap.computeN([completionConfig], state => state.facet(completionConfig).defaultKeymap ? [completionKeymap] : [])); - +const pickedCompletion = /*@__PURE__*/Annotation.define(); /** -A collection of JavaScript-related -[snippets](https://codemirror.net/6/docs/ref/#autocomplete.snippet). +Helper function that returns a transaction spec which inserts a +completion's text in the main selection range, and any other +selection range that has the same text in front of it. */ -const snippets = [ - /*@__PURE__*/snippetCompletion("function ${name}(${params}) {\n\t${}\n}", { - label: "function", - detail: "definition", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n\t${}\n}", { - label: "for", - detail: "loop", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("for (let ${name} of ${collection}) {\n\t${}\n}", { - label: "for", - detail: "of loop", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("do {\n\t${}\n} while (${})", { - label: "do", - detail: "loop", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("while (${}) {\n\t${}\n}", { - label: "while", - detail: "loop", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("try {\n\t${}\n} catch (${error}) {\n\t${}\n}", { - label: "try", - detail: "/ catch block", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("if (${}) {\n\t${}\n}", { - label: "if", - detail: "block", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("if (${}) {\n\t${}\n} else {\n\t${}\n}", { - label: "if", - detail: "/ else block", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("class ${name} {\n\tconstructor(${params}) {\n\t\t${}\n\t}\n}", { - label: "class", - detail: "definition", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("import {${names}} from \"${module}\"\n${}", { - label: "import", - detail: "named", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("import ${name} from \"${module}\"\n${}", { - label: "import", - detail: "default", - type: "keyword" - }) -]; -/** -A collection of snippet completions for TypeScript. Includes the -JavaScript [snippets](https://codemirror.net/6/docs/ref/#lang-javascript.snippets). -*/ -const typescriptSnippets = /*@__PURE__*/snippets.concat([ - /*@__PURE__*/snippetCompletion("interface ${name} {\n\t${}\n}", { - label: "interface", - detail: "definition", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("type ${name} = ${type}", { - label: "type", - detail: "definition", - type: "keyword" - }), - /*@__PURE__*/snippetCompletion("enum ${name} {\n\t${}\n}", { - label: "enum", - detail: "definition", - type: "keyword" - }) -]); - -const cache = /*@__PURE__*/new NodeWeakMap(); -const ScopeNodes = /*@__PURE__*/new Set([ - "Script", "Block", - "FunctionExpression", "FunctionDeclaration", "ArrowFunction", "MethodDeclaration", - "ForStatement" -]); -function defID(type) { - return (node, def) => { - let id = node.node.getChild("VariableDefinition"); - if (id) - def(id, type); - return true; - }; +function insertCompletionText(state, text, from, to) { + let { main } = state.selection, fromOff = from - main.from, toOff = to - main.from; + return Object.assign(Object.assign({}, state.changeByRange(range => { + if (range != main && from != to && + state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to)) + return { range }; + return { + changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: text }, + range: EditorSelection.cursor(range.from + fromOff + text.length) + }; + })), { scrollIntoView: true, userEvent: "input.complete" }); } -const functionContext = ["FunctionDeclaration"]; -const gatherCompletions = { - FunctionDeclaration: /*@__PURE__*/defID("function"), - ClassDeclaration: /*@__PURE__*/defID("class"), - ClassExpression: () => true, - EnumDeclaration: /*@__PURE__*/defID("constant"), - TypeAliasDeclaration: /*@__PURE__*/defID("type"), - NamespaceDeclaration: /*@__PURE__*/defID("namespace"), - VariableDefinition(node, def) { if (!node.matchContext(functionContext)) - def(node, "variable"); }, - TypeDefinition(node, def) { def(node, "type"); }, - __proto__: null -}; -function getScope(doc, node) { - let cached = cache.get(node); - if (cached) - return cached; - let completions = [], top = true; - function def(node, type) { - let name = doc.sliceString(node.from, node.to); - completions.push({ label: name, type }); +const SourceCache = /*@__PURE__*/new WeakMap(); +function asSource(source) { + if (!Array.isArray(source)) + return source; + let known = SourceCache.get(source); + if (!known) + SourceCache.set(source, known = completeFromList(source)); + return known; +} +const startCompletionEffect = /*@__PURE__*/StateEffect.define(); +const closeCompletionEffect = /*@__PURE__*/StateEffect.define(); + +// A pattern matcher for fuzzy completion matching. Create an instance +// once for a pattern, and then use that to match any number of +// completions. +class FuzzyMatcher { + constructor(pattern) { + this.pattern = pattern; + this.chars = []; + this.folded = []; + // Buffers reused by calls to `match` to track matched character + // positions. + this.any = []; + this.precise = []; + this.byWord = []; + this.score = 0; + this.matched = []; + for (let p = 0; p < pattern.length;) { + let char = codePointAt(pattern, p), size = codePointSize(char); + this.chars.push(char); + let part = pattern.slice(p, p + size), upper = part.toUpperCase(); + this.folded.push(codePointAt(upper == part ? part.toLowerCase() : upper, 0)); + p += size; + } + this.astral = pattern.length != this.chars.length; } - node.cursor(IterMode.IncludeAnonymous).iterate(node => { - if (top) { - top = false; + ret(score, matched) { + this.score = score; + this.matched = matched; + return this; + } + // Matches a given word (completion) against the pattern (input). + // Will return a boolean indicating whether there was a match and, + // on success, set `this.score` to the score, `this.matched` to an + // array of `from, to` pairs indicating the matched parts of `word`. + // + // The score is a number that is more negative the worse the match + // is. See `Penalty` above. + match(word) { + if (this.pattern.length == 0) + return this.ret(-100 /* Penalty.NotFull */, []); + if (word.length < this.pattern.length) + return null; + let { chars, folded, any, precise, byWord } = this; + // For single-character queries, only match when they occur right + // at the start + if (chars.length == 1) { + let first = codePointAt(word, 0), firstSize = codePointSize(first); + let score = firstSize == word.length ? 0 : -100 /* Penalty.NotFull */; + if (first == chars[0]) ; + else if (first == folded[0]) + score += -200 /* Penalty.CaseFold */; + else + return null; + return this.ret(score, [0, firstSize]); } - else if (node.name) { - let gather = gatherCompletions[node.name]; - if (gather && gather(node, def) || ScopeNodes.has(node.name)) - return false; + let direct = word.indexOf(this.pattern); + if (direct == 0) + return this.ret(word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */, [0, this.pattern.length]); + let len = chars.length, anyTo = 0; + if (direct < 0) { + for (let i = 0, e = Math.min(word.length, 200); i < e && anyTo < len;) { + let next = codePointAt(word, i); + if (next == chars[anyTo] || next == folded[anyTo]) + any[anyTo++] = i; + i += codePointSize(next); + } + // No match, exit immediately + if (anyTo < len) + return null; } - else if (node.to - node.from > 8192) { - // Allow caching for bigger internal nodes - for (let c of getScope(doc, node.node)) - completions.push(c); - return false; + // This tracks the extent of the precise (non-folded, not + // necessarily adjacent) match + let preciseTo = 0; + // Tracks whether there is a match that hits only characters that + // appear to be starting words. `byWordFolded` is set to true when + // a case folded character is encountered in such a match + let byWordTo = 0, byWordFolded = false; + // If we've found a partial adjacent match, these track its state + let adjacentTo = 0, adjacentStart = -1, adjacentEnd = -1; + let hasLower = /[a-z]/.test(word), wordAdjacent = true; + // Go over the option's text, scanning for the various kinds of matches + for (let i = 0, e = Math.min(word.length, 200), prevType = 0 /* Tp.NonWord */; i < e && byWordTo < len;) { + let next = codePointAt(word, i); + if (direct < 0) { + if (preciseTo < len && next == chars[preciseTo]) + precise[preciseTo++] = i; + if (adjacentTo < len) { + if (next == chars[adjacentTo] || next == folded[adjacentTo]) { + if (adjacentTo == 0) + adjacentStart = i; + adjacentEnd = i + 1; + adjacentTo++; + } + else { + adjacentTo = 0; + } + } + } + let ch, type = next < 0xff + ? (next >= 48 && next <= 57 || next >= 97 && next <= 122 ? 2 /* Tp.Lower */ : next >= 65 && next <= 90 ? 1 /* Tp.Upper */ : 0 /* Tp.NonWord */) + : ((ch = fromCodePoint(next)) != ch.toLowerCase() ? 1 /* Tp.Upper */ : ch != ch.toUpperCase() ? 2 /* Tp.Lower */ : 0 /* Tp.NonWord */); + if (!i || type == 1 /* Tp.Upper */ && hasLower || prevType == 0 /* Tp.NonWord */ && type != 0 /* Tp.NonWord */) { + if (chars[byWordTo] == next || (folded[byWordTo] == next && (byWordFolded = true))) + byWord[byWordTo++] = i; + else if (byWord.length) + wordAdjacent = false; + } + prevType = type; + i += codePointSize(next); } - }); - cache.set(node, completions); - return completions; -} -const Identifier = /^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/; -const dontComplete = [ - "TemplateString", "String", "RegExp", - "LineComment", "BlockComment", - "VariableDefinition", "TypeDefinition", "Label", - "PropertyDefinition", "PropertyName", - "PrivatePropertyDefinition", "PrivatePropertyName", - ".", "?." -]; -/** -Completion source that looks up locally defined names in -JavaScript code. -*/ -function localCompletionSource(context) { - let inner = syntaxTree(context.state).resolveInner(context.pos, -1); - if (dontComplete.indexOf(inner.name) > -1) - return null; - let isWord = inner.name == "VariableName" || - inner.to - inner.from < 20 && Identifier.test(context.state.sliceDoc(inner.from, inner.to)); - if (!isWord && !context.explicit) - return null; - let options = []; - for (let pos = inner; pos; pos = pos.parent) { - if (ScopeNodes.has(pos.name)) - options = options.concat(getScope(context.state.doc, pos)); + if (byWordTo == len && byWord[0] == 0 && wordAdjacent) + return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0), byWord, word); + if (adjacentTo == len && adjacentStart == 0) + return this.ret(-200 /* Penalty.CaseFold */ - word.length + (adjacentEnd == word.length ? 0 : -100 /* Penalty.NotFull */), [0, adjacentEnd]); + if (direct > -1) + return this.ret(-700 /* Penalty.NotStart */ - word.length, [direct, direct + this.pattern.length]); + if (adjacentTo == len) + return this.ret(-200 /* Penalty.CaseFold */ + -700 /* Penalty.NotStart */ - word.length, [adjacentStart, adjacentEnd]); + if (byWordTo == len) + return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0) + -700 /* Penalty.NotStart */ + + (wordAdjacent ? 0 : -1100 /* Penalty.Gap */), byWord, word); + return chars.length == 2 ? null + : this.result((any[0] ? -700 /* Penalty.NotStart */ : 0) + -200 /* Penalty.CaseFold */ + -1100 /* Penalty.Gap */, any, word); } - return { - options, - from: isWord ? inner.from : context.pos, - validFor: Identifier - }; -} - -/** -A language provider based on the [Lezer JavaScript -parser](https://github.com/lezer-parser/javascript), extended with -highlighting and indentation information. -*/ -const javascriptLanguage = /*@__PURE__*/LRLanguage.define({ - name: "javascript", - parser: /*@__PURE__*/parser.configure({ - props: [ - /*@__PURE__*/indentNodeProp.add({ - IfStatement: /*@__PURE__*/continuedIndent({ except: /^\s*({|else\b)/ }), - TryStatement: /*@__PURE__*/continuedIndent({ except: /^\s*({|catch\b|finally\b)/ }), - LabeledStatement: flatIndent, - SwitchBody: context => { - let after = context.textAfter, closed = /^\s*\}/.test(after), isCase = /^\s*(case|default)\b/.test(after); - return context.baseIndent + (closed ? 0 : isCase ? 1 : 2) * context.unit; - }, - Block: /*@__PURE__*/delimitedIndent({ closing: "}" }), - ArrowFunction: cx => cx.baseIndent + cx.unit, - "TemplateString BlockComment": () => null, - "Statement Property": /*@__PURE__*/continuedIndent({ except: /^{/ }), - JSXElement(context) { - let closed = /^\s*<\//.test(context.textAfter); - return context.lineIndent(context.node.from) + (closed ? 0 : context.unit); - }, - JSXEscape(context) { - let closed = /\s*\}/.test(context.textAfter); - return context.lineIndent(context.node.from) + (closed ? 0 : context.unit); - }, - "JSXOpenTag JSXSelfClosingTag"(context) { - return context.column(context.node.from) + context.unit; - } - }), - /*@__PURE__*/foldNodeProp.add({ - "Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType": foldInside, - BlockComment(tree) { return { from: tree.from + 2, to: tree.to - 2 }; } - }) - ] - }), - languageData: { - closeBrackets: { brackets: ["(", "[", "{", "'", '"', "`"] }, - commentTokens: { line: "//", block: { open: "/*", close: "*/" } }, - indentOnInput: /^\s*(?:case |default:|\{|\}|<\/)$/, - wordChars: "$" + result(score, positions, word) { + let result = [], i = 0; + for (let pos of positions) { + let to = pos + (this.astral ? codePointSize(codePointAt(word, pos)) : 1); + if (i && result[i - 1] == pos) + result[i - 1] = to; + else { + result[i++] = pos; + result[i++] = to; + } + } + return this.ret(score - word.length, result); } -}); -const jsxSublanguage = { - test: node => /^JSX/.test(node.name), - facet: /*@__PURE__*/defineLanguageFacet({ commentTokens: { block: { open: "{/*", close: "*/}" } } }) -}; -/** -A language provider for TypeScript. -*/ -const typescriptLanguage = /*@__PURE__*/javascriptLanguage.configure({ dialect: "ts" }, "typescript"); -/** -Language provider for JSX. -*/ -const jsxLanguage = /*@__PURE__*/javascriptLanguage.configure({ - dialect: "jsx", - props: [/*@__PURE__*/sublanguageProp.add(n => n.isTop ? [jsxSublanguage] : undefined)] -}); -/** -Language provider for JSX + TypeScript. -*/ -const tsxLanguage = /*@__PURE__*/javascriptLanguage.configure({ - dialect: "jsx ts", - props: [/*@__PURE__*/sublanguageProp.add(n => n.isTop ? [jsxSublanguage] : undefined)] -}, "typescript"); -let kwCompletion = (name) => ({ label: name, type: "keyword" }); -const keywords = /*@__PURE__*/"break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(kwCompletion); -const typescriptKeywords = /*@__PURE__*/keywords.concat(/*@__PURE__*/["declare", "implements", "private", "protected", "public"].map(kwCompletion)); -/** -JavaScript support. Includes [snippet](https://codemirror.net/6/docs/ref/#lang-javascript.snippets) -and local variable completion. -*/ -function javascript(config = {}) { - let lang = config.jsx ? (config.typescript ? tsxLanguage : jsxLanguage) - : config.typescript ? typescriptLanguage : javascriptLanguage; - let completions = config.typescript ? typescriptSnippets.concat(typescriptKeywords) : snippets.concat(keywords); - return new LanguageSupport(lang, [ - javascriptLanguage.data.of({ - autocomplete: ifNotIn(dontComplete, completeFromList(completions)) - }), - javascriptLanguage.data.of({ - autocomplete: localCompletionSource - }), - config.jsx ? autoCloseTags : [], - ]); } -function findOpenTag(node) { - for (;;) { - if (node.name == "JSXOpenTag" || node.name == "JSXSelfClosingTag" || node.name == "JSXFragmentTag") - return node; - if (node.name == "JSXEscape" || !node.parent) +class StrictMatcher { + constructor(pattern) { + this.pattern = pattern; + this.matched = []; + this.score = 0; + this.folded = pattern.toLowerCase(); + } + match(word) { + if (word.length < this.pattern.length) return null; - node = node.parent; + let start = word.slice(0, this.pattern.length); + let match = start == this.pattern ? 0 : start.toLowerCase() == this.folded ? -200 /* Penalty.CaseFold */ : null; + if (match == null) + return null; + this.matched = [0, start.length]; + this.score = match + (word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */); + return this; } } -function elementName(doc, tree, max = doc.length) { - for (let ch = tree === null || tree === void 0 ? void 0 : tree.firstChild; ch; ch = ch.nextSibling) { - if (ch.name == "JSXIdentifier" || ch.name == "JSXBuiltin" || ch.name == "JSXNamespacedName" || - ch.name == "JSXMemberExpression") - return doc.sliceString(ch.from, Math.min(ch.to, max)); + +const completionConfig = /*@__PURE__*/Facet.define({ + combine(configs) { + return combineConfig(configs, { + activateOnTyping: true, + activateOnCompletion: () => false, + activateOnTypingDelay: 100, + selectOnOpen: true, + override: null, + closeOnBlur: true, + maxRenderedOptions: 100, + defaultKeymap: true, + tooltipClass: () => "", + optionClass: () => "", + aboveCursor: false, + icons: true, + addToOptions: [], + positionInfo: defaultPositionInfo, + filterStrict: false, + compareCompletions: (a, b) => a.label.localeCompare(b.label), + interactionDelay: 75, + updateSyncTime: 100 + }, { + defaultKeymap: (a, b) => a && b, + closeOnBlur: (a, b) => a && b, + icons: (a, b) => a && b, + tooltipClass: (a, b) => c => joinClass(a(c), b(c)), + optionClass: (a, b) => c => joinClass(a(c), b(c)), + addToOptions: (a, b) => a.concat(b), + filterStrict: (a, b) => a || b, + }); } - return ""; +}); +function joinClass(a, b) { + return a ? b ? a + " " + b : a : b; } -const android = typeof navigator == "object" && /*@__PURE__*//Android\b/.test(navigator.userAgent); -/** -Extension that will automatically insert JSX close tags when a `>` or -`/` is typed. -*/ -const autoCloseTags = /*@__PURE__*/EditorView.inputHandler.of((view, from, to, text, defaultInsert) => { - if ((android ? view.composing : view.compositionStarted) || view.state.readOnly || - from != to || (text != ">" && text != "/") || - !javascriptLanguage.isActiveAt(view.state, from, -1)) - return false; - let base = defaultInsert(), { state } = base; - let closeTags = state.changeByRange(range => { - var _a; - let { head } = range, around = syntaxTree(state).resolveInner(head - 1, -1), name; - if (around.name == "JSXStartTag") - around = around.parent; - if (state.doc.sliceString(head - 1, head) != text || around.name == "JSXAttributeValue" && around.to > head) ; - else if (text == ">" && around.name == "JSXFragmentTag") { - return { range, changes: { from: head, insert: `` } }; - } - else if (text == "/" && around.name == "JSXStartCloseTag") { - let empty = around.parent, base = empty.parent; - if (base && empty.from == head - 2 && - ((name = elementName(state.doc, base.firstChild, head)) || ((_a = base.firstChild) === null || _a === void 0 ? void 0 : _a.name) == "JSXFragmentTag")) { - let insert = `${name}>`; - return { range: EditorSelection.cursor(head + insert.length, -1), changes: { from: head, insert } }; - } +function defaultPositionInfo(view, list, option, info, space, tooltip) { + let rtl = view.textDirection == Direction.RTL, left = rtl, narrow = false; + let side = "top", offset, maxWidth; + let spaceLeft = list.left - space.left, spaceRight = space.right - list.right; + let infoWidth = info.right - info.left, infoHeight = info.bottom - info.top; + if (left && spaceLeft < Math.min(infoWidth, spaceRight)) + left = false; + else if (!left && spaceRight < Math.min(infoWidth, spaceLeft)) + left = true; + if (infoWidth <= (left ? spaceLeft : spaceRight)) { + offset = Math.max(space.top, Math.min(option.top, space.bottom - infoHeight)) - list.top; + maxWidth = Math.min(400 /* Info.Width */, left ? spaceLeft : spaceRight); + } + else { + narrow = true; + maxWidth = Math.min(400 /* Info.Width */, (rtl ? list.right : space.right - list.left) - 30 /* Info.Margin */); + let spaceBelow = space.bottom - list.bottom; + if (spaceBelow >= infoHeight || spaceBelow > list.top) { // Below the completion + offset = option.bottom - list.top; } - else if (text == ">") { - let openTag = findOpenTag(around); - if (openTag && openTag.name == "JSXOpenTag" && - !/^\/?>|^<\//.test(state.doc.sliceString(head, head + 2)) && - (name = elementName(state.doc, openTag, head))) - return { range, changes: { from: head, insert: `` } }; + else { // Above it + side = "bottom"; + offset = list.bottom - option.top; } - return { range }; - }); - if (closeTags.changes.empty) - return false; - view.dispatch([ - base, - state.update(closeTags, { userEvent: "input.complete", scrollIntoView: true }) - ]); - return true; -}); - -/** -Comment or uncomment the current selection. Will use line comments -if available, otherwise falling back to block comments. -*/ -const toggleComment = target => { - let { state } = target, line = state.doc.lineAt(state.selection.main.from), config = getConfig(target.state, line.from); - return config.line ? toggleLineComment(target) : config.block ? toggleBlockCommentByLine(target) : false; -}; -function command(f, option) { - return ({ state, dispatch }) => { - if (state.readOnly) - return false; - let tr = f(option, state); - if (!tr) - return false; - dispatch(state.update(tr)); - return true; + } + let scaleY = (list.bottom - list.top) / tooltip.offsetHeight; + let scaleX = (list.right - list.left) / tooltip.offsetWidth; + return { + style: `${side}: ${offset / scaleY}px; max-width: ${maxWidth / scaleX}px`, + class: "cm-completionInfo-" + (narrow ? (rtl ? "left-narrow" : "right-narrow") : left ? "left" : "right") }; } -/** -Comment or uncomment the current selection using line comments. -The line comment syntax is taken from the -[`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language -data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). -*/ -const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* CommentOption.Toggle */); -/** -Comment or uncomment the current selection using block comments. -The block comment syntax is taken from the -[`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language -data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). -*/ -const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* CommentOption.Toggle */); -/** -Comment or uncomment the lines around the current selection using -block comments. -*/ -const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* CommentOption.Toggle */); -function getConfig(state, pos) { - let data = state.languageDataAt("commentTokens", pos); - return data.length ? data[0] : {}; + +function optionContent(config) { + let content = config.addToOptions.slice(); + if (config.icons) + content.push({ + render(completion) { + let icon = document.createElement("div"); + icon.classList.add("cm-completionIcon"); + if (completion.type) + icon.classList.add(...completion.type.split(/\s+/g).map(cls => "cm-completionIcon-" + cls)); + icon.setAttribute("aria-hidden", "true"); + return icon; + }, + position: 20 + }); + content.push({ + render(completion, _s, _v, match) { + let labelElt = document.createElement("span"); + labelElt.className = "cm-completionLabel"; + let label = completion.displayLabel || completion.label, off = 0; + for (let j = 0; j < match.length;) { + let from = match[j++], to = match[j++]; + if (from > off) + labelElt.appendChild(document.createTextNode(label.slice(off, from))); + let span = labelElt.appendChild(document.createElement("span")); + span.appendChild(document.createTextNode(label.slice(from, to))); + span.className = "cm-completionMatchedText"; + off = to; + } + if (off < label.length) + labelElt.appendChild(document.createTextNode(label.slice(off))); + return labelElt; + }, + position: 50 + }, { + render(completion) { + if (!completion.detail) + return null; + let detailElt = document.createElement("span"); + detailElt.className = "cm-completionDetail"; + detailElt.textContent = completion.detail; + return detailElt; + }, + position: 80 + }); + return content.sort((a, b) => a.position - b.position).map(a => a.render); } -const SearchMargin = 50; -/** -Determines if the given range is block-commented in the given -state. -*/ -function findBlockComment(state, { open, close }, from, to) { - let textBefore = state.sliceDoc(from - SearchMargin, from); - let textAfter = state.sliceDoc(to, to + SearchMargin); - let spaceBefore = /\s*$/.exec(textBefore)[0].length, spaceAfter = /^\s*/.exec(textAfter)[0].length; - let beforeOff = textBefore.length - spaceBefore; - if (textBefore.slice(beforeOff - open.length, beforeOff) == open && - textAfter.slice(spaceAfter, spaceAfter + close.length) == close) { - return { open: { pos: from - spaceBefore, margin: spaceBefore && 1 }, - close: { pos: to + spaceAfter, margin: spaceAfter && 1 } }; - } - let startText, endText; - if (to - from <= 2 * SearchMargin) { - startText = endText = state.sliceDoc(from, to); - } - else { - startText = state.sliceDoc(from, from + SearchMargin); - endText = state.sliceDoc(to - SearchMargin, to); - } - let startSpace = /^\s*/.exec(startText)[0].length, endSpace = /\s*$/.exec(endText)[0].length; - let endOff = endText.length - endSpace - close.length; - if (startText.slice(startSpace, startSpace + open.length) == open && - endText.slice(endOff, endOff + close.length) == close) { - return { open: { pos: from + startSpace + open.length, - margin: /\s/.test(startText.charAt(startSpace + open.length)) ? 1 : 0 }, - close: { pos: to - endSpace - close.length, - margin: /\s/.test(endText.charAt(endOff - 1)) ? 1 : 0 } }; +function rangeAroundSelected(total, selected, max) { + if (total <= max) + return { from: 0, to: total }; + if (selected < 0) + selected = 0; + if (selected <= (total >> 1)) { + let off = Math.floor(selected / max); + return { from: off * max, to: (off + 1) * max }; } - return null; + let off = Math.floor((total - selected) / max); + return { from: total - (off + 1) * max, to: total - off * max }; } -function selectedLineRanges(state) { - let ranges = []; - for (let r of state.selection.ranges) { - let fromLine = state.doc.lineAt(r.from); - let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to); - let last = ranges.length - 1; - if (last >= 0 && ranges[last].to > fromLine.from) - ranges[last].to = toLine.to; - else - ranges.push({ from: fromLine.from + /^\s*/.exec(fromLine.text)[0].length, to: toLine.to }); +class CompletionTooltip { + constructor(view, stateField, applyCompletion) { + this.view = view; + this.stateField = stateField; + this.applyCompletion = applyCompletion; + this.info = null; + this.infoDestroy = null; + this.placeInfoReq = { + read: () => this.measureInfo(), + write: (pos) => this.placeInfo(pos), + key: this + }; + this.space = null; + this.currentClass = ""; + let cState = view.state.field(stateField); + let { options, selected } = cState.open; + let config = view.state.facet(completionConfig); + this.optionContent = optionContent(config); + this.optionClass = config.optionClass; + this.tooltipClass = config.tooltipClass; + this.range = rangeAroundSelected(options.length, selected, config.maxRenderedOptions); + this.dom = document.createElement("div"); + this.dom.className = "cm-tooltip-autocomplete"; + this.updateTooltipClass(view.state); + this.dom.addEventListener("mousedown", (e) => { + let { options } = view.state.field(stateField).open; + for (let dom = e.target, match; dom && dom != this.dom; dom = dom.parentNode) { + if (dom.nodeName == "LI" && (match = /-(\d+)$/.exec(dom.id)) && +match[1] < options.length) { + this.applyCompletion(view, options[+match[1]]); + e.preventDefault(); + return; + } + } + }); + this.dom.addEventListener("focusout", (e) => { + let state = view.state.field(this.stateField, false); + if (state && state.tooltip && view.state.facet(completionConfig).closeOnBlur && + e.relatedTarget != view.contentDOM) + view.dispatch({ effects: closeCompletionEffect.of(null) }); + }); + this.showOptions(options, cState.id); } - return ranges; -} -// Performs toggle, comment and uncomment of block comments in -// languages that support them. -function changeBlockComment(option, state, ranges = state.selection.ranges) { - let tokens = ranges.map(r => getConfig(state, r.from).block); - if (!tokens.every(c => c)) - return null; - let comments = ranges.map((r, i) => findBlockComment(state, tokens[i], r.from, r.to)); - if (option != 2 /* CommentOption.Uncomment */ && !comments.every(c => c)) { - return { changes: state.changes(ranges.map((range, i) => { - if (comments[i]) - return []; - return [{ from: range.from, insert: tokens[i].open + " " }, { from: range.to, insert: " " + tokens[i].close }]; - })) }; + mount() { this.updateSel(); } + showOptions(options, id) { + if (this.list) + this.list.remove(); + this.list = this.dom.appendChild(this.createListBox(options, id, this.range)); + this.list.addEventListener("scroll", () => { + if (this.info) + this.view.requestMeasure(this.placeInfoReq); + }); } - else if (option != 1 /* CommentOption.Comment */ && comments.some(c => c)) { - let changes = []; - for (let i = 0, comment; i < comments.length; i++) - if (comment = comments[i]) { - let token = tokens[i], { open, close } = comment; - changes.push({ from: open.pos - token.open.length, to: open.pos + open.margin }, { from: close.pos - close.margin, to: close.pos + token.close.length }); + update(update) { + var _a; + let cState = update.state.field(this.stateField); + let prevState = update.startState.field(this.stateField); + this.updateTooltipClass(update.state); + if (cState != prevState) { + let { options, selected, disabled } = cState.open; + if (!prevState.open || prevState.open.options != options) { + this.range = rangeAroundSelected(options.length, selected, update.state.facet(completionConfig).maxRenderedOptions); + this.showOptions(options, cState.id); } - return { changes }; + this.updateSel(); + if (disabled != ((_a = prevState.open) === null || _a === void 0 ? void 0 : _a.disabled)) + this.dom.classList.toggle("cm-tooltip-autocomplete-disabled", !!disabled); + } } - return null; -} -// Performs toggle, comment and uncomment of line comments. -function changeLineComment(option, state, ranges = state.selection.ranges) { - let lines = []; - let prevLine = -1; - for (let { from, to } of ranges) { - let startI = lines.length, minIndent = 1e9; - let token = getConfig(state, from).line; - if (!token) - continue; - for (let pos = from; pos <= to;) { - let line = state.doc.lineAt(pos); - if (line.from > prevLine && (from == to || to > line.from)) { - prevLine = line.from; - let indent = /^\s*/.exec(line.text)[0].length; - let empty = indent == line.length; - let comment = line.text.slice(indent, indent + token.length) == token ? indent : -1; - if (indent < line.text.length && indent < minIndent) - minIndent = indent; - lines.push({ line, comment, token, indent, empty, single: false }); + updateTooltipClass(state) { + let cls = this.tooltipClass(state); + if (cls != this.currentClass) { + for (let c of this.currentClass.split(" ")) + if (c) + this.dom.classList.remove(c); + for (let c of cls.split(" ")) + if (c) + this.dom.classList.add(c); + this.currentClass = cls; + } + } + positioned(space) { + this.space = space; + if (this.info) + this.view.requestMeasure(this.placeInfoReq); + } + updateSel() { + let cState = this.view.state.field(this.stateField), open = cState.open; + if (open.selected > -1 && open.selected < this.range.from || open.selected >= this.range.to) { + this.range = rangeAroundSelected(open.options.length, open.selected, this.view.state.facet(completionConfig).maxRenderedOptions); + this.showOptions(open.options, cState.id); + } + if (this.updateSelectedOption(open.selected)) { + this.destroyInfo(); + let { completion } = open.options[open.selected]; + let { info } = completion; + if (!info) + return; + let infoResult = typeof info === "string" ? document.createTextNode(info) : info(completion); + if (!infoResult) + return; + if ("then" in infoResult) { + infoResult.then(obj => { + if (obj && this.view.state.field(this.stateField, false) == cState) + this.addInfoPane(obj, completion); + }).catch(e => logException(this.view.state, e, "completion info")); + } + else { + this.addInfoPane(infoResult, completion); } - pos = line.to + 1; } - if (minIndent < 1e9) - for (let i = startI; i < lines.length; i++) - if (lines[i].indent < lines[i].line.text.length) - lines[i].indent = minIndent; - if (lines.length == startI + 1) - lines[startI].single = true; } - if (option != 2 /* CommentOption.Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) { - let changes = []; - for (let { line, token, indent, empty, single } of lines) - if (single || !empty) - changes.push({ from: line.from + indent, insert: token + " " }); - let changeSet = state.changes(changes); - return { changes: changeSet, selection: state.selection.map(changeSet, 1) }; + addInfoPane(content, completion) { + this.destroyInfo(); + let wrap = this.info = document.createElement("div"); + wrap.className = "cm-tooltip cm-completionInfo"; + if (content.nodeType != null) { + wrap.appendChild(content); + this.infoDestroy = null; + } + else { + let { dom, destroy } = content; + wrap.appendChild(dom); + this.infoDestroy = destroy || null; + } + this.dom.appendChild(wrap); + this.view.requestMeasure(this.placeInfoReq); } - else if (option != 1 /* CommentOption.Comment */ && lines.some(l => l.comment >= 0)) { - let changes = []; - for (let { line, comment, token } of lines) - if (comment >= 0) { - let from = line.from + comment, to = from + token.length; - if (line.text[to - line.from] == " ") - to++; - changes.push({ from, to }); + updateSelectedOption(selected) { + let set = null; + for (let opt = this.list.firstChild, i = this.range.from; opt; opt = opt.nextSibling, i++) { + if (opt.nodeName != "LI" || !opt.id) { + i--; // A section header } - return { changes }; + else if (i == selected) { + if (!opt.hasAttribute("aria-selected")) { + opt.setAttribute("aria-selected", "true"); + set = opt; + } + } + else { + if (opt.hasAttribute("aria-selected")) + opt.removeAttribute("aria-selected"); + } + } + if (set) + scrollIntoView(this.list, set); + return set; } - return null; -} - -const fromHistory = /*@__PURE__*/Annotation.define(); -/** -Transaction annotation that will prevent that transaction from -being combined with other transactions in the undo history. Given -`"before"`, it'll prevent merging with previous transactions. With -`"after"`, subsequent transactions won't be combined with this -one. With `"full"`, the transaction is isolated on both sides. -*/ -const isolateHistory = /*@__PURE__*/Annotation.define(); -/** -This facet provides a way to register functions that, given a -transaction, provide a set of effects that the history should -store when inverting the transaction. This can be used to -integrate some kinds of effects in the history, so that they can -be undone (and redone again). -*/ -const invertedEffects = /*@__PURE__*/Facet.define(); -const historyConfig = /*@__PURE__*/Facet.define({ - combine(configs) { - return combineConfig(configs, { - minDepth: 100, - newGroupDelay: 500, - joinToEvent: (_t, isAdjacent) => isAdjacent, - }, { - minDepth: Math.max, - newGroupDelay: Math.min, - joinToEvent: (a, b) => (tr, adj) => a(tr, adj) || b(tr, adj) - }); + measureInfo() { + let sel = this.dom.querySelector("[aria-selected]"); + if (!sel || !this.info) + return null; + let listRect = this.dom.getBoundingClientRect(); + let infoRect = this.info.getBoundingClientRect(); + let selRect = sel.getBoundingClientRect(); + let space = this.space; + if (!space) { + let win = this.dom.ownerDocument.defaultView || window; + space = { left: 0, top: 0, right: win.innerWidth, bottom: win.innerHeight }; + } + if (selRect.top > Math.min(space.bottom, listRect.bottom) - 10 || + selRect.bottom < Math.max(space.top, listRect.top) + 10) + return null; + return this.view.state.facet(completionConfig).positionInfo(this.view, listRect, selRect, infoRect, space, this.dom); } -}); -const historyField_ = /*@__PURE__*/StateField.define({ - create() { - return HistoryState.empty; - }, - update(state, tr) { - let config = tr.state.facet(historyConfig); - let fromHist = tr.annotation(fromHistory); - if (fromHist) { - let item = HistEvent.fromTransaction(tr, fromHist.selection), from = fromHist.side; - let other = from == 0 /* BranchName.Done */ ? state.undone : state.done; - if (item) - other = updateBranch(other, other.length, config.minDepth, item); - else - other = addSelection(other, tr.startState.selection); - return new HistoryState(from == 0 /* BranchName.Done */ ? fromHist.rest : other, from == 0 /* BranchName.Done */ ? other : fromHist.rest); + placeInfo(pos) { + if (this.info) { + if (pos) { + if (pos.style) + this.info.style.cssText = pos.style; + this.info.className = "cm-tooltip cm-completionInfo " + (pos.class || ""); + } + else { + this.info.style.cssText = "top: -1e6px"; + } } - let isolate = tr.annotation(isolateHistory); - if (isolate == "full" || isolate == "before") - state = state.isolate(); - if (tr.annotation(Transaction.addToHistory) === false) - return !tr.changes.empty ? state.addMapping(tr.changes.desc) : state; - let event = HistEvent.fromTransaction(tr); - let time = tr.annotation(Transaction.time), userEvent = tr.annotation(Transaction.userEvent); - if (event) - state = state.addChanges(event, time, userEvent, config, tr); - else if (tr.selection) - state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay); - if (isolate == "full" || isolate == "after") - state = state.isolate(); - return state; - }, - toJSON(value) { - return { done: value.done.map(e => e.toJSON()), undone: value.undone.map(e => e.toJSON()) }; - }, - fromJSON(json) { - return new HistoryState(json.done.map(HistEvent.fromJSON), json.undone.map(HistEvent.fromJSON)); } -}); -/** -Create a history extension with the given configuration. -*/ -function history$1(config = {}) { - return [ - historyField_, - historyConfig.of(config), - EditorView.domEventHandlers({ - beforeinput(e, view) { - let command = e.inputType == "historyUndo" ? undo : e.inputType == "historyRedo" ? redo : null; - if (!command) - return false; - e.preventDefault(); - return command(view); + createListBox(options, id, range) { + const ul = document.createElement("ul"); + ul.id = id; + ul.setAttribute("role", "listbox"); + ul.setAttribute("aria-expanded", "true"); + ul.setAttribute("aria-label", this.view.state.phrase("Completions")); + let curSection = null; + for (let i = range.from; i < range.to; i++) { + let { completion, match } = options[i], { section } = completion; + if (section) { + let name = typeof section == "string" ? section : section.name; + if (name != curSection && (i > range.from || range.from == 0)) { + curSection = name; + if (typeof section != "string" && section.header) { + ul.appendChild(section.header(section)); + } + else { + let header = ul.appendChild(document.createElement("completion-section")); + header.textContent = name; + } + } } - }) - ]; -} -function cmd(side, selection) { - return function ({ state, dispatch }) { - if (!selection && state.readOnly) - return false; - let historyState = state.field(historyField_, false); - if (!historyState) - return false; - let tr = historyState.pop(side, state, selection); - if (!tr) - return false; - dispatch(tr); - return true; - }; -} -/** -Undo a single group of history events. Returns false if no group -was available. -*/ -const undo = /*@__PURE__*/cmd(0 /* BranchName.Done */, false); -/** -Redo a group of history events. Returns false if no group was -available. -*/ -const redo = /*@__PURE__*/cmd(1 /* BranchName.Undone */, false); -/** -Undo a change or selection change. -*/ -const undoSelection = /*@__PURE__*/cmd(0 /* BranchName.Done */, true); -/** -Redo a change or selection change. -*/ -const redoSelection = /*@__PURE__*/cmd(1 /* BranchName.Undone */, true); -// History events store groups of changes or effects that need to be -// undone/redone together. -class HistEvent { - constructor( - // The changes in this event. Normal events hold at least one - // change or effect. But it may be necessary to store selection - // events before the first change, in which case a special type of - // instance is created which doesn't hold any changes, with - // changes == startSelection == undefined - changes, - // The effects associated with this event - effects, - // Accumulated mapping (from addToHistory==false) that should be - // applied to events below this one. - mapped, - // The selection before this event - startSelection, - // Stores selection changes after this event, to be used for - // selection undo/redo. - selectionsAfter) { - this.changes = changes; - this.effects = effects; - this.mapped = mapped; - this.startSelection = startSelection; - this.selectionsAfter = selectionsAfter; - } - setSelAfter(after) { - return new HistEvent(this.changes, this.effects, this.mapped, this.startSelection, after); - } - toJSON() { - var _a, _b, _c; - return { - changes: (_a = this.changes) === null || _a === void 0 ? void 0 : _a.toJSON(), - mapped: (_b = this.mapped) === null || _b === void 0 ? void 0 : _b.toJSON(), - startSelection: (_c = this.startSelection) === null || _c === void 0 ? void 0 : _c.toJSON(), - selectionsAfter: this.selectionsAfter.map(s => s.toJSON()) - }; - } - static fromJSON(json) { - return new HistEvent(json.changes && ChangeSet.fromJSON(json.changes), [], json.mapped && ChangeDesc.fromJSON(json.mapped), json.startSelection && EditorSelection.fromJSON(json.startSelection), json.selectionsAfter.map(EditorSelection.fromJSON)); + const li = ul.appendChild(document.createElement("li")); + li.id = id + "-" + i; + li.setAttribute("role", "option"); + let cls = this.optionClass(completion); + if (cls) + li.className = cls; + for (let source of this.optionContent) { + let node = source(completion, this.view.state, this.view, match); + if (node) + li.appendChild(node); + } + } + if (range.from) + ul.classList.add("cm-completionListIncompleteTop"); + if (range.to < options.length) + ul.classList.add("cm-completionListIncompleteBottom"); + return ul; } - // This does not check `addToHistory` and such, it assumes the - // transaction needs to be converted to an item. Returns null when - // there are no changes or effects in the transaction. - static fromTransaction(tr, selection) { - let effects = none; - for (let invert of tr.startState.facet(invertedEffects)) { - let result = invert(tr); - if (result.length) - effects = effects.concat(result); + destroyInfo() { + if (this.info) { + if (this.infoDestroy) + this.infoDestroy(); + this.info.remove(); + this.info = null; } - if (!effects.length && tr.changes.empty) - return null; - return new HistEvent(tr.changes.invert(tr.startState.doc), effects, undefined, selection || tr.startState.selection, none); } - static selection(selections) { - return new HistEvent(undefined, none, undefined, undefined, selections); + destroy() { + this.destroyInfo(); } } -function updateBranch(branch, to, maxLen, newEvent) { - let start = to + 1 > maxLen + 20 ? to - maxLen - 1 : 0; - let newBranch = branch.slice(start, to); - newBranch.push(newEvent); - return newBranch; -} -function isAdjacent(a, b) { - let ranges = [], isAdjacent = false; - a.iterChangedRanges((f, t) => ranges.push(f, t)); - b.iterChangedRanges((_f, _t, f, t) => { - for (let i = 0; i < ranges.length;) { - let from = ranges[i++], to = ranges[i++]; - if (t >= from && f <= to) - isAdjacent = true; - } - }); - return isAdjacent; +function completionTooltip(stateField, applyCompletion) { + return (view) => new CompletionTooltip(view, stateField, applyCompletion); } -function eqSelectionShape(a, b) { - return a.ranges.length == b.ranges.length && - a.ranges.filter((r, i) => r.empty != b.ranges[i].empty).length === 0; +function scrollIntoView(container, element) { + let parent = container.getBoundingClientRect(); + let self = element.getBoundingClientRect(); + let scaleY = parent.height / container.offsetHeight; + if (self.top < parent.top) + container.scrollTop -= (parent.top - self.top) / scaleY; + else if (self.bottom > parent.bottom) + container.scrollTop += (self.bottom - parent.bottom) / scaleY; } -function conc(a, b) { - return !a.length ? b : !b.length ? a : a.concat(b); + +// Used to pick a preferred option when two options with the same +// label occur in the result. +function score(option) { + return (option.boost || 0) * 100 + (option.apply ? 10 : 0) + (option.info ? 5 : 0) + + (option.type ? 1 : 0); } -const none = []; -const MaxSelectionsPerEvent = 200; -function addSelection(branch, selection) { - if (!branch.length) { - return [HistEvent.selection([selection])]; +function sortOptions(active, state) { + let options = []; + let sections = null; + let addOption = (option) => { + options.push(option); + let { section } = option.completion; + if (section) { + if (!sections) + sections = []; + let name = typeof section == "string" ? section : section.name; + if (!sections.some(s => s.name == name)) + sections.push(typeof section == "string" ? { name } : section); + } + }; + let conf = state.facet(completionConfig); + for (let a of active) + if (a.hasResult()) { + let getMatch = a.result.getMatch; + if (a.result.filter === false) { + for (let option of a.result.options) { + addOption(new Option(option, a.source, getMatch ? getMatch(option) : [], 1e9 - options.length)); + } + } + else { + let pattern = state.sliceDoc(a.from, a.to), match; + let matcher = conf.filterStrict ? new StrictMatcher(pattern) : new FuzzyMatcher(pattern); + for (let option of a.result.options) + if (match = matcher.match(option.label)) { + let matched = !option.displayLabel ? match.matched : getMatch ? getMatch(option, match.matched) : []; + addOption(new Option(option, a.source, matched, match.score + (option.boost || 0))); + } + } + } + if (sections) { + let sectionOrder = Object.create(null), pos = 0; + let cmp = (a, b) => { var _a, _b; return ((_a = a.rank) !== null && _a !== void 0 ? _a : 1e9) - ((_b = b.rank) !== null && _b !== void 0 ? _b : 1e9) || (a.name < b.name ? -1 : 1); }; + for (let s of sections.sort(cmp)) { + pos -= 1e5; + sectionOrder[s.name] = pos; + } + for (let option of options) { + let { section } = option.completion; + if (section) + option.score += sectionOrder[typeof section == "string" ? section : section.name]; + } } - else { - let lastEvent = branch[branch.length - 1]; - let sels = lastEvent.selectionsAfter.slice(Math.max(0, lastEvent.selectionsAfter.length - MaxSelectionsPerEvent)); - if (sels.length && sels[sels.length - 1].eq(selection)) - return branch; - sels.push(selection); - return updateBranch(branch, branch.length - 1, 1e9, lastEvent.setSelAfter(sels)); + let result = [], prev = null; + let compare = conf.compareCompletions; + for (let opt of options.sort((a, b) => (b.score - a.score) || compare(a.completion, b.completion))) { + let cur = opt.completion; + if (!prev || prev.label != cur.label || prev.detail != cur.detail || + (prev.type != null && cur.type != null && prev.type != cur.type) || + prev.apply != cur.apply || prev.boost != cur.boost) + result.push(opt); + else if (score(opt.completion) > score(prev)) + result[result.length - 1] = opt; + prev = opt.completion; } + return result; } -// Assumes the top item has one or more selectionAfter values -function popSelection(branch) { - let last = branch[branch.length - 1]; - let newBranch = branch.slice(); - newBranch[branch.length - 1] = last.setSelAfter(last.selectionsAfter.slice(0, last.selectionsAfter.length - 1)); - return newBranch; -} -// Add a mapping to the top event in the given branch. If this maps -// away all the changes and effects in that item, drop it and -// propagate the mapping to the next item. -function addMappingToBranch(branch, mapping) { - if (!branch.length) - return branch; - let length = branch.length, selections = none; - while (length) { - let event = mapEvent(branch[length - 1], mapping, selections); - if (event.changes && !event.changes.empty || event.effects.length) { // Event survived mapping - let result = branch.slice(0, length); - result[length - 1] = event; - return result; +class CompletionDialog { + constructor(options, attrs, tooltip, timestamp, selected, disabled) { + this.options = options; + this.attrs = attrs; + this.tooltip = tooltip; + this.timestamp = timestamp; + this.selected = selected; + this.disabled = disabled; + } + setSelected(selected, id) { + return selected == this.selected || selected >= this.options.length ? this + : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled); + } + static build(active, state, id, prev, conf) { + let options = sortOptions(active, state); + if (!options.length) { + return prev && active.some(a => a.state == 1 /* State.Pending */) ? + new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null; } - else { // Drop this event, since there's no changes or effects left - mapping = event.mapped; - length--; - selections = event.selectionsAfter; + let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1; + if (prev && prev.selected != selected && prev.selected != -1) { + let selectedValue = prev.options[prev.selected].completion; + for (let i = 0; i < options.length; i++) + if (options[i].completion == selectedValue) { + selected = i; + break; + } } + return new CompletionDialog(options, makeAttrs(id, selected), { + pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8), + create: createTooltip, + above: conf.aboveCursor, + }, prev ? prev.timestamp : Date.now(), selected, false); + } + map(changes) { + return new CompletionDialog(this.options, this.attrs, Object.assign(Object.assign({}, this.tooltip), { pos: changes.mapPos(this.tooltip.pos) }), this.timestamp, this.selected, this.disabled); } - return selections.length ? [HistEvent.selection(selections)] : none; } -function mapEvent(event, mapping, extraSelections) { - let selections = conc(event.selectionsAfter.length ? event.selectionsAfter.map(s => s.map(mapping)) : none, extraSelections); - // Change-less events don't store mappings (they are always the last event in a branch) - if (!event.changes) - return HistEvent.selection(selections); - let mappedChanges = event.changes.map(mapping), before = mapping.mapDesc(event.changes, true); - let fullMapping = event.mapped ? event.mapped.composeDesc(before) : before; - return new HistEvent(mappedChanges, StateEffect.mapEffects(event.effects, mapping), fullMapping, event.startSelection.map(before), selections); +class CompletionState { + constructor(active, id, open) { + this.active = active; + this.id = id; + this.open = open; + } + static start() { + return new CompletionState(none$1, "cm-ac-" + Math.floor(Math.random() * 2e6).toString(36), null); + } + update(tr) { + let { state } = tr, conf = state.facet(completionConfig); + let sources = conf.override || + state.languageDataAt("autocomplete", cur(state)).map(asSource); + let active = sources.map(source => { + let value = this.active.find(s => s.source == source) || + new ActiveSource(source, this.active.some(a => a.state != 0 /* State.Inactive */) ? 1 /* State.Pending */ : 0 /* State.Inactive */); + return value.update(tr, conf); + }); + if (active.length == this.active.length && active.every((a, i) => a == this.active[i])) + active = this.active; + let open = this.open; + if (open && tr.docChanged) + open = open.map(tr.changes); + if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) || + !sameResults(active, this.active)) + open = CompletionDialog.build(active, state, this.id, open, conf); + else if (open && open.disabled && !active.some(a => a.state == 1 /* State.Pending */)) + open = null; + if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult())) + active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a); + for (let effect of tr.effects) + if (effect.is(setSelectedEffect)) + open = open && open.setSelected(effect.value, this.id); + return active == this.active && open == this.open ? this : new CompletionState(active, this.id, open); + } + get tooltip() { return this.open ? this.open.tooltip : null; } + get attrs() { return this.open ? this.open.attrs : baseAttrs; } } -const joinableUserEvent = /^(input\.type|delete)($|\.)/; -class HistoryState { - constructor(done, undone, prevTime = 0, prevUserEvent = undefined) { - this.done = done; - this.undone = undone; - this.prevTime = prevTime; - this.prevUserEvent = prevUserEvent; +function sameResults(a, b) { + if (a == b) + return true; + for (let iA = 0, iB = 0;;) { + while (iA < a.length && !a[iA].hasResult) + iA++; + while (iB < b.length && !b[iB].hasResult) + iB++; + let endA = iA == a.length, endB = iB == b.length; + if (endA || endB) + return endA == endB; + if (a[iA++].result != b[iB++].result) + return false; } - isolate() { - return this.prevTime ? new HistoryState(this.done, this.undone) : this; +} +const baseAttrs = { + "aria-autocomplete": "list" +}; +function makeAttrs(id, selected) { + let result = { + "aria-autocomplete": "list", + "aria-haspopup": "listbox", + "aria-controls": id + }; + if (selected > -1) + result["aria-activedescendant"] = id + "-" + selected; + return result; +} +const none$1 = []; +function getUserEvent(tr, conf) { + if (tr.isUserEvent("input.complete")) { + let completion = tr.annotation(pickedCompletion); + if (completion && conf.activateOnCompletion(completion)) + return "input"; } - addChanges(event, time, userEvent, config, tr) { - let done = this.done, lastEvent = done[done.length - 1]; - if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes && - (!userEvent || joinableUserEvent.test(userEvent)) && - ((!lastEvent.selectionsAfter.length && - time - this.prevTime < config.newGroupDelay && - config.joinToEvent(tr, isAdjacent(lastEvent.changes, event.changes))) || - // For compose (but not compose.start) events, always join with previous event - userEvent == "input.type.compose")) { - done = updateBranch(done, done.length - 1, config.minDepth, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none)); - } - else { - done = updateBranch(done, done.length, config.minDepth, event); + return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null; +} +class ActiveSource { + constructor(source, state, explicitPos = -1) { + this.source = source; + this.state = state; + this.explicitPos = explicitPos; + } + hasResult() { return false; } + update(tr, conf) { + let event = getUserEvent(tr, conf), value = this; + if (event) + value = value.handleUserEvent(tr, event, conf); + else if (tr.docChanged) + value = value.handleChange(tr); + else if (tr.selection && value.state != 0 /* State.Inactive */) + value = new ActiveSource(value.source, 0 /* State.Inactive */); + for (let effect of tr.effects) { + if (effect.is(startCompletionEffect)) + value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value ? cur(tr.state) : -1); + else if (effect.is(closeCompletionEffect)) + value = new ActiveSource(value.source, 0 /* State.Inactive */); + else if (effect.is(setActiveEffect)) + for (let active of effect.value) + if (active.source == value.source) + value = active; } - return new HistoryState(done, none, time, userEvent); + return value; } - addSelection(selection, time, userEvent, newGroupDelay) { - let last = this.done.length ? this.done[this.done.length - 1].selectionsAfter : none; - if (last.length > 0 && - time - this.prevTime < newGroupDelay && - userEvent == this.prevUserEvent && userEvent && /^select($|\.)/.test(userEvent) && - eqSelectionShape(last[last.length - 1], selection)) - return this; - return new HistoryState(addSelection(this.done, selection), this.undone, time, userEvent); + handleUserEvent(tr, type, conf) { + return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(this.source, 1 /* State.Pending */); } - addMapping(mapping) { - return new HistoryState(addMappingToBranch(this.done, mapping), addMappingToBranch(this.undone, mapping), this.prevTime, this.prevUserEvent); + handleChange(tr) { + return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes); } - pop(side, state, onlySelection) { - let branch = side == 0 /* BranchName.Done */ ? this.done : this.undone; - if (branch.length == 0) - return null; - let event = branch[branch.length - 1], selection = event.selectionsAfter[0] || state.selection; - if (onlySelection && event.selectionsAfter.length) { - return state.update({ - selection: event.selectionsAfter[event.selectionsAfter.length - 1], - annotations: fromHistory.of({ side, rest: popSelection(branch), selection }), - userEvent: side == 0 /* BranchName.Done */ ? "select.undo" : "select.redo", - scrollIntoView: true - }); - } - else if (!event.changes) { - return null; - } - else { - let rest = branch.length == 1 ? none : branch.slice(0, branch.length - 1); - if (event.mapped) - rest = addMappingToBranch(rest, event.mapped); - return state.update({ - changes: event.changes, - selection: event.startSelection, - effects: event.effects, - annotations: fromHistory.of({ side, rest, selection }), - filter: false, - userEvent: side == 0 /* BranchName.Done */ ? "undo" : "redo", - scrollIntoView: true - }); - } + map(changes) { + return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos)); } } -HistoryState.empty = /*@__PURE__*/new HistoryState(none, none); -/** -Default key bindings for the undo history. - -- Mod-z: [`undo`](https://codemirror.net/6/docs/ref/#commands.undo). -- Mod-y (Mod-Shift-z on macOS) + Ctrl-Shift-z on Linux: [`redo`](https://codemirror.net/6/docs/ref/#commands.redo). -- Mod-u: [`undoSelection`](https://codemirror.net/6/docs/ref/#commands.undoSelection). -- Alt-u (Mod-Shift-u on macOS): [`redoSelection`](https://codemirror.net/6/docs/ref/#commands.redoSelection). -*/ -const historyKeymap = [ - { key: "Mod-z", run: undo, preventDefault: true }, - { key: "Mod-y", mac: "Mod-Shift-z", run: redo, preventDefault: true }, - { linux: "Ctrl-Shift-z", run: redo, preventDefault: true }, - { key: "Mod-u", run: undoSelection, preventDefault: true }, - { key: "Alt-u", mac: "Mod-Shift-u", run: redoSelection, preventDefault: true } -]; - -function updateSel(sel, by) { - return EditorSelection.create(sel.ranges.map(by), sel.mainIndex); -} -function setSel(state, selection) { - return state.update({ selection, scrollIntoView: true, userEvent: "select" }); +class ActiveResult extends ActiveSource { + constructor(source, explicitPos, result, from, to) { + super(source, 2 /* State.Result */, explicitPos); + this.result = result; + this.from = from; + this.to = to; + } + hasResult() { return true; } + handleUserEvent(tr, type, conf) { + var _a; + let result = this.result; + if (result.map && !tr.changes.empty) + result = result.map(result, tr.changes); + let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1); + let pos = cur(tr.state); + if ((this.explicitPos < 0 ? pos <= from : pos < this.from) || + pos > to || !result || + type == "delete" && cur(tr.startState) == this.from) + return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* State.Pending */ : 0 /* State.Inactive */); + let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos); + if (checkValid(result.validFor, tr.state, from, to)) + return new ActiveResult(this.source, explicitPos, result, from, to); + if (result.update && + (result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0)))) + return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state)); + return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos); + } + handleChange(tr) { + return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes); + } + map(mapping) { + if (mapping.empty) + return this; + let result = this.result.map ? this.result.map(this.result, mapping) : this.result; + if (!result) + return new ActiveSource(this.source, 0 /* State.Inactive */); + return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1)); + } } -function moveSel({ state, dispatch }, how) { - let selection = updateSel(state.selection, how); - if (selection.eq(state.selection, true)) +function checkValid(validFor, state, from, to) { + if (!validFor) return false; - dispatch(setSel(state, selection)); - return true; -} -function rangeEnd(range, forward) { - return EditorSelection.cursor(forward ? range.to : range.from); -} -function cursorByChar(view, forward) { - return moveSel(view, range => range.empty ? view.moveByChar(range, forward) : rangeEnd(range, forward)); -} -function ltrAtCursor(view) { - return view.textDirectionAt(view.state.selection.main.head) == Direction.LTR; + let text = state.sliceDoc(from, to); + return typeof validFor == "function" ? validFor(text, from, to, state) : ensureAnchor(validFor, true).test(text); } -/** -Move the selection one character to the left (which is backward in -left-to-right text, forward in right-to-left text). -*/ -const cursorCharLeft = view => cursorByChar(view, !ltrAtCursor(view)); -/** -Move the selection one character to the right. -*/ -const cursorCharRight = view => cursorByChar(view, ltrAtCursor(view)); -function cursorByGroup(view, forward) { - return moveSel(view, range => range.empty ? view.moveByGroup(range, forward) : rangeEnd(range, forward)); -} -/** -Move the selection to the left across one group of word or -non-word (but also non-space) characters. -*/ -const cursorGroupLeft = view => cursorByGroup(view, !ltrAtCursor(view)); -/** -Move the selection one group to the right. -*/ -const cursorGroupRight = view => cursorByGroup(view, ltrAtCursor(view)); -function interestingNode(state, node, bracketProp) { - if (node.type.prop(bracketProp)) - return true; - let len = node.to - node.from; - return len && (len > 2 || /[^\s,.;:]/.test(state.sliceDoc(node.from, node.to))) || node.firstChild; -} -function moveBySyntax(state, start, forward) { - let pos = syntaxTree(state).resolveInner(start.head); - let bracketProp = forward ? NodeProp.closedBy : NodeProp.openedBy; - // Scan forward through child nodes to see if there's an interesting - // node ahead. - for (let at = start.head;;) { - let next = forward ? pos.childAfter(at) : pos.childBefore(at); - if (!next) - break; - if (interestingNode(state, next, bracketProp)) - pos = next; - else - at = forward ? next.to : next.from; - } - let bracket = pos.type.prop(bracketProp), match, newPos; - if (bracket && (match = forward ? matchBrackets(state, pos.from, 1) : matchBrackets(state, pos.to, -1)) && match.matched) - newPos = forward ? match.end.to : match.end.from; - else - newPos = forward ? pos.to : pos.from; - return EditorSelection.cursor(newPos, forward ? -1 : 1); -} -/** -Move the cursor over the next syntactic element to the left. -*/ -const cursorSyntaxLeft = view => moveSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view))); -/** -Move the cursor over the next syntactic element to the right. -*/ -const cursorSyntaxRight = view => moveSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view))); -function cursorByLine(view, forward) { - return moveSel(view, range => { - if (!range.empty) - return rangeEnd(range, forward); - let moved = view.moveVertically(range, forward); - return moved.head != range.head ? moved : view.moveToLineBoundary(range, forward); - }); -} -/** -Move the selection one line up. -*/ -const cursorLineUp = view => cursorByLine(view, false); -/** -Move the selection one line down. -*/ -const cursorLineDown = view => cursorByLine(view, true); -function pageInfo(view) { - let selfScroll = view.scrollDOM.clientHeight < view.scrollDOM.scrollHeight - 2; - let marginTop = 0, marginBottom = 0, height; - if (selfScroll) { - for (let source of view.state.facet(EditorView.scrollMargins)) { - let margins = source(view); - if (margins === null || margins === void 0 ? void 0 : margins.top) - marginTop = Math.max(margins === null || margins === void 0 ? void 0 : margins.top, marginTop); - if (margins === null || margins === void 0 ? void 0 : margins.bottom) - marginBottom = Math.max(margins === null || margins === void 0 ? void 0 : margins.bottom, marginBottom); - } - height = view.scrollDOM.clientHeight - marginTop - marginBottom; - } - else { - height = (view.dom.ownerDocument.defaultView || window).innerHeight; - } - return { marginTop, marginBottom, selfScroll, - height: Math.max(view.defaultLineHeight, height - 5) }; -} -function cursorByPage(view, forward) { - let page = pageInfo(view); - let { state } = view, selection = updateSel(state.selection, range => { - return range.empty ? view.moveVertically(range, forward, page.height) - : rangeEnd(range, forward); - }); - if (selection.eq(state.selection)) +const setActiveEffect = /*@__PURE__*/StateEffect.define({ + map(sources, mapping) { return sources.map(s => s.map(mapping)); } +}); +const setSelectedEffect = /*@__PURE__*/StateEffect.define(); +const completionState = /*@__PURE__*/StateField.define({ + create() { return CompletionState.start(); }, + update(value, tr) { return value.update(tr); }, + provide: f => [ + showTooltip.from(f, val => val.tooltip), + EditorView.contentAttributes.from(f, state => state.attrs) + ] +}); +function applyCompletion(view, option) { + const apply = option.completion.apply || option.completion.label; + let result = view.state.field(completionState).active.find(a => a.source == option.source); + if (!(result instanceof ActiveResult)) return false; - let effect; - if (page.selfScroll) { - let startPos = view.coordsAtPos(state.selection.main.head); - let scrollRect = view.scrollDOM.getBoundingClientRect(); - let scrollTop = scrollRect.top + page.marginTop, scrollBottom = scrollRect.bottom - page.marginBottom; - if (startPos && startPos.top > scrollTop && startPos.bottom < scrollBottom) - effect = EditorView.scrollIntoView(selection.main.head, { y: "start", yMargin: startPos.top - scrollTop }); - } - view.dispatch(setSel(state, selection), { effects: effect }); + if (typeof apply == "string") + view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) })); + else + apply(view, option.completion, result.from, result.to); return true; } +const createTooltip = /*@__PURE__*/completionTooltip(completionState, applyCompletion); + /** -Move the selection one page up. -*/ -const cursorPageUp = view => cursorByPage(view, false); -/** -Move the selection one page down. +Returns a command that moves the completion selection forward or +backward by the given amount. */ -const cursorPageDown = view => cursorByPage(view, true); -function moveByLineBoundary(view, start, forward) { - let line = view.lineBlockAt(start.head), moved = view.moveToLineBoundary(start, forward); - if (moved.head == start.head && moved.head != (forward ? line.to : line.from)) - moved = view.moveToLineBoundary(start, forward, false); - if (!forward && moved.head == line.from && line.length) { - let space = /^\s*/.exec(view.state.sliceDoc(line.from, Math.min(line.from + 100, line.to)))[0].length; - if (space && start.head != line.from + space) - moved = EditorSelection.cursor(line.from + space); - } - return moved; +function moveCompletionSelection(forward, by = "option") { + return (view) => { + let cState = view.state.field(completionState, false); + if (!cState || !cState.open || cState.open.disabled || + Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) + return false; + let step = 1, tooltip; + if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip))) + step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / + tooltip.dom.querySelector("li").offsetHeight) - 1); + let { length } = cState.open.options; + let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length - 1; + if (selected < 0) + selected = by == "page" ? 0 : length - 1; + else if (selected >= length) + selected = by == "page" ? length - 1 : 0; + view.dispatch({ effects: setSelectedEffect.of(selected) }); + return true; + }; } /** -Move the selection to the next line wrap point, or to the end of -the line if there isn't one left on this line. -*/ -const cursorLineBoundaryForward = view => moveSel(view, range => moveByLineBoundary(view, range, true)); -/** -Move the selection to previous line wrap point, or failing that to -the start of the line. If the line is indented, and the cursor -isn't already at the end of the indentation, this will move to the -end of the indentation instead of the start of the line. -*/ -const cursorLineBoundaryBackward = view => moveSel(view, range => moveByLineBoundary(view, range, false)); -/** -Move the selection one line wrap point to the left. -*/ -const cursorLineBoundaryLeft = view => moveSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view))); -/** -Move the selection one line wrap point to the right. -*/ -const cursorLineBoundaryRight = view => moveSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view))); -/** -Move the selection to the start of the line. +Accept the current completion. */ -const cursorLineStart = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1)); +const acceptCompletion = (view) => { + let cState = view.state.field(completionState, false); + if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || cState.open.disabled || + Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) + return false; + return applyCompletion(view, cState.open.options[cState.open.selected]); +}; /** -Move the selection to the end of the line. +Explicitly start autocompletion. */ -const cursorLineEnd = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to, -1)); -function toMatchingBracket(state, dispatch, extend) { - let found = false, selection = updateSel(state.selection, range => { - let matching = matchBrackets(state, range.head, -1) - || matchBrackets(state, range.head, 1) - || (range.head > 0 && matchBrackets(state, range.head - 1, 1)) - || (range.head < state.doc.length && matchBrackets(state, range.head + 1, -1)); - if (!matching || !matching.end) - return range; - found = true; - let head = matching.start.from == range.head ? matching.end.to : matching.end.from; - return EditorSelection.cursor(head); - }); - if (!found) +const startCompletion = (view) => { + let cState = view.state.field(completionState, false); + if (!cState) return false; - dispatch(setSel(state, selection)); + view.dispatch({ effects: startCompletionEffect.of(true) }); return true; -} +}; /** -Move the selection to the bracket matching the one it is currently -on, if any. +Close the currently active completion. */ -const cursorMatchingBracket = ({ state, dispatch }) => toMatchingBracket(state, dispatch); -function extendSel(view, how) { - let selection = updateSel(view.state.selection, range => { - let head = how(range); - return EditorSelection.range(range.anchor, head.head, head.goalColumn, head.bidiLevel || undefined); - }); - if (selection.eq(view.state.selection)) +const closeCompletion = (view) => { + let cState = view.state.field(completionState, false); + if (!cState || !cState.active.some(a => a.state != 0 /* State.Inactive */)) return false; - view.dispatch(setSel(view.state, selection)); + view.dispatch({ effects: closeCompletionEffect.of(null) }); return true; +}; +class RunningQuery { + constructor(active, context) { + this.active = active; + this.context = context; + this.time = Date.now(); + this.updates = []; + // Note that 'undefined' means 'not done yet', whereas 'null' means + // 'query returned null'. + this.done = undefined; + } } -function selectByChar(view, forward) { - return extendSel(view, range => view.moveByChar(range, forward)); -} -/** -Move the selection head one character to the left, while leaving -the anchor in place. -*/ -const selectCharLeft = view => selectByChar(view, !ltrAtCursor(view)); -/** -Move the selection head one character to the right. -*/ -const selectCharRight = view => selectByChar(view, ltrAtCursor(view)); -function selectByGroup(view, forward) { - return extendSel(view, range => view.moveByGroup(range, forward)); -} -/** -Move the selection head one [group](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) to -the left. -*/ -const selectGroupLeft = view => selectByGroup(view, !ltrAtCursor(view)); -/** -Move the selection head one group to the right. -*/ -const selectGroupRight = view => selectByGroup(view, ltrAtCursor(view)); -/** -Move the selection head over the next syntactic element to the left. -*/ -const selectSyntaxLeft = view => extendSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view))); -/** -Move the selection head over the next syntactic element to the right. -*/ -const selectSyntaxRight = view => extendSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view))); -function selectByLine(view, forward) { - return extendSel(view, range => view.moveVertically(range, forward)); -} -/** -Move the selection head one line up. -*/ -const selectLineUp = view => selectByLine(view, false); -/** -Move the selection head one line down. -*/ -const selectLineDown = view => selectByLine(view, true); -function selectByPage(view, forward) { - return extendSel(view, range => view.moveVertically(range, forward, pageInfo(view).height)); -} -/** -Move the selection head one page up. -*/ -const selectPageUp = view => selectByPage(view, false); -/** -Move the selection head one page down. -*/ -const selectPageDown = view => selectByPage(view, true); -/** -Move the selection head to the next line boundary. -*/ -const selectLineBoundaryForward = view => extendSel(view, range => moveByLineBoundary(view, range, true)); -/** -Move the selection head to the previous line boundary. -*/ -const selectLineBoundaryBackward = view => extendSel(view, range => moveByLineBoundary(view, range, false)); -/** -Move the selection head one line boundary to the left. -*/ -const selectLineBoundaryLeft = view => extendSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view))); -/** -Move the selection head one line boundary to the right. -*/ -const selectLineBoundaryRight = view => extendSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view))); -/** -Move the selection head to the start of the line. -*/ -const selectLineStart = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from)); -/** -Move the selection head to the end of the line. -*/ -const selectLineEnd = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to)); -/** -Move the selection to the start of the document. -*/ -const cursorDocStart = ({ state, dispatch }) => { - dispatch(setSel(state, { anchor: 0 })); - return true; -}; -/** -Move the selection to the end of the document. -*/ -const cursorDocEnd = ({ state, dispatch }) => { - dispatch(setSel(state, { anchor: state.doc.length })); - return true; -}; -/** -Move the selection head to the start of the document. -*/ -const selectDocStart = ({ state, dispatch }) => { - dispatch(setSel(state, { anchor: state.selection.main.anchor, head: 0 })); - return true; -}; -/** -Move the selection head to the end of the document. -*/ -const selectDocEnd = ({ state, dispatch }) => { - dispatch(setSel(state, { anchor: state.selection.main.anchor, head: state.doc.length })); - return true; -}; -/** -Select the entire document. -*/ -const selectAll = ({ state, dispatch }) => { - dispatch(state.update({ selection: { anchor: 0, head: state.doc.length }, userEvent: "select" })); - return true; -}; -/** -Expand the selection to cover entire lines. -*/ -const selectLine = ({ state, dispatch }) => { - let ranges = selectedLineBlocks(state).map(({ from, to }) => EditorSelection.range(from, Math.min(to + 1, state.doc.length))); - dispatch(state.update({ selection: EditorSelection.create(ranges), userEvent: "select" })); - return true; -}; -/** -Select the next syntactic construct that is larger than the -selection. Note that this will only work insofar as the language -[provider](https://codemirror.net/6/docs/ref/#language.language) you use builds up a full -syntax tree. -*/ -const selectParentSyntax = ({ state, dispatch }) => { - let selection = updateSel(state.selection, range => { - var _a; - let stack = syntaxTree(state).resolveStack(range.from, 1); - for (let cur = stack; cur; cur = cur.next) { - let { node } = cur; - if (((node.from < range.from && node.to >= range.to) || - (node.to > range.to && node.from <= range.from)) && - ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent)) - return EditorSelection.range(node.to, node.from); - } - return range; - }); - dispatch(setSel(state, selection)); - return true; -}; -/** -Simplify the current selection. When multiple ranges are selected, -reduce it to its main range. Otherwise, if the selection is -non-empty, convert it to a cursor selection. -*/ -const simplifySelection = ({ state, dispatch }) => { - let cur = state.selection, selection = null; - if (cur.ranges.length > 1) - selection = EditorSelection.create([cur.main]); - else if (!cur.main.empty) - selection = EditorSelection.create([EditorSelection.cursor(cur.main.head)]); - if (!selection) - return false; - dispatch(setSel(state, selection)); - return true; -}; -function deleteBy(target, by) { - if (target.state.readOnly) - return false; - let event = "delete.selection", { state } = target; - let changes = state.changeByRange(range => { - let { from, to } = range; - if (from == to) { - let towards = by(range); - if (towards < from) { - event = "delete.backward"; - towards = skipAtomic(target, towards, false); +const MaxUpdateCount = 50, MinAbortTime = 1000; +const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class { + constructor(view) { + this.view = view; + this.debounceUpdate = -1; + this.running = []; + this.debounceAccept = -1; + this.pendingStart = false; + this.composing = 0 /* CompositionState.None */; + for (let active of view.state.field(completionState).active) + if (active.state == 1 /* State.Pending */) + this.startQuery(active); + } + update(update) { + let cState = update.state.field(completionState); + let conf = update.state.facet(completionConfig); + if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState) + return; + let doesReset = update.transactions.some(tr => { + return (tr.selection || tr.docChanged) && !getUserEvent(tr, conf); + }); + for (let i = 0; i < this.running.length; i++) { + let query = this.running[i]; + if (doesReset || + query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) { + for (let handler of query.context.abortListeners) { + try { + handler(); + } + catch (e) { + logException(this.view.state, e); + } + } + query.context.abortListeners = null; + this.running.splice(i--, 1); } - else if (towards > from) { - event = "delete.forward"; - towards = skipAtomic(target, towards, true); + else { + query.updates.push(...update.transactions); } - from = Math.min(from, towards); - to = Math.max(to, towards); } - else { - from = skipAtomic(target, from, false); - to = skipAtomic(target, to, true); + if (this.debounceUpdate > -1) + clearTimeout(this.debounceUpdate); + if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect)))) + this.pendingStart = true; + let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay; + this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source)) + ? setTimeout(() => this.startUpdate(), delay) : -1; + if (this.composing != 0 /* CompositionState.None */) + for (let tr of update.transactions) { + if (getUserEvent(tr, conf) == "input") + this.composing = 2 /* CompositionState.Changed */; + else if (this.composing == 2 /* CompositionState.Changed */ && tr.selection) + this.composing = 3 /* CompositionState.ChangedAndMoved */; + } + } + startUpdate() { + this.debounceUpdate = -1; + this.pendingStart = false; + let { state } = this.view, cState = state.field(completionState); + for (let active of cState.active) { + if (active.state == 1 /* State.Pending */ && !this.running.some(r => r.active.source == active.source)) + this.startQuery(active); } - return from == to ? { range } : { changes: { from, to }, range: EditorSelection.cursor(from, from < range.head ? -1 : 1) }; - }); - if (changes.changes.empty) - return false; - target.dispatch(state.update(changes, { - scrollIntoView: true, - userEvent: event, - effects: event == "delete.selection" ? EditorView.announce.of(state.phrase("Selection deleted")) : undefined - })); - return true; -} -function skipAtomic(target, pos, forward) { - if (target instanceof EditorView) - for (let ranges of target.state.facet(EditorView.atomicRanges).map(f => f(target))) - ranges.between(pos, pos, (from, to) => { - if (from < pos && to > pos) - pos = forward ? to : from; - }); - return pos; -} -const deleteByChar = (target, forward, byIndentUnit) => deleteBy(target, range => { - let pos = range.from, { state } = target, line = state.doc.lineAt(pos), before, targetPos; - if (byIndentUnit && !forward && pos > line.from && pos < line.from + 200 && - !/[^ \t]/.test(before = line.text.slice(0, pos - line.from))) { - if (before[before.length - 1] == "\t") - return pos - 1; - let col = countColumn(before, state.tabSize), drop = col % getIndentUnit(state) || getIndentUnit(state); - for (let i = 0; i < drop && before[before.length - 1 - i] == " "; i++) - pos--; - targetPos = pos; } - else { - targetPos = findClusterBreak(line.text, pos - line.from, forward, forward) + line.from; - if (targetPos == pos && line.number != (forward ? state.doc.lines : 1)) - targetPos += forward ? 1 : -1; - else if (!forward && /[\ufe00-\ufe0f]/.test(line.text.slice(targetPos - line.from, pos - line.from))) - targetPos = findClusterBreak(line.text, targetPos - line.from, false, false) + line.from; + startQuery(active) { + let { state } = this.view, pos = cur(state); + let context = new CompletionContext(state, pos, active.explicitPos == pos); + let pending = new RunningQuery(active, context); + this.running.push(pending); + Promise.resolve(active.source(context)).then(result => { + if (!pending.context.aborted) { + pending.done = result || null; + this.scheduleAccept(); + } + }, err => { + this.view.dispatch({ effects: closeCompletionEffect.of(null) }); + logException(this.view.state, err); + }); } - return targetPos; -}); -/** -Delete the selection, or, for cursor selections, the character or -indentation unit before the cursor. -*/ -const deleteCharBackward = view => deleteByChar(view, false, true); -/** -Delete the selection or the character after the cursor. -*/ -const deleteCharForward = view => deleteByChar(view, true, false); -const deleteByGroup = (target, forward) => deleteBy(target, range => { - let pos = range.head, { state } = target, line = state.doc.lineAt(pos); - let categorize = state.charCategorizer(pos); - for (let cat = null;;) { - if (pos == (forward ? line.to : line.from)) { - if (pos == range.head && line.number != (forward ? state.doc.lines : 1)) - pos += forward ? 1 : -1; - break; - } - let next = findClusterBreak(line.text, pos - line.from, forward) + line.from; - let nextChar = line.text.slice(Math.min(pos, next) - line.from, Math.max(pos, next) - line.from); - let nextCat = categorize(nextChar); - if (cat != null && nextCat != cat) - break; - if (nextChar != " " || pos != range.head) - cat = nextCat; - pos = next; + scheduleAccept() { + if (this.running.every(q => q.done !== undefined)) + this.accept(); + else if (this.debounceAccept < 0) + this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(completionConfig).updateSyncTime); } - return pos; -}); -/** -Delete the selection or backward until the end of the next -[group](https://codemirror.net/6/docs/ref/#view.EditorView.moveByGroup), only skipping groups of -whitespace when they consist of a single space. -*/ -const deleteGroupBackward = target => deleteByGroup(target, false); -/** -Delete the selection or forward until the end of the next group. -*/ -const deleteGroupForward = target => deleteByGroup(target, true); -/** -Delete the selection, or, if it is a cursor selection, delete to -the end of the line. If the cursor is directly at the end of the -line, delete the line break after it. -*/ -const deleteToLineEnd = view => deleteBy(view, range => { - let lineEnd = view.lineBlockAt(range.head).to; - return range.head < lineEnd ? lineEnd : Math.min(view.state.doc.length, range.head + 1); -}); -/** -Delete the selection, or, if it is a cursor selection, delete to -the start of the line or the next line wrap before the cursor. -*/ -const deleteLineBoundaryBackward = view => deleteBy(view, range => { - let lineStart = view.moveToLineBoundary(range, false).head; - return range.head > lineStart ? lineStart : Math.max(0, range.head - 1); -}); -/** -Delete the selection, or, if it is a cursor selection, delete to -the end of the line or the next line wrap after the cursor. -*/ -const deleteLineBoundaryForward = view => deleteBy(view, range => { - let lineStart = view.moveToLineBoundary(range, true).head; - return range.head < lineStart ? lineStart : Math.min(view.state.doc.length, range.head + 1); -}); -/** -Replace each selection range with a line break, leaving the cursor -on the line before the break. -*/ -const splitLine = ({ state, dispatch }) => { - if (state.readOnly) - return false; - let changes = state.changeByRange(range => { - return { changes: { from: range.from, to: range.to, insert: Text.of(["", ""]) }, - range: EditorSelection.cursor(range.from) }; - }); - dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" })); - return true; -}; -/** -Flip the characters before and after the cursor(s). -*/ -const transposeChars = ({ state, dispatch }) => { - if (state.readOnly) - return false; - let changes = state.changeByRange(range => { - if (!range.empty || range.from == 0 || range.from == state.doc.length) - return { range }; - let pos = range.from, line = state.doc.lineAt(pos); - let from = pos == line.from ? pos - 1 : findClusterBreak(line.text, pos - line.from, false) + line.from; - let to = pos == line.to ? pos + 1 : findClusterBreak(line.text, pos - line.from, true) + line.from; - return { changes: { from, to, insert: state.doc.slice(pos, to).append(state.doc.slice(from, pos)) }, - range: EditorSelection.cursor(to) }; - }); - if (changes.changes.empty) - return false; - dispatch(state.update(changes, { scrollIntoView: true, userEvent: "move.character" })); - return true; -}; -function selectedLineBlocks(state) { - let blocks = [], upto = -1; - for (let range of state.selection.ranges) { - let startLine = state.doc.lineAt(range.from), endLine = state.doc.lineAt(range.to); - if (!range.empty && range.to == endLine.from) - endLine = state.doc.lineAt(range.to - 1); - if (upto >= startLine.number) { - let prev = blocks[blocks.length - 1]; - prev.to = endLine.to; - prev.ranges.push(range); - } - else { - blocks.push({ from: startLine.from, to: endLine.to, ranges: [range] }); + // For each finished query in this.running, try to create a result + // or, if appropriate, restart the query. + accept() { + var _a; + if (this.debounceAccept > -1) + clearTimeout(this.debounceAccept); + this.debounceAccept = -1; + let updated = []; + let conf = this.view.state.facet(completionConfig); + for (let i = 0; i < this.running.length; i++) { + let query = this.running[i]; + if (query.done === undefined) + continue; + this.running.splice(i--, 1); + if (query.done) { + let active = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : cur(query.updates.length ? query.updates[0].startState : this.view.state)); + // Replay the transactions that happened since the start of + // the request and see if that preserves the result + for (let tr of query.updates) + active = active.update(tr, conf); + if (active.hasResult()) { + updated.push(active); + continue; + } + } + let current = this.view.state.field(completionState).active.find(a => a.source == query.active.source); + if (current && current.state == 1 /* State.Pending */) { + if (query.done == null) { + // Explicitly failed. Should clear the pending status if it + // hasn't been re-set in the meantime. + let active = new ActiveSource(query.active.source, 0 /* State.Inactive */); + for (let tr of query.updates) + active = active.update(tr, conf); + if (active.state != 1 /* State.Pending */) + updated.push(active); + } + else { + // Cleared by subsequent transactions. Restart. + this.startQuery(current); + } + } } - upto = endLine.number + 1; + if (updated.length) + this.view.dispatch({ effects: setActiveEffect.of(updated) }); } - return blocks; -} -function moveLine(state, dispatch, forward) { - if (state.readOnly) - return false; - let changes = [], ranges = []; - for (let block of selectedLineBlocks(state)) { - if (forward ? block.to == state.doc.length : block.from == 0) - continue; - let nextLine = state.doc.lineAt(forward ? block.to + 1 : block.from - 1); - let size = nextLine.length + 1; - if (forward) { - changes.push({ from: block.to, to: nextLine.to }, { from: block.from, insert: nextLine.text + state.lineBreak }); - for (let r of block.ranges) - ranges.push(EditorSelection.range(Math.min(state.doc.length, r.anchor + size), Math.min(state.doc.length, r.head + size))); - } - else { - changes.push({ from: nextLine.from, to: block.from }, { from: block.to, insert: state.lineBreak + nextLine.text }); - for (let r of block.ranges) - ranges.push(EditorSelection.range(r.anchor - size, r.head - size)); +}, { + eventHandlers: { + blur(event) { + let state = this.view.state.field(completionState, false); + if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) { + let dialog = state.open && getTooltip(this.view, state.open.tooltip); + if (!dialog || !dialog.dom.contains(event.relatedTarget)) + setTimeout(() => this.view.dispatch({ effects: closeCompletionEffect.of(null) }), 10); + } + }, + compositionstart() { + this.composing = 1 /* CompositionState.Started */; + }, + compositionend() { + if (this.composing == 3 /* CompositionState.ChangedAndMoved */) { + // Safari fires compositionend events synchronously, possibly + // from inside an update, so dispatch asynchronously to avoid reentrancy + setTimeout(() => this.view.dispatch({ effects: startCompletionEffect.of(false) }), 20); + } + this.composing = 0 /* CompositionState.None */; } } - if (!changes.length) - return false; - dispatch(state.update({ - changes, - scrollIntoView: true, - selection: EditorSelection.create(ranges, state.selection.mainIndex), - userEvent: "move.line" - })); - return true; -} -/** -Move the selected lines up one line. -*/ -const moveLineUp = ({ state, dispatch }) => moveLine(state, dispatch, false); -/** -Move the selected lines down one line. -*/ -const moveLineDown = ({ state, dispatch }) => moveLine(state, dispatch, true); -function copyLine(state, dispatch, forward) { - if (state.readOnly) +}); +const windows = typeof navigator == "object" && /*@__PURE__*//Win/.test(navigator.platform); +const commitCharacters = /*@__PURE__*/Prec.highest(/*@__PURE__*/EditorView.domEventHandlers({ + keydown(event, view) { + let field = view.state.field(completionState, false); + if (!field || !field.open || field.open.disabled || field.open.selected < 0 || + event.key.length > 1 || event.ctrlKey && !(windows && event.altKey) || event.metaKey) + return false; + let option = field.open.options[field.open.selected]; + let result = field.active.find(a => a.source == option.source); + let commitChars = option.completion.commitCharacters || result.result.commitCharacters; + if (commitChars && commitChars.indexOf(event.key) > -1) + applyCompletion(view, option); return false; - let changes = []; - for (let block of selectedLineBlocks(state)) { - if (forward) - changes.push({ from: block.from, insert: state.doc.slice(block.from, block.to) + state.lineBreak }); - else - changes.push({ from: block.to, insert: state.lineBreak + state.doc.slice(block.from, block.to) }); } - dispatch(state.update({ changes, scrollIntoView: true, userEvent: "input.copyline" })); - return true; -} -/** -Create a copy of the selected lines. Keep the selection in the top copy. -*/ -const copyLineUp = ({ state, dispatch }) => copyLine(state, dispatch, false); -/** -Create a copy of the selected lines. Keep the selection in the bottom copy. -*/ -const copyLineDown = ({ state, dispatch }) => copyLine(state, dispatch, true); -/** -Delete selected lines. -*/ -const deleteLine = view => { - if (view.state.readOnly) - return false; - let { state } = view, changes = state.changes(selectedLineBlocks(state).map(({ from, to }) => { - if (from > 0) - from--; - else if (to < state.doc.length) - to++; - return { from, to }; - })); - let selection = updateSel(state.selection, range => { - let dist = undefined; - if (view.lineWrapping) { - let block = view.lineBlockAt(range.head), pos = view.coordsAtPos(range.head, range.assoc || 1); - if (pos) - dist = (block.bottom + view.documentTop) - pos.bottom + view.defaultLineHeight / 2; +})); + +const baseTheme$1 = /*@__PURE__*/EditorView.baseTheme({ + ".cm-tooltip.cm-tooltip-autocomplete": { + "& > ul": { + fontFamily: "monospace", + whiteSpace: "nowrap", + overflow: "hidden auto", + maxWidth_fallback: "700px", + maxWidth: "min(700px, 95vw)", + minWidth: "250px", + maxHeight: "10em", + height: "100%", + listStyle: "none", + margin: 0, + padding: 0, + "& > li, & > completion-section": { + padding: "1px 3px", + lineHeight: 1.2 + }, + "& > li": { + overflowX: "hidden", + textOverflow: "ellipsis", + cursor: "pointer" + }, + "& > completion-section": { + display: "list-item", + borderBottom: "1px solid silver", + paddingLeft: "0.5em", + opacity: 0.7 + } } - return view.moveVertically(range, true, dist); - }).map(changes); - view.dispatch({ changes, selection, scrollIntoView: true, userEvent: "delete.line" }); - return true; -}; -function isBetweenBrackets(state, pos) { - if (/\(\)|\[\]|\{\}/.test(state.sliceDoc(pos - 1, pos + 1))) - return { from: pos, to: pos }; - let context = syntaxTree(state).resolveInner(pos); - let before = context.childBefore(pos), after = context.childAfter(pos), closedBy; - if (before && after && before.to <= pos && after.from >= pos && - (closedBy = before.type.prop(NodeProp.closedBy)) && closedBy.indexOf(after.name) > -1 && - state.doc.lineAt(before.to).from == state.doc.lineAt(after.from).from && - !/\S/.test(state.sliceDoc(before.to, after.from))) - return { from: before.to, to: after.from }; - return null; + }, + "&light .cm-tooltip-autocomplete ul li[aria-selected]": { + background: "#17c", + color: "white", + }, + "&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]": { + background: "#777", + }, + "&dark .cm-tooltip-autocomplete ul li[aria-selected]": { + background: "#347", + color: "white", + }, + "&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]": { + background: "#444", + }, + ".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": { + content: '"···"', + opacity: 0.5, + display: "block", + textAlign: "center" + }, + ".cm-tooltip.cm-completionInfo": { + position: "absolute", + padding: "3px 9px", + width: "max-content", + maxWidth: `${400 /* Info.Width */}px`, + boxSizing: "border-box" + }, + ".cm-completionInfo.cm-completionInfo-left": { right: "100%" }, + ".cm-completionInfo.cm-completionInfo-right": { left: "100%" }, + ".cm-completionInfo.cm-completionInfo-left-narrow": { right: `${30 /* Info.Margin */}px` }, + ".cm-completionInfo.cm-completionInfo-right-narrow": { left: `${30 /* Info.Margin */}px` }, + "&light .cm-snippetField": { backgroundColor: "#00000022" }, + "&dark .cm-snippetField": { backgroundColor: "#ffffff22" }, + ".cm-snippetFieldPosition": { + verticalAlign: "text-top", + width: 0, + height: "1.15em", + display: "inline-block", + margin: "0 -0.7px -.7em", + borderLeft: "1.4px dotted #888" + }, + ".cm-completionMatchedText": { + textDecoration: "underline" + }, + ".cm-completionDetail": { + marginLeft: "0.5em", + fontStyle: "italic" + }, + ".cm-completionIcon": { + fontSize: "90%", + width: ".8em", + display: "inline-block", + textAlign: "center", + paddingRight: ".6em", + opacity: "0.6", + boxSizing: "content-box" + }, + ".cm-completionIcon-function, .cm-completionIcon-method": { + "&:after": { content: "'ƒ'" } + }, + ".cm-completionIcon-class": { + "&:after": { content: "'○'" } + }, + ".cm-completionIcon-interface": { + "&:after": { content: "'◌'" } + }, + ".cm-completionIcon-variable": { + "&:after": { content: "'𝑥'" } + }, + ".cm-completionIcon-constant": { + "&:after": { content: "'𝐶'" } + }, + ".cm-completionIcon-type": { + "&:after": { content: "'𝑡'" } + }, + ".cm-completionIcon-enum": { + "&:after": { content: "'∪'" } + }, + ".cm-completionIcon-property": { + "&:after": { content: "'□'" } + }, + ".cm-completionIcon-keyword": { + "&:after": { content: "'🔑\uFE0E'" } // Disable emoji rendering + }, + ".cm-completionIcon-namespace": { + "&:after": { content: "'▢'" } + }, + ".cm-completionIcon-text": { + "&:after": { content: "'abc'", fontSize: "50%", verticalAlign: "middle" } + } +}); + +class FieldPos { + constructor(field, line, from, to) { + this.field = field; + this.line = line; + this.from = from; + this.to = to; + } } -/** -Replace the selection with a newline and indent the newly created -line(s). If the current line consists only of whitespace, this -will also delete that whitespace. When the cursor is between -matching brackets, an additional newline will be inserted after -the cursor. -*/ -const insertNewlineAndIndent = /*@__PURE__*/newlineAndIndent(false); -/** -Create a blank, indented line below the current line. -*/ -const insertBlankLine = /*@__PURE__*/newlineAndIndent(true); -function newlineAndIndent(atEof) { - return ({ state, dispatch }) => { - if (state.readOnly) - return false; - let changes = state.changeByRange(range => { - let { from, to } = range, line = state.doc.lineAt(from); - let explode = !atEof && from == to && isBetweenBrackets(state, from); - if (atEof) - from = to = (to <= line.to ? line : state.doc.lineAt(to)).to; - let cx = new IndentContext(state, { simulateBreak: from, simulateDoubleBreak: !!explode }); - let indent = getIndentation(cx, from); - if (indent == null) - indent = countColumn(/^\s*/.exec(state.doc.lineAt(from).text)[0], state.tabSize); - while (to < line.to && /\s/.test(line.text[to - line.from])) - to++; - if (explode) - ({ from, to } = explode); - else if (from > line.from && from < line.from + 100 && !/\S/.test(line.text.slice(0, from))) - from = line.from; - let insert = ["", indentString(state, indent)]; - if (explode) - insert.push(indentString(state, cx.lineIndent(line.from, -1))); - return { changes: { from, to, insert: Text.of(insert) }, - range: EditorSelection.cursor(from + 1 + insert[1].length) }; - }); - dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" })); - return true; - }; +class FieldRange { + constructor(field, from, to) { + this.field = field; + this.from = from; + this.to = to; + } + map(changes) { + let from = changes.mapPos(this.from, -1, MapMode.TrackDel); + let to = changes.mapPos(this.to, 1, MapMode.TrackDel); + return from == null || to == null ? null : new FieldRange(this.field, from, to); + } } -function changeBySelectedLine(state, f) { - let atLine = -1; - return state.changeByRange(range => { - let changes = []; - for (let pos = range.from; pos <= range.to;) { - let line = state.doc.lineAt(pos); - if (line.number > atLine && (range.empty || range.to > line.from)) { - f(line, changes, range); - atLine = line.number; +class Snippet { + constructor(lines, fieldPositions) { + this.lines = lines; + this.fieldPositions = fieldPositions; + } + instantiate(state, pos) { + let text = [], lineStart = [pos]; + let lineObj = state.doc.lineAt(pos), baseIndent = /^\s*/.exec(lineObj.text)[0]; + for (let line of this.lines) { + if (text.length) { + let indent = baseIndent, tabs = /^\t*/.exec(line)[0].length; + for (let i = 0; i < tabs; i++) + indent += state.facet(indentUnit); + lineStart.push(pos + indent.length - tabs); + line = indent + line.slice(tabs); } - pos = line.to + 1; + text.push(line); + pos += line.length + 1; } - let changeSet = state.changes(changes); - return { changes, - range: EditorSelection.range(changeSet.mapPos(range.anchor, 1), changeSet.mapPos(range.head, 1)) }; - }); + let ranges = this.fieldPositions.map(pos => new FieldRange(pos.field, lineStart[pos.line] + pos.from, lineStart[pos.line] + pos.to)); + return { text, ranges }; + } + static parse(template) { + let fields = []; + let lines = [], positions = [], m; + for (let line of template.split(/\r\n?|\n/)) { + while (m = /[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(line)) { + let seq = m[1] ? +m[1] : null, rawName = m[2] || m[3] || "", found = -1; + let name = rawName.replace(/\\[{}]/g, m => m[1]); + for (let i = 0; i < fields.length; i++) { + if (seq != null ? fields[i].seq == seq : name ? fields[i].name == name : false) + found = i; + } + if (found < 0) { + let i = 0; + while (i < fields.length && (seq == null || (fields[i].seq != null && fields[i].seq < seq))) + i++; + fields.splice(i, 0, { seq, name }); + found = i; + for (let pos of positions) + if (pos.field >= found) + pos.field++; + } + positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length)); + line = line.slice(0, m.index) + rawName + line.slice(m.index + m[0].length); + } + line = line.replace(/\\([{}])/g, (_, brace, index) => { + for (let pos of positions) + if (pos.line == lines.length && pos.from > index) { + pos.from--; + pos.to--; + } + return brace; + }); + lines.push(line); + } + return new Snippet(lines, positions); + } +} +let fieldMarker = /*@__PURE__*/Decoration.widget({ widget: /*@__PURE__*/new class extends WidgetType { + toDOM() { + let span = document.createElement("span"); + span.className = "cm-snippetFieldPosition"; + return span; + } + ignoreEvent() { return false; } + } }); +let fieldRange = /*@__PURE__*/Decoration.mark({ class: "cm-snippetField" }); +class ActiveSnippet { + constructor(ranges, active) { + this.ranges = ranges; + this.active = active; + this.deco = Decoration.set(ranges.map(r => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to))); + } + map(changes) { + let ranges = []; + for (let r of this.ranges) { + let mapped = r.map(changes); + if (!mapped) + return null; + ranges.push(mapped); + } + return new ActiveSnippet(ranges, this.active); + } + selectionInsideField(sel) { + return sel.ranges.every(range => this.ranges.some(r => r.field == this.active && r.from <= range.from && r.to >= range.to)); + } +} +const setActive = /*@__PURE__*/StateEffect.define({ + map(value, changes) { return value && value.map(changes); } +}); +const moveToField = /*@__PURE__*/StateEffect.define(); +const snippetState = /*@__PURE__*/StateField.define({ + create() { return null; }, + update(value, tr) { + for (let effect of tr.effects) { + if (effect.is(setActive)) + return effect.value; + if (effect.is(moveToField) && value) + return new ActiveSnippet(value.ranges, effect.value); + } + if (value && tr.docChanged) + value = value.map(tr.changes); + if (value && tr.selection && !value.selectionInsideField(tr.selection)) + value = null; + return value; + }, + provide: f => EditorView.decorations.from(f, val => val ? val.deco : Decoration.none) +}); +function fieldSelection(ranges, field) { + return EditorSelection.create(ranges.filter(r => r.field == field).map(r => EditorSelection.range(r.from, r.to))); } /** -Auto-indent the selected lines. This uses the [indentation service -facet](https://codemirror.net/6/docs/ref/#language.indentService) as source for auto-indent -information. +Convert a snippet template to a function that can +[apply](https://codemirror.net/6/docs/ref/#autocomplete.Completion.apply) it. Snippets are written +using syntax like this: + + "for (let ${index} = 0; ${index} < ${end}; ${index}++) {\n\t${}\n}" + +Each `${}` placeholder (you may also use `#{}`) indicates a field +that the user can fill in. Its name, if any, will be the default +content for the field. + +When the snippet is activated by calling the returned function, +the code is inserted at the given position. Newlines in the +template are indented by the indentation of the start line, plus +one [indent unit](https://codemirror.net/6/docs/ref/#language.indentUnit) per tab character after +the newline. + +On activation, (all instances of) the first field are selected. +The user can move between fields with Tab and Shift-Tab as long as +the fields are active. Moving to the last field or moving the +cursor out of the current field deactivates the fields. + +The order of fields defaults to textual order, but you can add +numbers to placeholders (`${1}` or `${1:defaultText}`) to provide +a custom order. + +To include a literal `{` or `}` in your template, put a backslash +in front of it. This will be removed and the brace will not be +interpreted as indicating a placeholder. */ -const indentSelection = ({ state, dispatch }) => { - if (state.readOnly) - return false; - let updated = Object.create(null); - let context = new IndentContext(state, { overrideIndentation: start => { - let found = updated[start]; - return found == null ? -1 : found; - } }); - let changes = changeBySelectedLine(state, (line, changes, range) => { - let indent = getIndentation(context, line.from); - if (indent == null) - return; - if (!/\S/.test(line.text)) - indent = 0; - let cur = /^\s*/.exec(line.text)[0]; - let norm = indentString(state, indent); - if (cur != norm || range.from < line.from + cur.length) { - updated[line.from] = indent; - changes.push({ from: line.from, to: line.from + cur.length, insert: norm }); +function snippet(template) { + let snippet = Snippet.parse(template); + return (editor, completion, from, to) => { + let { text, ranges } = snippet.instantiate(editor.state, from); + let spec = { + changes: { from, to, insert: Text.of(text) }, + scrollIntoView: true, + annotations: completion ? [pickedCompletion.of(completion), Transaction.userEvent.of("input.complete")] : undefined + }; + if (ranges.length) + spec.selection = fieldSelection(ranges, 0); + if (ranges.some(r => r.field > 0)) { + let active = new ActiveSnippet(ranges, 0); + let effects = spec.effects = [setActive.of(active)]; + if (editor.state.field(snippetState, false) === undefined) + effects.push(StateEffect.appendConfig.of([snippetState, addSnippetKeymap, snippetPointerHandler, baseTheme$1])); } - }); - if (!changes.changes.empty) - dispatch(state.update(changes, { userEvent: "indent" })); - return true; -}; + editor.dispatch(editor.state.update(spec)); + }; +} +function moveField(dir) { + return ({ state, dispatch }) => { + let active = state.field(snippetState, false); + if (!active || dir < 0 && active.active == 0) + return false; + let next = active.active + dir, last = dir > 0 && !active.ranges.some(r => r.field == next + dir); + dispatch(state.update({ + selection: fieldSelection(active.ranges, next), + effects: setActive.of(last ? null : new ActiveSnippet(active.ranges, next)), + scrollIntoView: true + })); + return true; + }; +} /** -Add a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation to all selected -lines. +A command that clears the active snippet, if any. */ -const indentMore = ({ state, dispatch }) => { - if (state.readOnly) +const clearSnippet = ({ state, dispatch }) => { + let active = state.field(snippetState, false); + if (!active) return false; - dispatch(state.update(changeBySelectedLine(state, (line, changes) => { - changes.push({ from: line.from, insert: state.facet(indentUnit) }); - }), { userEvent: "input.indent" })); + dispatch(state.update({ effects: setActive.of(null) })); return true; }; /** -Remove a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation from all -selected lines. +Move to the next snippet field, if available. */ -const indentLess = ({ state, dispatch }) => { - if (state.readOnly) - return false; - dispatch(state.update(changeBySelectedLine(state, (line, changes) => { - let space = /^\s*/.exec(line.text)[0]; - if (!space) - return; - let col = countColumn(space, state.tabSize), keep = 0; - let insert = indentString(state, Math.max(0, col - getIndentUnit(state))); - while (keep < space.length && keep < insert.length && space.charCodeAt(keep) == insert.charCodeAt(keep)) - keep++; - changes.push({ from: line.from + keep, to: line.from + space.length, insert: insert.slice(keep) }); - }), { userEvent: "delete.dedent" })); - return true; -}; +const nextSnippetField = /*@__PURE__*/moveField(1); /** -Enables or disables -[tab-focus mode](https://codemirror.net/6/docs/ref/#view.EditorView.setTabFocusMode). While on, this -prevents the editor's key bindings from capturing Tab or -Shift-Tab, making it possible for the user to move focus out of -the editor with the keyboard. +Move to the previous snippet field, if available. */ -const toggleTabFocusMode = view => { - view.setTabFocusMode(); - return true; -}; +const prevSnippetField = /*@__PURE__*/moveField(-1); +const defaultSnippetKeymap = [ + { key: "Tab", run: nextSnippetField, shift: prevSnippetField }, + { key: "Escape", run: clearSnippet } +]; /** -Array of key bindings containing the Emacs-style bindings that are -available on macOS by default. - - - Ctrl-b: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift) - - Ctrl-f: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift) - - Ctrl-p: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift) - - Ctrl-n: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift) - - Ctrl-a: [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift) - - Ctrl-e: [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift) - - Ctrl-d: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward) - - Ctrl-h: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward) - - Ctrl-k: [`deleteToLineEnd`](https://codemirror.net/6/docs/ref/#commands.deleteToLineEnd) - - Ctrl-Alt-h: [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward) - - Ctrl-o: [`splitLine`](https://codemirror.net/6/docs/ref/#commands.splitLine) - - Ctrl-t: [`transposeChars`](https://codemirror.net/6/docs/ref/#commands.transposeChars) - - Ctrl-v: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) - - Alt-v: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) +A facet that can be used to configure the key bindings used by +snippets. The default binds Tab to +[`nextSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.nextSnippetField), Shift-Tab to +[`prevSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.prevSnippetField), and Escape +to [`clearSnippet`](https://codemirror.net/6/docs/ref/#autocomplete.clearSnippet). */ -const emacsStyleKeymap = [ - { key: "Ctrl-b", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true }, - { key: "Ctrl-f", run: cursorCharRight, shift: selectCharRight }, - { key: "Ctrl-p", run: cursorLineUp, shift: selectLineUp }, - { key: "Ctrl-n", run: cursorLineDown, shift: selectLineDown }, - { key: "Ctrl-a", run: cursorLineStart, shift: selectLineStart }, - { key: "Ctrl-e", run: cursorLineEnd, shift: selectLineEnd }, - { key: "Ctrl-d", run: deleteCharForward }, - { key: "Ctrl-h", run: deleteCharBackward }, - { key: "Ctrl-k", run: deleteToLineEnd }, - { key: "Ctrl-Alt-h", run: deleteGroupBackward }, - { key: "Ctrl-o", run: splitLine }, - { key: "Ctrl-t", run: transposeChars }, - { key: "Ctrl-v", run: cursorPageDown }, -]; -/** -An array of key bindings closely sticking to platform-standard or -widely used bindings. (This includes the bindings from -[`emacsStyleKeymap`](https://codemirror.net/6/docs/ref/#commands.emacsStyleKeymap), with their `key` -property changed to `mac`.) - - - ArrowLeft: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift) - - ArrowRight: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift) - - Ctrl-ArrowLeft (Alt-ArrowLeft on macOS): [`cursorGroupLeft`](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) ([`selectGroupLeft`](https://codemirror.net/6/docs/ref/#commands.selectGroupLeft) with Shift) - - Ctrl-ArrowRight (Alt-ArrowRight on macOS): [`cursorGroupRight`](https://codemirror.net/6/docs/ref/#commands.cursorGroupRight) ([`selectGroupRight`](https://codemirror.net/6/docs/ref/#commands.selectGroupRight) with Shift) - - Cmd-ArrowLeft (on macOS): [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift) - - Cmd-ArrowRight (on macOS): [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift) - - ArrowUp: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift) - - ArrowDown: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift) - - Cmd-ArrowUp (on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift) - - Cmd-ArrowDown (on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift) - - Ctrl-ArrowUp (on macOS): [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift) - - Ctrl-ArrowDown (on macOS): [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift) - - PageUp: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift) - - PageDown: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift) - - Home: [`cursorLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryBackward) ([`selectLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryBackward) with Shift) - - End: [`cursorLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryForward) ([`selectLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryForward) with Shift) - - Ctrl-Home (Cmd-Home on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift) - - Ctrl-End (Cmd-Home on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift) - - Enter: [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent) - - Ctrl-a (Cmd-a on macOS): [`selectAll`](https://codemirror.net/6/docs/ref/#commands.selectAll) - - Backspace: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward) - - Delete: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward) - - Ctrl-Backspace (Alt-Backspace on macOS): [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward) - - Ctrl-Delete (Alt-Delete on macOS): [`deleteGroupForward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupForward) - - Cmd-Backspace (macOS): [`deleteLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.deleteLineBoundaryBackward). - - Cmd-Delete (macOS): [`deleteLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.deleteLineBoundaryForward). -*/ -const standardKeymap = /*@__PURE__*/[ - { key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true }, - { key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft, preventDefault: true }, - { mac: "Cmd-ArrowLeft", run: cursorLineBoundaryLeft, shift: selectLineBoundaryLeft, preventDefault: true }, - { key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true }, - { key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight, preventDefault: true }, - { mac: "Cmd-ArrowRight", run: cursorLineBoundaryRight, shift: selectLineBoundaryRight, preventDefault: true }, - { key: "ArrowUp", run: cursorLineUp, shift: selectLineUp, preventDefault: true }, - { mac: "Cmd-ArrowUp", run: cursorDocStart, shift: selectDocStart }, - { mac: "Ctrl-ArrowUp", run: cursorPageUp, shift: selectPageUp }, - { key: "ArrowDown", run: cursorLineDown, shift: selectLineDown, preventDefault: true }, - { mac: "Cmd-ArrowDown", run: cursorDocEnd, shift: selectDocEnd }, - { mac: "Ctrl-ArrowDown", run: cursorPageDown, shift: selectPageDown }, - { key: "PageUp", run: cursorPageUp, shift: selectPageUp }, - { key: "PageDown", run: cursorPageDown, shift: selectPageDown }, - { key: "Home", run: cursorLineBoundaryBackward, shift: selectLineBoundaryBackward, preventDefault: true }, - { key: "Mod-Home", run: cursorDocStart, shift: selectDocStart }, - { key: "End", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward, preventDefault: true }, - { key: "Mod-End", run: cursorDocEnd, shift: selectDocEnd }, - { key: "Enter", run: insertNewlineAndIndent }, - { key: "Mod-a", run: selectAll }, - { key: "Backspace", run: deleteCharBackward, shift: deleteCharBackward }, - { key: "Delete", run: deleteCharForward }, - { key: "Mod-Backspace", mac: "Alt-Backspace", run: deleteGroupBackward }, - { key: "Mod-Delete", mac: "Alt-Delete", run: deleteGroupForward }, - { mac: "Mod-Backspace", run: deleteLineBoundaryBackward }, - { mac: "Mod-Delete", run: deleteLineBoundaryForward } -].concat(/*@__PURE__*/emacsStyleKeymap.map(b => ({ mac: b.key, run: b.run, shift: b.shift }))); +const snippetKeymap = /*@__PURE__*/Facet.define({ + combine(maps) { return maps.length ? maps[0] : defaultSnippetKeymap; } +}); +const addSnippetKeymap = /*@__PURE__*/Prec.highest(/*@__PURE__*/keymap.compute([snippetKeymap], state => state.facet(snippetKeymap))); /** -The default keymap. Includes all bindings from -[`standardKeymap`](https://codemirror.net/6/docs/ref/#commands.standardKeymap) plus the following: - -- Alt-ArrowLeft (Ctrl-ArrowLeft on macOS): [`cursorSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxLeft) ([`selectSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxLeft) with Shift) -- Alt-ArrowRight (Ctrl-ArrowRight on macOS): [`cursorSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxRight) ([`selectSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxRight) with Shift) -- Alt-ArrowUp: [`moveLineUp`](https://codemirror.net/6/docs/ref/#commands.moveLineUp) -- Alt-ArrowDown: [`moveLineDown`](https://codemirror.net/6/docs/ref/#commands.moveLineDown) -- Shift-Alt-ArrowUp: [`copyLineUp`](https://codemirror.net/6/docs/ref/#commands.copyLineUp) -- Shift-Alt-ArrowDown: [`copyLineDown`](https://codemirror.net/6/docs/ref/#commands.copyLineDown) -- Escape: [`simplifySelection`](https://codemirror.net/6/docs/ref/#commands.simplifySelection) -- Ctrl-Enter (Cmd-Enter on macOS): [`insertBlankLine`](https://codemirror.net/6/docs/ref/#commands.insertBlankLine) -- Alt-l (Ctrl-l on macOS): [`selectLine`](https://codemirror.net/6/docs/ref/#commands.selectLine) -- Ctrl-i (Cmd-i on macOS): [`selectParentSyntax`](https://codemirror.net/6/docs/ref/#commands.selectParentSyntax) -- Ctrl-[ (Cmd-[ on macOS): [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess) -- Ctrl-] (Cmd-] on macOS): [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore) -- Ctrl-Alt-\\ (Cmd-Alt-\\ on macOS): [`indentSelection`](https://codemirror.net/6/docs/ref/#commands.indentSelection) -- Shift-Ctrl-k (Shift-Cmd-k on macOS): [`deleteLine`](https://codemirror.net/6/docs/ref/#commands.deleteLine) -- Shift-Ctrl-\\ (Shift-Cmd-\\ on macOS): [`cursorMatchingBracket`](https://codemirror.net/6/docs/ref/#commands.cursorMatchingBracket) -- Ctrl-/ (Cmd-/ on macOS): [`toggleComment`](https://codemirror.net/6/docs/ref/#commands.toggleComment). -- Shift-Alt-a: [`toggleBlockComment`](https://codemirror.net/6/docs/ref/#commands.toggleBlockComment). -- Ctrl-m (Alt-Shift-m on macOS): [`toggleTabFocusMode`](https://codemirror.net/6/docs/ref/#commands.toggleTabFocusMode). +Create a completion from a snippet. Returns an object with the +properties from `completion`, plus an `apply` function that +applies the snippet. */ -const defaultKeymap = /*@__PURE__*/[ - { key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: cursorSyntaxLeft, shift: selectSyntaxLeft }, - { key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: cursorSyntaxRight, shift: selectSyntaxRight }, - { key: "Alt-ArrowUp", run: moveLineUp }, - { key: "Shift-Alt-ArrowUp", run: copyLineUp }, - { key: "Alt-ArrowDown", run: moveLineDown }, - { key: "Shift-Alt-ArrowDown", run: copyLineDown }, - { key: "Escape", run: simplifySelection }, - { key: "Mod-Enter", run: insertBlankLine }, - { key: "Alt-l", mac: "Ctrl-l", run: selectLine }, - { key: "Mod-i", run: selectParentSyntax, preventDefault: true }, - { key: "Mod-[", run: indentLess }, - { key: "Mod-]", run: indentMore }, - { key: "Mod-Alt-\\", run: indentSelection }, - { key: "Shift-Mod-k", run: deleteLine }, - { key: "Shift-Mod-\\", run: cursorMatchingBracket }, - { key: "Mod-/", run: toggleComment }, - { key: "Alt-A", run: toggleBlockComment }, - { key: "Ctrl-m", mac: "Shift-Alt-m", run: toggleTabFocusMode }, -].concat(standardKeymap); +function snippetCompletion(template, completion) { + return Object.assign(Object.assign({}, completion), { apply: snippet(template) }); +} +const snippetPointerHandler = /*@__PURE__*/EditorView.domEventHandlers({ + mousedown(event, view) { + let active = view.state.field(snippetState, false), pos; + if (!active || (pos = view.posAtCoords({ x: event.clientX, y: event.clientY })) == null) + return false; + let match = active.ranges.find(r => r.from <= pos && r.to >= pos); + if (!match || match.field == active.active) + return false; + view.dispatch({ + selection: fieldSelection(active.ranges, match.field), + effects: setActive.of(active.ranges.some(r => r.field > match.field) + ? new ActiveSnippet(active.ranges, match.field) : null), + scrollIntoView: true + }); + return true; + } +}); -function crelt() { - var elt = arguments[0]; - if (typeof elt == "string") elt = document.createElement(elt); - var i = 1, next = arguments[1]; - if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) { - for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) { - var value = next[name]; - if (typeof value == "string") elt.setAttribute(name, value); - else if (value != null) elt[name] = value; +const defaults = { + brackets: ["(", "[", "{", "'", '"'], + before: ")]}:;>", + stringPrefixes: [] +}; +const closeBracketEffect = /*@__PURE__*/StateEffect.define({ + map(value, mapping) { + let mapped = mapping.mapPos(value, -1, MapMode.TrackAfter); + return mapped == null ? undefined : mapped; } - i++; - } - for (; i < arguments.length; i++) add(elt, arguments[i]); - return elt +}); +const closedBracket = /*@__PURE__*/new class extends RangeValue { +}; +closedBracket.startSide = 1; +closedBracket.endSide = -1; +const bracketState = /*@__PURE__*/StateField.define({ + create() { return RangeSet.empty; }, + update(value, tr) { + value = value.map(tr.changes); + if (tr.selection) { + let line = tr.state.doc.lineAt(tr.selection.main.head); + value = value.update({ filter: from => from >= line.from && from <= line.to }); + } + for (let effect of tr.effects) + if (effect.is(closeBracketEffect)) + value = value.update({ add: [closedBracket.range(effect.value, effect.value + 1)] }); + return value; + } +}); +/** +Extension to enable bracket-closing behavior. When a closeable +bracket is typed, its closing bracket is immediately inserted +after the cursor. When closing a bracket directly in front of a +closing bracket inserted by the extension, the cursor moves over +that bracket. +*/ +function closeBrackets() { + return [inputHandler, bracketState]; } - -function add(elt, child) { - if (typeof child == "string") { - elt.appendChild(document.createTextNode(child)); - } else if (child == null) ; else if (child.nodeType != null) { - elt.appendChild(child); - } else if (Array.isArray(child)) { - for (var i = 0; i < child.length; i++) add(elt, child[i]); - } else { - throw new RangeError("Unsupported child node: " + child) - } +const definedClosing = "()[]{}<>"; +function closing(ch) { + for (let i = 0; i < definedClosing.length; i += 2) + if (definedClosing.charCodeAt(i) == ch) + return definedClosing.charAt(i + 1); + return fromCodePoint(ch < 128 ? ch : ch + 1); } - -const basicNormalize = typeof String.prototype.normalize == "function" - ? x => x.normalize("NFKD") : x => x; +function config(state, pos) { + return state.languageDataAt("closeBrackets", pos)[0] || defaults; +} +const android$1 = typeof navigator == "object" && /*@__PURE__*//Android\b/.test(navigator.userAgent); +const inputHandler = /*@__PURE__*/EditorView.inputHandler.of((view, from, to, insert) => { + if ((android$1 ? view.composing : view.compositionStarted) || view.state.readOnly) + return false; + let sel = view.state.selection.main; + if (insert.length > 2 || insert.length == 2 && codePointSize(codePointAt(insert, 0)) == 1 || + from != sel.from || to != sel.to) + return false; + let tr = insertBracket(view.state, insert); + if (!tr) + return false; + view.dispatch(tr); + return true; +}); /** -A search cursor provides an iterator over text matches in a -document. +Command that implements deleting a pair of matching brackets when +the cursor is between them. */ -class SearchCursor { - /** - Create a text cursor. The query is the search string, `from` to - `to` provides the region to search. - - When `normalize` is given, it will be called, on both the query - string and the content it is matched against, before comparing. - You can, for example, create a case-insensitive search by - passing `s => s.toLowerCase()`. - - Text is always normalized with - [`.normalize("NFKD")`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize) - (when supported). - */ - constructor(text, query, from = 0, to = text.length, normalize, test) { - this.test = test; - /** - The current match (only holds a meaningful value after - [`next`](https://codemirror.net/6/docs/ref/#search.SearchCursor.next) has been called and when - `done` is false). - */ - this.value = { from: 0, to: 0 }; - /** - Whether the end of the iterated region has been reached. - */ - this.done = false; - this.matches = []; - this.buffer = ""; - this.bufferPos = 0; - this.iter = text.iterRange(from, to); - this.bufferStart = from; - this.normalize = normalize ? x => normalize(basicNormalize(x)) : basicNormalize; - this.query = this.normalize(query); - } - peek() { - if (this.bufferPos == this.buffer.length) { - this.bufferStart += this.buffer.length; - this.iter.next(); - if (this.iter.done) - return -1; - this.bufferPos = 0; - this.buffer = this.iter.value; - } - return codePointAt(this.buffer, this.bufferPos); - } - /** - Look for the next match. Updates the iterator's - [`value`](https://codemirror.net/6/docs/ref/#search.SearchCursor.value) and - [`done`](https://codemirror.net/6/docs/ref/#search.SearchCursor.done) properties. Should be called - at least once before using the cursor. - */ - next() { - while (this.matches.length) - this.matches.pop(); - return this.nextOverlapping(); - } - /** - The `next` method will ignore matches that partially overlap a - previous match. This method behaves like `next`, but includes - such matches. - */ - nextOverlapping() { - for (;;) { - let next = this.peek(); - if (next < 0) { - this.done = true; - return this; - } - let str = fromCodePoint(next), start = this.bufferStart + this.bufferPos; - this.bufferPos += codePointSize(next); - let norm = this.normalize(str); - for (let i = 0, pos = start;; i++) { - let code = norm.charCodeAt(i); - let match = this.match(code, pos, this.bufferPos + this.bufferStart); - if (i == norm.length - 1) { - if (match) { - this.value = match; - return this; - } - break; - } - if (pos == start && i < str.length && str.charCodeAt(i) == code) - pos++; +const deleteBracketPair = ({ state, dispatch }) => { + if (state.readOnly) + return false; + let conf = config(state, state.selection.main.head); + let tokens = conf.brackets || defaults.brackets; + let dont = null, changes = state.changeByRange(range => { + if (range.empty) { + let before = prevChar(state.doc, range.head); + for (let token of tokens) { + if (token == before && nextChar(state.doc, range.head) == closing(codePointAt(token, 0))) + return { changes: { from: range.head - token.length, to: range.head + token.length }, + range: EditorSelection.cursor(range.head - token.length) }; } } + return { range: dont = range }; + }); + if (!dont) + dispatch(state.update(changes, { scrollIntoView: true, userEvent: "delete.backward" })); + return !dont; +}; +/** +Close-brackets related key bindings. Binds Backspace to +[`deleteBracketPair`](https://codemirror.net/6/docs/ref/#autocomplete.deleteBracketPair). +*/ +const closeBracketsKeymap = [ + { key: "Backspace", run: deleteBracketPair } +]; +/** +Implements the extension's behavior on text insertion. If the +given string counts as a bracket in the language around the +selection, and replacing the selection with it requires custom +behavior (inserting a closing version or skipping past a +previously-closed bracket), this function returns a transaction +representing that custom behavior. (You only need this if you want +to programmatically insert brackets—the +[`closeBrackets`](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets) extension will +take care of running this for user input.) +*/ +function insertBracket(state, bracket) { + let conf = config(state, state.selection.main.head); + let tokens = conf.brackets || defaults.brackets; + for (let tok of tokens) { + let closed = closing(codePointAt(tok, 0)); + if (bracket == tok) + return closed == tok ? handleSame(state, tok, tokens.indexOf(tok + tok + tok) > -1, conf) + : handleOpen(state, tok, closed, conf.before || defaults.before); + if (bracket == closed && closedBracketAt(state, state.selection.main.from)) + return handleClose(state, tok, closed); } - match(code, pos, end) { - let match = null; - for (let i = 0; i < this.matches.length; i += 2) { - let index = this.matches[i], keep = false; - if (this.query.charCodeAt(index) == code) { - if (index == this.query.length - 1) { - match = { from: this.matches[i + 1], to: end }; - } - else { - this.matches[i]++; - keep = true; - } + return null; +} +function closedBracketAt(state, pos) { + let found = false; + state.field(bracketState).between(0, state.doc.length, from => { + if (from == pos) + found = true; + }); + return found; +} +function nextChar(doc, pos) { + let next = doc.sliceString(pos, pos + 2); + return next.slice(0, codePointSize(codePointAt(next, 0))); +} +function prevChar(doc, pos) { + let prev = doc.sliceString(pos - 2, pos); + return codePointSize(codePointAt(prev, 0)) == prev.length ? prev : prev.slice(1); +} +function handleOpen(state, open, close, closeBefore) { + let dont = null, changes = state.changeByRange(range => { + if (!range.empty) + return { changes: [{ insert: open, from: range.from }, { insert: close, from: range.to }], + effects: closeBracketEffect.of(range.to + open.length), + range: EditorSelection.range(range.anchor + open.length, range.head + open.length) }; + let next = nextChar(state.doc, range.head); + if (!next || /\s/.test(next) || closeBefore.indexOf(next) > -1) + return { changes: { insert: open + close, from: range.head }, + effects: closeBracketEffect.of(range.head + open.length), + range: EditorSelection.cursor(range.head + open.length) }; + return { range: dont = range }; + }); + return dont ? null : state.update(changes, { + scrollIntoView: true, + userEvent: "input.type" + }); +} +function handleClose(state, _open, close) { + let dont = null, changes = state.changeByRange(range => { + if (range.empty && nextChar(state.doc, range.head) == close) + return { changes: { from: range.head, to: range.head + close.length, insert: close }, + range: EditorSelection.cursor(range.head + close.length) }; + return dont = { range }; + }); + return dont ? null : state.update(changes, { + scrollIntoView: true, + userEvent: "input.type" + }); +} +// Handles cases where the open and close token are the same, and +// possibly triple quotes (as in `"""abc"""`-style quoting). +function handleSame(state, token, allowTriple, config) { + let stringPrefixes = config.stringPrefixes || defaults.stringPrefixes; + let dont = null, changes = state.changeByRange(range => { + if (!range.empty) + return { changes: [{ insert: token, from: range.from }, { insert: token, from: range.to }], + effects: closeBracketEffect.of(range.to + token.length), + range: EditorSelection.range(range.anchor + token.length, range.head + token.length) }; + let pos = range.head, next = nextChar(state.doc, pos), start; + if (next == token) { + if (nodeStart(state, pos)) { + return { changes: { insert: token + token, from: pos }, + effects: closeBracketEffect.of(pos + token.length), + range: EditorSelection.cursor(pos + token.length) }; } - if (!keep) { - this.matches.splice(i, 2); - i -= 2; + else if (closedBracketAt(state, pos)) { + let isTriple = allowTriple && state.sliceDoc(pos, pos + token.length * 3) == token + token + token; + let content = isTriple ? token + token + token : token; + return { changes: { from: pos, to: pos + content.length, insert: content }, + range: EditorSelection.cursor(pos + content.length) }; } } - if (this.query.charCodeAt(0) == code) { - if (this.query.length == 1) - match = { from: pos, to: end }; - else - this.matches.push(1, pos); + else if (allowTriple && state.sliceDoc(pos - 2 * token.length, pos) == token + token && + (start = canStartStringAt(state, pos - 2 * token.length, stringPrefixes)) > -1 && + nodeStart(state, start)) { + return { changes: { insert: token + token + token + token, from: pos }, + effects: closeBracketEffect.of(pos + token.length), + range: EditorSelection.cursor(pos + token.length) }; } - if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferStart)) - match = null; - return match; + else if (state.charCategorizer(pos)(next) != CharCategory.Word) { + if (canStartStringAt(state, pos, stringPrefixes) > -1 && !probablyInString(state, pos, token, stringPrefixes)) + return { changes: { insert: token + token, from: pos }, + effects: closeBracketEffect.of(pos + token.length), + range: EditorSelection.cursor(pos + token.length) }; + } + return { range: dont = range }; + }); + return dont ? null : state.update(changes, { + scrollIntoView: true, + userEvent: "input.type" + }); +} +function nodeStart(state, pos) { + let tree = syntaxTree(state).resolveInner(pos + 1); + return tree.parent && tree.from == pos; +} +function probablyInString(state, pos, quoteToken, prefixes) { + let node = syntaxTree(state).resolveInner(pos, -1); + let maxPrefix = prefixes.reduce((m, p) => Math.max(m, p.length), 0); + for (let i = 0; i < 5; i++) { + let start = state.sliceDoc(node.from, Math.min(node.to, node.from + quoteToken.length + maxPrefix)); + let quotePos = start.indexOf(quoteToken); + if (!quotePos || quotePos > -1 && prefixes.indexOf(start.slice(0, quotePos)) > -1) { + let first = node.firstChild; + while (first && first.from == node.from && first.to - first.from > quoteToken.length + quotePos) { + if (state.sliceDoc(first.to - quoteToken.length, first.to) == quoteToken) + return false; + first = first.firstChild; + } + return true; + } + let parent = node.to == pos && node.parent; + if (!parent) + break; + node = parent; } + return false; +} +function canStartStringAt(state, pos, prefixes) { + let charCat = state.charCategorizer(pos); + if (charCat(state.sliceDoc(pos - 1, pos)) != CharCategory.Word) + return pos; + for (let prefix of prefixes) { + let start = pos - prefix.length; + if (state.sliceDoc(start, pos) == prefix && charCat(state.sliceDoc(start - 1, start)) != CharCategory.Word) + return start; + } + return -1; } -if (typeof Symbol != "undefined") - SearchCursor.prototype[Symbol.iterator] = function () { return this; }; -const empty = { from: -1, to: -1, match: /*@__PURE__*//.*/.exec("") }; -const baseFlags = "gm" + (/x/.unicode == null ? "" : "u"); /** -This class is similar to [`SearchCursor`](https://codemirror.net/6/docs/ref/#search.SearchCursor) -but searches for a regular expression pattern instead of a plain -string. +Returns an extension that enables autocompletion. */ -class RegExpCursor { - /** - Create a cursor that will search the given range in the given - document. `query` should be the raw pattern (as you'd pass it to - `new RegExp`). - */ - constructor(text, query, options, from = 0, to = text.length) { - this.text = text; - this.to = to; - this.curLine = ""; - /** - Set to `true` when the cursor has reached the end of the search - range. - */ - this.done = false; - /** - Will contain an object with the extent of the match and the - match object when [`next`](https://codemirror.net/6/docs/ref/#search.RegExpCursor.next) - sucessfully finds a match. - */ - this.value = empty; - if (/\\[sWDnr]|\n|\r|\[\^/.test(query)) - return new MultilineRegExpCursor(text, query, options, from, to); - this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : "")); - this.test = options === null || options === void 0 ? void 0 : options.test; - this.iter = text.iter(); - let startLine = text.lineAt(from); - this.curLineStart = startLine.from; - this.matchPos = toCharEnd(text, from); - this.getLine(this.curLineStart); +function autocompletion(config = {}) { + return [ + commitCharacters, + completionState, + completionConfig.of(config), + completionPlugin, + completionKeymapExt, + baseTheme$1 + ]; +} +/** +Basic keybindings for autocompletion. + + - Ctrl-Space: [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion) + - Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion) + - ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)` + - ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)` + - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")` + - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")` + - Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion) +*/ +const completionKeymap = [ + { key: "Ctrl-Space", run: startCompletion }, + { key: "Escape", run: closeCompletion }, + { key: "ArrowDown", run: /*@__PURE__*/moveCompletionSelection(true) }, + { key: "ArrowUp", run: /*@__PURE__*/moveCompletionSelection(false) }, + { key: "PageDown", run: /*@__PURE__*/moveCompletionSelection(true, "page") }, + { key: "PageUp", run: /*@__PURE__*/moveCompletionSelection(false, "page") }, + { key: "Enter", run: acceptCompletion } +]; +const completionKeymapExt = /*@__PURE__*/Prec.highest(/*@__PURE__*/keymap.computeN([completionConfig], state => state.facet(completionConfig).defaultKeymap ? [completionKeymap] : [])); + +/** +A collection of JavaScript-related +[snippets](https://codemirror.net/6/docs/ref/#autocomplete.snippet). +*/ +const snippets = [ + /*@__PURE__*/snippetCompletion("function ${name}(${params}) {\n\t${}\n}", { + label: "function", + detail: "definition", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n\t${}\n}", { + label: "for", + detail: "loop", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("for (let ${name} of ${collection}) {\n\t${}\n}", { + label: "for", + detail: "of loop", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("do {\n\t${}\n} while (${})", { + label: "do", + detail: "loop", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("while (${}) {\n\t${}\n}", { + label: "while", + detail: "loop", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("try {\n\t${}\n} catch (${error}) {\n\t${}\n}", { + label: "try", + detail: "/ catch block", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("if (${}) {\n\t${}\n}", { + label: "if", + detail: "block", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("if (${}) {\n\t${}\n} else {\n\t${}\n}", { + label: "if", + detail: "/ else block", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("class ${name} {\n\tconstructor(${params}) {\n\t\t${}\n\t}\n}", { + label: "class", + detail: "definition", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("import {${names}} from \"${module}\"\n${}", { + label: "import", + detail: "named", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("import ${name} from \"${module}\"\n${}", { + label: "import", + detail: "default", + type: "keyword" + }) +]; +/** +A collection of snippet completions for TypeScript. Includes the +JavaScript [snippets](https://codemirror.net/6/docs/ref/#lang-javascript.snippets). +*/ +const typescriptSnippets = /*@__PURE__*/snippets.concat([ + /*@__PURE__*/snippetCompletion("interface ${name} {\n\t${}\n}", { + label: "interface", + detail: "definition", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("type ${name} = ${type}", { + label: "type", + detail: "definition", + type: "keyword" + }), + /*@__PURE__*/snippetCompletion("enum ${name} {\n\t${}\n}", { + label: "enum", + detail: "definition", + type: "keyword" + }) +]); + +const cache = /*@__PURE__*/new NodeWeakMap(); +const ScopeNodes = /*@__PURE__*/new Set([ + "Script", "Block", + "FunctionExpression", "FunctionDeclaration", "ArrowFunction", "MethodDeclaration", + "ForStatement" +]); +function defID(type) { + return (node, def) => { + let id = node.node.getChild("VariableDefinition"); + if (id) + def(id, type); + return true; + }; +} +const functionContext = ["FunctionDeclaration"]; +const gatherCompletions = { + FunctionDeclaration: /*@__PURE__*/defID("function"), + ClassDeclaration: /*@__PURE__*/defID("class"), + ClassExpression: () => true, + EnumDeclaration: /*@__PURE__*/defID("constant"), + TypeAliasDeclaration: /*@__PURE__*/defID("type"), + NamespaceDeclaration: /*@__PURE__*/defID("namespace"), + VariableDefinition(node, def) { if (!node.matchContext(functionContext)) + def(node, "variable"); }, + TypeDefinition(node, def) { def(node, "type"); }, + __proto__: null +}; +function getScope(doc, node) { + let cached = cache.get(node); + if (cached) + return cached; + let completions = [], top = true; + function def(node, type) { + let name = doc.sliceString(node.from, node.to); + completions.push({ label: name, type }); } - getLine(skip) { - this.iter.next(skip); - if (this.iter.lineBreak) { - this.curLine = ""; + node.cursor(IterMode.IncludeAnonymous).iterate(node => { + if (top) { + top = false; } - else { - this.curLine = this.iter.value; - if (this.curLineStart + this.curLine.length > this.to) - this.curLine = this.curLine.slice(0, this.to - this.curLineStart); - this.iter.next(); + else if (node.name) { + let gather = gatherCompletions[node.name]; + if (gather && gather(node, def) || ScopeNodes.has(node.name)) + return false; } - } - nextLine() { - this.curLineStart = this.curLineStart + this.curLine.length + 1; - if (this.curLineStart > this.to) - this.curLine = ""; - else - this.getLine(0); - } - /** - Move to the next match, if there is one. - */ - next() { - for (let off = this.matchPos - this.curLineStart;;) { - this.re.lastIndex = off; - let match = this.matchPos <= this.to && this.re.exec(this.curLine); - if (match) { - let from = this.curLineStart + match.index, to = from + match[0].length; - this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0)); - if (from == this.curLineStart + this.curLine.length) - this.nextLine(); - if ((from < to || from > this.value.to) && (!this.test || this.test(from, to, match))) { - this.value = { from, to, match }; - return this; - } - off = this.matchPos - this.curLineStart; - } - else if (this.curLineStart + this.curLine.length < this.to) { - this.nextLine(); - off = 0; - } - else { - this.done = true; - return this; - } + else if (node.to - node.from > 8192) { + // Allow caching for bigger internal nodes + for (let c of getScope(doc, node.node)) + completions.push(c); + return false; } - } + }); + cache.set(node, completions); + return completions; } -const flattened = /*@__PURE__*/new WeakMap(); -// Reusable (partially) flattened document strings -class FlattenedDoc { - constructor(from, text) { - this.from = from; - this.text = text; - } - get to() { return this.from + this.text.length; } - static get(doc, from, to) { - let cached = flattened.get(doc); - if (!cached || cached.from >= to || cached.to <= from) { - let flat = new FlattenedDoc(from, doc.sliceString(from, to)); - flattened.set(doc, flat); - return flat; - } - if (cached.from == from && cached.to == to) - return cached; - let { text, from: cachedFrom } = cached; - if (cachedFrom > from) { - text = doc.sliceString(from, cachedFrom) + text; - cachedFrom = from; - } - if (cached.to < to) - text += doc.sliceString(cached.to, to); - flattened.set(doc, new FlattenedDoc(cachedFrom, text)); - return new FlattenedDoc(from, text.slice(from - cachedFrom, to - cachedFrom)); - } -} -class MultilineRegExpCursor { - constructor(text, query, options, from, to) { - this.text = text; - this.to = to; - this.done = false; - this.value = empty; - this.matchPos = toCharEnd(text, from); - this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : "")); - this.test = options === null || options === void 0 ? void 0 : options.test; - this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5000 /* Chunk.Base */)); - } - chunkEnd(pos) { - return pos >= this.to ? this.to : this.text.lineAt(pos).to; - } - next() { - for (;;) { - let off = this.re.lastIndex = this.matchPos - this.flat.from; - let match = this.re.exec(this.flat.text); - // Skip empty matches directly after the last match - if (match && !match[0] && match.index == off) { - this.re.lastIndex = off + 1; - match = this.re.exec(this.flat.text); - } - if (match) { - let from = this.flat.from + match.index, to = from + match[0].length; - // If a match goes almost to the end of a noncomplete chunk, try - // again, since it'll likely be able to match more - if ((this.flat.to >= this.to || match.index + match[0].length <= this.flat.text.length - 10) && - (!this.test || this.test(from, to, match))) { - this.value = { from, to, match }; - this.matchPos = toCharEnd(this.text, to + (from == to ? 1 : 0)); - return this; - } - } - if (this.flat.to == this.to) { - this.done = true; - return this; - } - // Grow the flattened doc - this.flat = FlattenedDoc.get(this.text, this.flat.from, this.chunkEnd(this.flat.from + this.flat.text.length * 2)); - } - } -} -if (typeof Symbol != "undefined") { - RegExpCursor.prototype[Symbol.iterator] = MultilineRegExpCursor.prototype[Symbol.iterator] = - function () { return this; }; -} -function validRegExp(source) { - try { - new RegExp(source, baseFlags); - return true; - } - catch (_a) { - return false; +const Identifier = /^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/; +const dontComplete = [ + "TemplateString", "String", "RegExp", + "LineComment", "BlockComment", + "VariableDefinition", "TypeDefinition", "Label", + "PropertyDefinition", "PropertyName", + "PrivatePropertyDefinition", "PrivatePropertyName", + ".", "?." +]; +/** +Completion source that looks up locally defined names in +JavaScript code. +*/ +function localCompletionSource(context) { + let inner = syntaxTree(context.state).resolveInner(context.pos, -1); + if (dontComplete.indexOf(inner.name) > -1) + return null; + let isWord = inner.name == "VariableName" || + inner.to - inner.from < 20 && Identifier.test(context.state.sliceDoc(inner.from, inner.to)); + if (!isWord && !context.explicit) + return null; + let options = []; + for (let pos = inner; pos; pos = pos.parent) { + if (ScopeNodes.has(pos.name)) + options = options.concat(getScope(context.state.doc, pos)); } -} -function toCharEnd(text, pos) { - if (pos >= text.length) - return pos; - let line = text.lineAt(pos), next; - while (pos < line.to && (next = line.text.charCodeAt(pos - line.from)) >= 0xDC00 && next < 0xE000) - pos++; - return pos; + return { + options, + from: isWord ? inner.from : context.pos, + validFor: Identifier + }; } -function createLineDialog(view) { - let line = String(view.state.doc.lineAt(view.state.selection.main.head).number); - let input = crelt("input", { class: "cm-textfield", name: "line", value: line }); - let dom = crelt("form", { - class: "cm-gotoLine", - onkeydown: (event) => { - if (event.keyCode == 27) { // Escape - event.preventDefault(); - view.dispatch({ effects: dialogEffect.of(false) }); - view.focus(); - } - else if (event.keyCode == 13) { // Enter - event.preventDefault(); - go(); - } - }, - onsubmit: (event) => { - event.preventDefault(); - go(); - } - }, crelt("label", view.state.phrase("Go to line"), ": ", input), " ", crelt("button", { class: "cm-button", type: "submit" }, view.state.phrase("go"))); - function go() { - let match = /^([+-])?(\d+)?(:\d+)?(%)?$/.exec(input.value); - if (!match) - return; - let { state } = view, startLine = state.doc.lineAt(state.selection.main.head); - let [, sign, ln, cl, percent] = match; - let col = cl ? +cl.slice(1) : 0; - let line = ln ? +ln : startLine.number; - if (ln && percent) { - let pc = line / 100; - if (sign) - pc = pc * (sign == "-" ? -1 : 1) + (startLine.number / state.doc.lines); - line = Math.round(state.doc.lines * pc); - } - else if (ln && sign) { - line = line * (sign == "-" ? -1 : 1) + startLine.number; - } - let docLine = state.doc.line(Math.max(1, Math.min(state.doc.lines, line))); - let selection = EditorSelection.cursor(docLine.from + Math.max(0, Math.min(col, docLine.length))); - view.dispatch({ - effects: [dialogEffect.of(false), EditorView.scrollIntoView(selection.from, { y: 'center' })], - selection, - }); - view.focus(); - } - return { dom }; -} -const dialogEffect = /*@__PURE__*/StateEffect.define(); -const dialogField = /*@__PURE__*/StateField.define({ - create() { return true; }, - update(value, tr) { - for (let e of tr.effects) - if (e.is(dialogEffect)) - value = e.value; - return value; - }, - provide: f => showPanel.from(f, val => val ? createLineDialog : null) -}); /** -Command that shows a dialog asking the user for a line number, and -when a valid position is provided, moves the cursor to that line. - -Supports line numbers, relative line offsets prefixed with `+` or -`-`, document percentages suffixed with `%`, and an optional -column position by adding `:` and a second number after the line -number. +A language provider based on the [Lezer JavaScript +parser](https://github.com/lezer-parser/javascript), extended with +highlighting and indentation information. */ -const gotoLine = view => { - let panel = getPanel(view, createLineDialog); - if (!panel) { - let effects = [dialogEffect.of(true)]; - if (view.state.field(dialogField, false) == null) - effects.push(StateEffect.appendConfig.of([dialogField, baseTheme$1])); - view.dispatch({ effects }); - panel = getPanel(view, createLineDialog); - } - if (panel) - panel.dom.querySelector("input").select(); - return true; -}; -const baseTheme$1 = /*@__PURE__*/EditorView.baseTheme({ - ".cm-panel.cm-gotoLine": { - padding: "2px 6px 4px", - "& label": { fontSize: "80%" } +const javascriptLanguage = /*@__PURE__*/LRLanguage.define({ + name: "javascript", + parser: /*@__PURE__*/parser.configure({ + props: [ + /*@__PURE__*/indentNodeProp.add({ + IfStatement: /*@__PURE__*/continuedIndent({ except: /^\s*({|else\b)/ }), + TryStatement: /*@__PURE__*/continuedIndent({ except: /^\s*({|catch\b|finally\b)/ }), + LabeledStatement: flatIndent, + SwitchBody: context => { + let after = context.textAfter, closed = /^\s*\}/.test(after), isCase = /^\s*(case|default)\b/.test(after); + return context.baseIndent + (closed ? 0 : isCase ? 1 : 2) * context.unit; + }, + Block: /*@__PURE__*/delimitedIndent({ closing: "}" }), + ArrowFunction: cx => cx.baseIndent + cx.unit, + "TemplateString BlockComment": () => null, + "Statement Property": /*@__PURE__*/continuedIndent({ except: /^{/ }), + JSXElement(context) { + let closed = /^\s*<\//.test(context.textAfter); + return context.lineIndent(context.node.from) + (closed ? 0 : context.unit); + }, + JSXEscape(context) { + let closed = /\s*\}/.test(context.textAfter); + return context.lineIndent(context.node.from) + (closed ? 0 : context.unit); + }, + "JSXOpenTag JSXSelfClosingTag"(context) { + return context.column(context.node.from) + context.unit; + } + }), + /*@__PURE__*/foldNodeProp.add({ + "Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType": foldInside, + BlockComment(tree) { return { from: tree.from + 2, to: tree.to - 2 }; } + }) + ] + }), + languageData: { + closeBrackets: { brackets: ["(", "[", "{", "'", '"', "`"] }, + commentTokens: { line: "//", block: { open: "/*", close: "*/" } }, + indentOnInput: /^\s*(?:case |default:|\{|\}|<\/)$/, + wordChars: "$" } }); - -const defaultHighlightOptions = { - highlightWordAroundCursor: false, - minSelectionLength: 1, - maxMatches: 100, - wholeWords: false +const jsxSublanguage = { + test: node => /^JSX/.test(node.name), + facet: /*@__PURE__*/defineLanguageFacet({ commentTokens: { block: { open: "{/*", close: "*/}" } } }) }; -const highlightConfig = /*@__PURE__*/Facet.define({ - combine(options) { - return combineConfig(options, defaultHighlightOptions, { - highlightWordAroundCursor: (a, b) => a || b, - minSelectionLength: Math.min, - maxMatches: Math.min - }); - } +/** +A language provider for TypeScript. +*/ +const typescriptLanguage = /*@__PURE__*/javascriptLanguage.configure({ dialect: "ts" }, "typescript"); +/** +Language provider for JSX. +*/ +const jsxLanguage = /*@__PURE__*/javascriptLanguage.configure({ + dialect: "jsx", + props: [/*@__PURE__*/sublanguageProp.add(n => n.isTop ? [jsxSublanguage] : undefined)] }); /** -This extension highlights text that matches the selection. It uses -the `"cm-selectionMatch"` class for the highlighting. When -`highlightWordAroundCursor` is enabled, the word at the cursor -itself will be highlighted with `"cm-selectionMatch-main"`. +Language provider for JSX + TypeScript. */ -function highlightSelectionMatches(options) { - let ext = [defaultTheme, matchHighlighter]; - return ext; -} -const matchDeco = /*@__PURE__*/Decoration.mark({ class: "cm-selectionMatch" }); -const mainMatchDeco = /*@__PURE__*/Decoration.mark({ class: "cm-selectionMatch cm-selectionMatch-main" }); -// Whether the characters directly outside the given positions are non-word characters -function insideWordBoundaries(check, state, from, to) { - return (from == 0 || check(state.sliceDoc(from - 1, from)) != CharCategory.Word) && - (to == state.doc.length || check(state.sliceDoc(to, to + 1)) != CharCategory.Word); -} -// Whether the characters directly at the given positions are word characters -function insideWord(check, state, from, to) { - return check(state.sliceDoc(from, from + 1)) == CharCategory.Word - && check(state.sliceDoc(to - 1, to)) == CharCategory.Word; +const tsxLanguage = /*@__PURE__*/javascriptLanguage.configure({ + dialect: "jsx ts", + props: [/*@__PURE__*/sublanguageProp.add(n => n.isTop ? [jsxSublanguage] : undefined)] +}, "typescript"); +let kwCompletion = (name) => ({ label: name, type: "keyword" }); +const keywords = /*@__PURE__*/"break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(kwCompletion); +const typescriptKeywords = /*@__PURE__*/keywords.concat(/*@__PURE__*/["declare", "implements", "private", "protected", "public"].map(kwCompletion)); +/** +JavaScript support. Includes [snippet](https://codemirror.net/6/docs/ref/#lang-javascript.snippets) +and local variable completion. +*/ +function javascript(config = {}) { + let lang = config.jsx ? (config.typescript ? tsxLanguage : jsxLanguage) + : config.typescript ? typescriptLanguage : javascriptLanguage; + let completions = config.typescript ? typescriptSnippets.concat(typescriptKeywords) : snippets.concat(keywords); + return new LanguageSupport(lang, [ + javascriptLanguage.data.of({ + autocomplete: ifNotIn(dontComplete, completeFromList(completions)) + }), + javascriptLanguage.data.of({ + autocomplete: localCompletionSource + }), + config.jsx ? autoCloseTags : [], + ]); } -const matchHighlighter = /*@__PURE__*/ViewPlugin.fromClass(class { - constructor(view) { - this.decorations = this.getDeco(view); +function findOpenTag(node) { + for (;;) { + if (node.name == "JSXOpenTag" || node.name == "JSXSelfClosingTag" || node.name == "JSXFragmentTag") + return node; + if (node.name == "JSXEscape" || !node.parent) + return null; + node = node.parent; } - update(update) { - if (update.selectionSet || update.docChanged || update.viewportChanged) - this.decorations = this.getDeco(update.view); +} +function elementName(doc, tree, max = doc.length) { + for (let ch = tree === null || tree === void 0 ? void 0 : tree.firstChild; ch; ch = ch.nextSibling) { + if (ch.name == "JSXIdentifier" || ch.name == "JSXBuiltin" || ch.name == "JSXNamespacedName" || + ch.name == "JSXMemberExpression") + return doc.sliceString(ch.from, Math.min(ch.to, max)); } - getDeco(view) { - let conf = view.state.facet(highlightConfig); - let { state } = view, sel = state.selection; - if (sel.ranges.length > 1) - return Decoration.none; - let range = sel.main, query, check = null; - if (range.empty) { - if (!conf.highlightWordAroundCursor) - return Decoration.none; - let word = state.wordAt(range.head); - if (!word) - return Decoration.none; - check = state.charCategorizer(range.head); - query = state.sliceDoc(word.from, word.to); + return ""; +} +const android = typeof navigator == "object" && /*@__PURE__*//Android\b/.test(navigator.userAgent); +/** +Extension that will automatically insert JSX close tags when a `>` or +`/` is typed. +*/ +const autoCloseTags = /*@__PURE__*/EditorView.inputHandler.of((view, from, to, text, defaultInsert) => { + if ((android ? view.composing : view.compositionStarted) || view.state.readOnly || + from != to || (text != ">" && text != "/") || + !javascriptLanguage.isActiveAt(view.state, from, -1)) + return false; + let base = defaultInsert(), { state } = base; + let closeTags = state.changeByRange(range => { + var _a; + let { head } = range, around = syntaxTree(state).resolveInner(head - 1, -1), name; + if (around.name == "JSXStartTag") + around = around.parent; + if (state.doc.sliceString(head - 1, head) != text || around.name == "JSXAttributeValue" && around.to > head) ; + else if (text == ">" && around.name == "JSXFragmentTag") { + return { range, changes: { from: head, insert: `` } }; } - else { - let len = range.to - range.from; - if (len < conf.minSelectionLength || len > 200) - return Decoration.none; - if (conf.wholeWords) { - query = state.sliceDoc(range.from, range.to); // TODO: allow and include leading/trailing space? - check = state.charCategorizer(range.head); - if (!(insideWordBoundaries(check, state, range.from, range.to) && - insideWord(check, state, range.from, range.to))) - return Decoration.none; - } - else { - query = state.sliceDoc(range.from, range.to); - if (!query) - return Decoration.none; + else if (text == "/" && around.name == "JSXStartCloseTag") { + let empty = around.parent, base = empty.parent; + if (base && empty.from == head - 2 && + ((name = elementName(state.doc, base.firstChild, head)) || ((_a = base.firstChild) === null || _a === void 0 ? void 0 : _a.name) == "JSXFragmentTag")) { + let insert = `${name}>`; + return { range: EditorSelection.cursor(head + insert.length, -1), changes: { from: head, insert } }; } } - let deco = []; - for (let part of view.visibleRanges) { - let cursor = new SearchCursor(state.doc, query, part.from, part.to); - while (!cursor.next().done) { - let { from, to } = cursor.value; - if (!check || insideWordBoundaries(check, state, from, to)) { - if (range.empty && from <= range.from && to >= range.to) - deco.push(mainMatchDeco.range(from, to)); - else if (from >= range.to || to <= range.from) - deco.push(matchDeco.range(from, to)); - if (deco.length > conf.maxMatches) - return Decoration.none; - } - } + else if (text == ">") { + let openTag = findOpenTag(around); + if (openTag && openTag.name == "JSXOpenTag" && + !/^\/?>|^<\//.test(state.doc.sliceString(head, head + 2)) && + (name = elementName(state.doc, openTag, head))) + return { range, changes: { from: head, insert: `` } }; } - return Decoration.set(deco); - } -}, { - decorations: v => v.decorations -}); -const defaultTheme = /*@__PURE__*/EditorView.baseTheme({ - ".cm-selectionMatch": { backgroundColor: "#99ff7780" }, - ".cm-searchMatch .cm-selectionMatch": { backgroundColor: "transparent" } -}); -// Select the words around the cursors. -const selectWord = ({ state, dispatch }) => { - let { selection } = state; - let newSel = EditorSelection.create(selection.ranges.map(range => state.wordAt(range.head) || EditorSelection.cursor(range.head)), selection.mainIndex); - if (newSel.eq(selection)) + return { range }; + }); + if (closeTags.changes.empty) return false; - dispatch(state.update({ selection: newSel })); + view.dispatch([ + base, + state.update(closeTags, { userEvent: "input.complete", scrollIntoView: true }) + ]); return true; +}); + +/** +Comment or uncomment the current selection. Will use line comments +if available, otherwise falling back to block comments. +*/ +const toggleComment = target => { + let { state } = target, line = state.doc.lineAt(state.selection.main.from), config = getConfig(target.state, line.from); + return config.line ? toggleLineComment(target) : config.block ? toggleBlockCommentByLine(target) : false; }; -// Find next occurrence of query relative to last cursor. Wrap around -// the document if there are no more matches. -function findNextOccurrence(state, query) { - let { main, ranges } = state.selection; - let word = state.wordAt(main.head), fullWord = word && word.from == main.from && word.to == main.to; - for (let cycled = false, cursor = new SearchCursor(state.doc, query, ranges[ranges.length - 1].to);;) { - cursor.next(); - if (cursor.done) { - if (cycled) - return null; - cursor = new SearchCursor(state.doc, query, 0, Math.max(0, ranges[ranges.length - 1].from - 1)); - cycled = true; - } - else { - if (cycled && ranges.some(r => r.from == cursor.value.from)) - continue; - if (fullWord) { - let word = state.wordAt(cursor.value.from); - if (!word || word.from != cursor.value.from || word.to != cursor.value.to) - continue; - } - return cursor.value; - } - } +function command(f, option) { + return ({ state, dispatch }) => { + if (state.readOnly) + return false; + let tr = f(option, state); + if (!tr) + return false; + dispatch(state.update(tr)); + return true; + }; } /** -Select next occurrence of the current selection. Expand selection -to the surrounding word when the selection is empty. +Comment or uncomment the current selection using line comments. +The line comment syntax is taken from the +[`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language +data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). */ -const selectNextOccurrence = ({ state, dispatch }) => { - let { ranges } = state.selection; - if (ranges.some(sel => sel.from === sel.to)) - return selectWord({ state, dispatch }); - let searchedText = state.sliceDoc(ranges[0].from, ranges[0].to); - if (state.selection.ranges.some(r => state.sliceDoc(r.from, r.to) != searchedText)) - return false; - let range = findNextOccurrence(state, searchedText); - if (!range) - return false; - dispatch(state.update({ - selection: state.selection.addRange(EditorSelection.range(range.from, range.to), false), - effects: EditorView.scrollIntoView(range.to) - })); - return true; -}; - -const searchConfigFacet = /*@__PURE__*/Facet.define({ - combine(configs) { - return combineConfig(configs, { - top: false, - caseSensitive: false, - literal: false, - regexp: false, - wholeWord: false, - createPanel: view => new SearchPanel(view), - scrollToMatch: range => EditorView.scrollIntoView(range) - }); - } -}); +const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* CommentOption.Toggle */); /** -A search query. Part of the editor's search state. +Comment or uncomment the current selection using block comments. +The block comment syntax is taken from the +[`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language +data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt). */ -class SearchQuery { - /** - Create a query object. - */ - constructor(config) { - this.search = config.search; - this.caseSensitive = !!config.caseSensitive; - this.literal = !!config.literal; - this.regexp = !!config.regexp; - this.replace = config.replace || ""; - this.valid = !!this.search && (!this.regexp || validRegExp(this.search)); - this.unquoted = this.unquote(this.search); - this.wholeWord = !!config.wholeWord; - } - /** - @internal - */ - unquote(text) { - return this.literal ? text : - text.replace(/\\([nrt\\])/g, (_, ch) => ch == "n" ? "\n" : ch == "r" ? "\r" : ch == "t" ? "\t" : "\\"); +const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* CommentOption.Toggle */); +/** +Comment or uncomment the lines around the current selection using +block comments. +*/ +const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* CommentOption.Toggle */); +function getConfig(state, pos) { + let data = state.languageDataAt("commentTokens", pos); + return data.length ? data[0] : {}; +} +const SearchMargin = 50; +/** +Determines if the given range is block-commented in the given +state. +*/ +function findBlockComment(state, { open, close }, from, to) { + let textBefore = state.sliceDoc(from - SearchMargin, from); + let textAfter = state.sliceDoc(to, to + SearchMargin); + let spaceBefore = /\s*$/.exec(textBefore)[0].length, spaceAfter = /^\s*/.exec(textAfter)[0].length; + let beforeOff = textBefore.length - spaceBefore; + if (textBefore.slice(beforeOff - open.length, beforeOff) == open && + textAfter.slice(spaceAfter, spaceAfter + close.length) == close) { + return { open: { pos: from - spaceBefore, margin: spaceBefore && 1 }, + close: { pos: to + spaceAfter, margin: spaceAfter && 1 } }; } - /** - Compare this query to another query. - */ - eq(other) { - return this.search == other.search && this.replace == other.replace && - this.caseSensitive == other.caseSensitive && this.regexp == other.regexp && - this.wholeWord == other.wholeWord; + let startText, endText; + if (to - from <= 2 * SearchMargin) { + startText = endText = state.sliceDoc(from, to); } - /** - @internal - */ - create() { - return this.regexp ? new RegExpQuery(this) : new StringQuery(this); + else { + startText = state.sliceDoc(from, from + SearchMargin); + endText = state.sliceDoc(to - SearchMargin, to); } - /** - Get a search cursor for this query, searching through the given - range in the given state. - */ - getCursor(state, from = 0, to) { - let st = state.doc ? state : EditorState.create({ doc: state }); - if (to == null) - to = st.doc.length; - return this.regexp ? regexpCursor(this, st, from, to) : stringCursor(this, st, from, to); + let startSpace = /^\s*/.exec(startText)[0].length, endSpace = /\s*$/.exec(endText)[0].length; + let endOff = endText.length - endSpace - close.length; + if (startText.slice(startSpace, startSpace + open.length) == open && + endText.slice(endOff, endOff + close.length) == close) { + return { open: { pos: from + startSpace + open.length, + margin: /\s/.test(startText.charAt(startSpace + open.length)) ? 1 : 0 }, + close: { pos: to - endSpace - close.length, + margin: /\s/.test(endText.charAt(endOff - 1)) ? 1 : 0 } }; } + return null; } -class QueryType { - constructor(spec) { - this.spec = spec; +function selectedLineRanges(state) { + let ranges = []; + for (let r of state.selection.ranges) { + let fromLine = state.doc.lineAt(r.from); + let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to); + let last = ranges.length - 1; + if (last >= 0 && ranges[last].to > fromLine.from) + ranges[last].to = toLine.to; + else + ranges.push({ from: fromLine.from + /^\s*/.exec(fromLine.text)[0].length, to: toLine.to }); } + return ranges; } -function stringCursor(spec, state, from, to) { - return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined); -} -function stringWordTest(doc, categorizer) { - return (from, to, buf, bufPos) => { - if (bufPos > from || bufPos + buf.length < to) { - bufPos = Math.max(0, from - 2); - buf = doc.sliceString(bufPos, Math.min(doc.length, to + 2)); - } - return (categorizer(charBefore(buf, from - bufPos)) != CharCategory.Word || - categorizer(charAfter(buf, from - bufPos)) != CharCategory.Word) && - (categorizer(charAfter(buf, to - bufPos)) != CharCategory.Word || - categorizer(charBefore(buf, to - bufPos)) != CharCategory.Word); - }; -} -class StringQuery extends QueryType { - constructor(spec) { - super(spec); +// Performs toggle, comment and uncomment of block comments in +// languages that support them. +function changeBlockComment(option, state, ranges = state.selection.ranges) { + let tokens = ranges.map(r => getConfig(state, r.from).block); + if (!tokens.every(c => c)) + return null; + let comments = ranges.map((r, i) => findBlockComment(state, tokens[i], r.from, r.to)); + if (option != 2 /* CommentOption.Uncomment */ && !comments.every(c => c)) { + return { changes: state.changes(ranges.map((range, i) => { + if (comments[i]) + return []; + return [{ from: range.from, insert: tokens[i].open + " " }, { from: range.to, insert: " " + tokens[i].close }]; + })) }; } - nextMatch(state, curFrom, curTo) { - let cursor = stringCursor(this.spec, state, curTo, state.doc.length).nextOverlapping(); - if (cursor.done) - cursor = stringCursor(this.spec, state, 0, curFrom).nextOverlapping(); - return cursor.done ? null : cursor.value; + else if (option != 1 /* CommentOption.Comment */ && comments.some(c => c)) { + let changes = []; + for (let i = 0, comment; i < comments.length; i++) + if (comment = comments[i]) { + let token = tokens[i], { open, close } = comment; + changes.push({ from: open.pos - token.open.length, to: open.pos + open.margin }, { from: close.pos - close.margin, to: close.pos + token.close.length }); + } + return { changes }; } - // Searching in reverse is, rather than implementing an inverted search - // cursor, done by scanning chunk after chunk forward. - prevMatchInRange(state, from, to) { - for (let pos = to;;) { - let start = Math.max(from, pos - 10000 /* FindPrev.ChunkSize */ - this.spec.unquoted.length); - let cursor = stringCursor(this.spec, state, start, pos), range = null; - while (!cursor.nextOverlapping().done) - range = cursor.value; - if (range) - return range; - if (start == from) - return null; - pos -= 10000 /* FindPrev.ChunkSize */; + return null; +} +// Performs toggle, comment and uncomment of line comments. +function changeLineComment(option, state, ranges = state.selection.ranges) { + let lines = []; + let prevLine = -1; + for (let { from, to } of ranges) { + let startI = lines.length, minIndent = 1e9; + let token = getConfig(state, from).line; + if (!token) + continue; + for (let pos = from; pos <= to;) { + let line = state.doc.lineAt(pos); + if (line.from > prevLine && (from == to || to > line.from)) { + prevLine = line.from; + let indent = /^\s*/.exec(line.text)[0].length; + let empty = indent == line.length; + let comment = line.text.slice(indent, indent + token.length) == token ? indent : -1; + if (indent < line.text.length && indent < minIndent) + minIndent = indent; + lines.push({ line, comment, token, indent, empty, single: false }); + } + pos = line.to + 1; } + if (minIndent < 1e9) + for (let i = startI; i < lines.length; i++) + if (lines[i].indent < lines[i].line.text.length) + lines[i].indent = minIndent; + if (lines.length == startI + 1) + lines[startI].single = true; } - prevMatch(state, curFrom, curTo) { - return this.prevMatchInRange(state, 0, curFrom) || - this.prevMatchInRange(state, curTo, state.doc.length); - } - getReplacement(_result) { return this.spec.unquote(this.spec.replace); } - matchAll(state, limit) { - let cursor = stringCursor(this.spec, state, 0, state.doc.length), ranges = []; - while (!cursor.next().done) { - if (ranges.length >= limit) - return null; - ranges.push(cursor.value); - } - return ranges; + if (option != 2 /* CommentOption.Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) { + let changes = []; + for (let { line, token, indent, empty, single } of lines) + if (single || !empty) + changes.push({ from: line.from + indent, insert: token + " " }); + let changeSet = state.changes(changes); + return { changes: changeSet, selection: state.selection.map(changeSet, 1) }; } - highlight(state, from, to, add) { - let cursor = stringCursor(this.spec, state, Math.max(0, from - this.spec.unquoted.length), Math.min(to + this.spec.unquoted.length, state.doc.length)); - while (!cursor.next().done) - add(cursor.value.from, cursor.value.to); + else if (option != 1 /* CommentOption.Comment */ && lines.some(l => l.comment >= 0)) { + let changes = []; + for (let { line, comment, token } of lines) + if (comment >= 0) { + let from = line.from + comment, to = from + token.length; + if (line.text[to - line.from] == " ") + to++; + changes.push({ from, to }); + } + return { changes }; } + return null; } -function regexpCursor(spec, state, from, to) { - return new RegExpCursor(state.doc, spec.search, { - ignoreCase: !spec.caseSensitive, - test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined - }, from, to); -} -function charBefore(str, index) { - return str.slice(findClusterBreak(str, index, false), index); -} -function charAfter(str, index) { - return str.slice(index, findClusterBreak(str, index)); -} -function regexpWordTest(categorizer) { - return (_from, _to, match) => !match[0].length || - (categorizer(charBefore(match.input, match.index)) != CharCategory.Word || - categorizer(charAfter(match.input, match.index)) != CharCategory.Word) && - (categorizer(charAfter(match.input, match.index + match[0].length)) != CharCategory.Word || - categorizer(charBefore(match.input, match.index + match[0].length)) != CharCategory.Word); -} -class RegExpQuery extends QueryType { - nextMatch(state, curFrom, curTo) { - let cursor = regexpCursor(this.spec, state, curTo, state.doc.length).next(); - if (cursor.done) - cursor = regexpCursor(this.spec, state, 0, curFrom).next(); - return cursor.done ? null : cursor.value; + +const fromHistory = /*@__PURE__*/Annotation.define(); +/** +Transaction annotation that will prevent that transaction from +being combined with other transactions in the undo history. Given +`"before"`, it'll prevent merging with previous transactions. With +`"after"`, subsequent transactions won't be combined with this +one. With `"full"`, the transaction is isolated on both sides. +*/ +const isolateHistory = /*@__PURE__*/Annotation.define(); +/** +This facet provides a way to register functions that, given a +transaction, provide a set of effects that the history should +store when inverting the transaction. This can be used to +integrate some kinds of effects in the history, so that they can +be undone (and redone again). +*/ +const invertedEffects = /*@__PURE__*/Facet.define(); +const historyConfig = /*@__PURE__*/Facet.define({ + combine(configs) { + return combineConfig(configs, { + minDepth: 100, + newGroupDelay: 500, + joinToEvent: (_t, isAdjacent) => isAdjacent, + }, { + minDepth: Math.max, + newGroupDelay: Math.min, + joinToEvent: (a, b) => (tr, adj) => a(tr, adj) || b(tr, adj) + }); } - prevMatchInRange(state, from, to) { - for (let size = 1;; size++) { - let start = Math.max(from, to - size * 10000 /* FindPrev.ChunkSize */); - let cursor = regexpCursor(this.spec, state, start, to), range = null; - while (!cursor.next().done) - range = cursor.value; - if (range && (start == from || range.from > start + 10)) - return range; - if (start == from) - return null; - } - } - prevMatch(state, curFrom, curTo) { - return this.prevMatchInRange(state, 0, curFrom) || - this.prevMatchInRange(state, curTo, state.doc.length); - } - getReplacement(result) { - return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$" - : i == "&" ? result.match[0] - : i != "0" && +i < result.match.length ? result.match[i] - : m); - } - matchAll(state, limit) { - let cursor = regexpCursor(this.spec, state, 0, state.doc.length), ranges = []; - while (!cursor.next().done) { - if (ranges.length >= limit) - return null; - ranges.push(cursor.value); - } - return ranges; - } - highlight(state, from, to, add) { - let cursor = regexpCursor(this.spec, state, Math.max(0, from - 250 /* RegExp.HighlightMargin */), Math.min(to + 250 /* RegExp.HighlightMargin */, state.doc.length)); - while (!cursor.next().done) - add(cursor.value.from, cursor.value.to); - } -} -/** -A state effect that updates the current search query. Note that -this only has an effect if the search state has been initialized -(by including [`search`](https://codemirror.net/6/docs/ref/#search.search) in your configuration or -by running [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSearchPanel) at least -once). -*/ -const setSearchQuery = /*@__PURE__*/StateEffect.define(); -const togglePanel$1 = /*@__PURE__*/StateEffect.define(); -const searchState = /*@__PURE__*/StateField.define({ - create(state) { - return new SearchState(defaultQuery(state).create(), null); +}); +const historyField_ = /*@__PURE__*/StateField.define({ + create() { + return HistoryState.empty; }, - update(value, tr) { - for (let effect of tr.effects) { - if (effect.is(setSearchQuery)) - value = new SearchState(effect.value.create(), value.panel); - else if (effect.is(togglePanel$1)) - value = new SearchState(value.query, effect.value ? createSearchPanel : null); + update(state, tr) { + let config = tr.state.facet(historyConfig); + let fromHist = tr.annotation(fromHistory); + if (fromHist) { + let item = HistEvent.fromTransaction(tr, fromHist.selection), from = fromHist.side; + let other = from == 0 /* BranchName.Done */ ? state.undone : state.done; + if (item) + other = updateBranch(other, other.length, config.minDepth, item); + else + other = addSelection(other, tr.startState.selection); + return new HistoryState(from == 0 /* BranchName.Done */ ? fromHist.rest : other, from == 0 /* BranchName.Done */ ? other : fromHist.rest); } - return value; + let isolate = tr.annotation(isolateHistory); + if (isolate == "full" || isolate == "before") + state = state.isolate(); + if (tr.annotation(Transaction.addToHistory) === false) + return !tr.changes.empty ? state.addMapping(tr.changes.desc) : state; + let event = HistEvent.fromTransaction(tr); + let time = tr.annotation(Transaction.time), userEvent = tr.annotation(Transaction.userEvent); + if (event) + state = state.addChanges(event, time, userEvent, config, tr); + else if (tr.selection) + state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay); + if (isolate == "full" || isolate == "after") + state = state.isolate(); + return state; }, - provide: f => showPanel.from(f, val => val.panel) -}); -class SearchState { - constructor(query, panel) { - this.query = query; - this.panel = panel; - } -} -const matchMark = /*@__PURE__*/Decoration.mark({ class: "cm-searchMatch" }), selectedMatchMark = /*@__PURE__*/Decoration.mark({ class: "cm-searchMatch cm-searchMatch-selected" }); -const searchHighlighter = /*@__PURE__*/ViewPlugin.fromClass(class { - constructor(view) { - this.view = view; - this.decorations = this.highlight(view.state.field(searchState)); - } - update(update) { - let state = update.state.field(searchState); - if (state != update.startState.field(searchState) || update.docChanged || update.selectionSet || update.viewportChanged) - this.decorations = this.highlight(state); - } - highlight({ query, panel }) { - if (!panel || !query.spec.valid) - return Decoration.none; - let { view } = this; - let builder = new RangeSetBuilder(); - for (let i = 0, ranges = view.visibleRanges, l = ranges.length; i < l; i++) { - let { from, to } = ranges[i]; - while (i < l - 1 && to > ranges[i + 1].from - 2 * 250 /* RegExp.HighlightMargin */) - to = ranges[++i].to; - query.highlight(view.state, from, to, (from, to) => { - let selected = view.state.selection.ranges.some(r => r.from == from && r.to == to); - builder.add(from, to, selected ? selectedMatchMark : matchMark); - }); - } - return builder.finish(); + toJSON(value) { + return { done: value.done.map(e => e.toJSON()), undone: value.undone.map(e => e.toJSON()) }; + }, + fromJSON(json) { + return new HistoryState(json.done.map(HistEvent.fromJSON), json.undone.map(HistEvent.fromJSON)); } -}, { - decorations: v => v.decorations }); -function searchCommand(f) { - return view => { - let state = view.state.field(searchState, false); - return state && state.query.spec.valid ? f(view, state) : openSearchPanel(view); +/** +Create a history extension with the given configuration. +*/ +function history$1(config = {}) { + return [ + historyField_, + historyConfig.of(config), + EditorView.domEventHandlers({ + beforeinput(e, view) { + let command = e.inputType == "historyUndo" ? undo : e.inputType == "historyRedo" ? redo : null; + if (!command) + return false; + e.preventDefault(); + return command(view); + } + }) + ]; +} +function cmd(side, selection) { + return function ({ state, dispatch }) { + if (!selection && state.readOnly) + return false; + let historyState = state.field(historyField_, false); + if (!historyState) + return false; + let tr = historyState.pop(side, state, selection); + if (!tr) + return false; + dispatch(tr); + return true; }; } /** -Open the search panel if it isn't already open, and move the -selection to the first match after the current main selection. -Will wrap around to the start of the document when it reaches the -end. +Undo a single group of history events. Returns false if no group +was available. */ -const findNext = /*@__PURE__*/searchCommand((view, { query }) => { - let { to } = view.state.selection.main; - let next = query.nextMatch(view.state, to, to); - if (!next) - return false; - let selection = EditorSelection.single(next.from, next.to); - let config = view.state.facet(searchConfigFacet); - view.dispatch({ - selection, - effects: [announceMatch(view, next), config.scrollToMatch(selection.main, view)], - userEvent: "select.search" - }); - selectSearchInput(view); - return true; -}); +const undo = /*@__PURE__*/cmd(0 /* BranchName.Done */, false); /** -Move the selection to the previous instance of the search query, -before the current main selection. Will wrap past the start -of the document to start searching at the end again. +Redo a group of history events. Returns false if no group was +available. */ -const findPrevious = /*@__PURE__*/searchCommand((view, { query }) => { - let { state } = view, { from } = state.selection.main; - let prev = query.prevMatch(state, from, from); - if (!prev) - return false; - let selection = EditorSelection.single(prev.from, prev.to); - let config = view.state.facet(searchConfigFacet); - view.dispatch({ - selection, - effects: [announceMatch(view, prev), config.scrollToMatch(selection.main, view)], - userEvent: "select.search" - }); - selectSearchInput(view); - return true; -}); +const redo = /*@__PURE__*/cmd(1 /* BranchName.Undone */, false); /** -Select all instances of the search query. +Undo a change or selection change. */ -const selectMatches = /*@__PURE__*/searchCommand((view, { query }) => { - let ranges = query.matchAll(view.state, 1000); - if (!ranges || !ranges.length) - return false; - view.dispatch({ - selection: EditorSelection.create(ranges.map(r => EditorSelection.range(r.from, r.to))), - userEvent: "select.search.matches" - }); - return true; -}); +const undoSelection = /*@__PURE__*/cmd(0 /* BranchName.Done */, true); /** -Select all instances of the currently selected text. +Redo a change or selection change. */ -const selectSelectionMatches = ({ state, dispatch }) => { - let sel = state.selection; - if (sel.ranges.length > 1 || sel.main.empty) - return false; - let { from, to } = sel.main; - let ranges = [], main = 0; - for (let cur = new SearchCursor(state.doc, state.sliceDoc(from, to)); !cur.next().done;) { - if (ranges.length > 1000) - return false; - if (cur.value.from == from) - main = ranges.length; - ranges.push(EditorSelection.range(cur.value.from, cur.value.to)); +const redoSelection = /*@__PURE__*/cmd(1 /* BranchName.Undone */, true); +// History events store groups of changes or effects that need to be +// undone/redone together. +class HistEvent { + constructor( + // The changes in this event. Normal events hold at least one + // change or effect. But it may be necessary to store selection + // events before the first change, in which case a special type of + // instance is created which doesn't hold any changes, with + // changes == startSelection == undefined + changes, + // The effects associated with this event + effects, + // Accumulated mapping (from addToHistory==false) that should be + // applied to events below this one. + mapped, + // The selection before this event + startSelection, + // Stores selection changes after this event, to be used for + // selection undo/redo. + selectionsAfter) { + this.changes = changes; + this.effects = effects; + this.mapped = mapped; + this.startSelection = startSelection; + this.selectionsAfter = selectionsAfter; } - dispatch(state.update({ - selection: EditorSelection.create(ranges, main), - userEvent: "select.search.matches" - })); - return true; -}; -/** -Replace the current match of the search query. -*/ -const replaceNext = /*@__PURE__*/searchCommand((view, { query }) => { - let { state } = view, { from, to } = state.selection.main; - if (state.readOnly) - return false; - let next = query.nextMatch(state, from, from); - if (!next) - return false; - let changes = [], selection, replacement; - let effects = []; - if (next.from == from && next.to == to) { - replacement = state.toText(query.getReplacement(next)); - changes.push({ from: next.from, to: next.to, insert: replacement }); - next = query.nextMatch(state, next.from, next.to); - effects.push(EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + ".")); + setSelAfter(after) { + return new HistEvent(this.changes, this.effects, this.mapped, this.startSelection, after); } - if (next) { - let off = changes.length == 0 || changes[0].from >= next.to ? 0 : next.to - next.from - replacement.length; - selection = EditorSelection.single(next.from - off, next.to - off); - effects.push(announceMatch(view, next)); - effects.push(state.facet(searchConfigFacet).scrollToMatch(selection.main, view)); + toJSON() { + var _a, _b, _c; + return { + changes: (_a = this.changes) === null || _a === void 0 ? void 0 : _a.toJSON(), + mapped: (_b = this.mapped) === null || _b === void 0 ? void 0 : _b.toJSON(), + startSelection: (_c = this.startSelection) === null || _c === void 0 ? void 0 : _c.toJSON(), + selectionsAfter: this.selectionsAfter.map(s => s.toJSON()) + }; + } + static fromJSON(json) { + return new HistEvent(json.changes && ChangeSet.fromJSON(json.changes), [], json.mapped && ChangeDesc.fromJSON(json.mapped), json.startSelection && EditorSelection.fromJSON(json.startSelection), json.selectionsAfter.map(EditorSelection.fromJSON)); + } + // This does not check `addToHistory` and such, it assumes the + // transaction needs to be converted to an item. Returns null when + // there are no changes or effects in the transaction. + static fromTransaction(tr, selection) { + let effects = none; + for (let invert of tr.startState.facet(invertedEffects)) { + let result = invert(tr); + if (result.length) + effects = effects.concat(result); + } + if (!effects.length && tr.changes.empty) + return null; + return new HistEvent(tr.changes.invert(tr.startState.doc), effects, undefined, selection || tr.startState.selection, none); + } + static selection(selections) { + return new HistEvent(undefined, none, undefined, undefined, selections); } - view.dispatch({ - changes, selection, effects, - userEvent: "input.replace" - }); - return true; -}); -/** -Replace all instances of the search query with the given -replacement. -*/ -const replaceAll = /*@__PURE__*/searchCommand((view, { query }) => { - if (view.state.readOnly) - return false; - let changes = query.matchAll(view.state, 1e9).map(match => { - let { from, to } = match; - return { from, to, insert: query.getReplacement(match) }; - }); - if (!changes.length) - return false; - let announceText = view.state.phrase("replaced $ matches", changes.length) + "."; - view.dispatch({ - changes, - effects: EditorView.announce.of(announceText), - userEvent: "input.replace.all" - }); - return true; -}); -function createSearchPanel(view) { - return view.state.facet(searchConfigFacet).createPanel(view); } -function defaultQuery(state, fallback) { - var _a, _b, _c, _d, _e; - let sel = state.selection.main; - let selText = sel.empty || sel.to > sel.from + 100 ? "" : state.sliceDoc(sel.from, sel.to); - if (fallback && !selText) - return fallback; - let config = state.facet(searchConfigFacet); - return new SearchQuery({ - search: ((_a = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _a !== void 0 ? _a : config.literal) ? selText : selText.replace(/\n/g, "\\n"), - caseSensitive: (_b = fallback === null || fallback === void 0 ? void 0 : fallback.caseSensitive) !== null && _b !== void 0 ? _b : config.caseSensitive, - literal: (_c = fallback === null || fallback === void 0 ? void 0 : fallback.literal) !== null && _c !== void 0 ? _c : config.literal, - regexp: (_d = fallback === null || fallback === void 0 ? void 0 : fallback.regexp) !== null && _d !== void 0 ? _d : config.regexp, - wholeWord: (_e = fallback === null || fallback === void 0 ? void 0 : fallback.wholeWord) !== null && _e !== void 0 ? _e : config.wholeWord +function updateBranch(branch, to, maxLen, newEvent) { + let start = to + 1 > maxLen + 20 ? to - maxLen - 1 : 0; + let newBranch = branch.slice(start, to); + newBranch.push(newEvent); + return newBranch; +} +function isAdjacent(a, b) { + let ranges = [], isAdjacent = false; + a.iterChangedRanges((f, t) => ranges.push(f, t)); + b.iterChangedRanges((_f, _t, f, t) => { + for (let i = 0; i < ranges.length;) { + let from = ranges[i++], to = ranges[i++]; + if (t >= from && f <= to) + isAdjacent = true; + } }); + return isAdjacent; } -function getSearchInput(view) { - let panel = getPanel(view, createSearchPanel); - return panel && panel.dom.querySelector("[main-field]"); +function eqSelectionShape(a, b) { + return a.ranges.length == b.ranges.length && + a.ranges.filter((r, i) => r.empty != b.ranges[i].empty).length === 0; } -function selectSearchInput(view) { - let input = getSearchInput(view); - if (input && input == view.root.activeElement) - input.select(); +function conc(a, b) { + return !a.length ? b : !b.length ? a : a.concat(b); } -/** -Make sure the search panel is open and focused. -*/ -const openSearchPanel = view => { - let state = view.state.field(searchState, false); - if (state && state.panel) { - let searchInput = getSearchInput(view); - if (searchInput && searchInput != view.root.activeElement) { - let query = defaultQuery(view.state, state.query.spec); - if (query.valid) - view.dispatch({ effects: setSearchQuery.of(query) }); - searchInput.focus(); - searchInput.select(); - } +const none = []; +const MaxSelectionsPerEvent = 200; +function addSelection(branch, selection) { + if (!branch.length) { + return [HistEvent.selection([selection])]; } else { - view.dispatch({ effects: [ - togglePanel$1.of(true), - state ? setSearchQuery.of(defaultQuery(view.state, state.query.spec)) : StateEffect.appendConfig.of(searchExtensions) - ] }); + let lastEvent = branch[branch.length - 1]; + let sels = lastEvent.selectionsAfter.slice(Math.max(0, lastEvent.selectionsAfter.length - MaxSelectionsPerEvent)); + if (sels.length && sels[sels.length - 1].eq(selection)) + return branch; + sels.push(selection); + return updateBranch(branch, branch.length - 1, 1e9, lastEvent.setSelAfter(sels)); } - return true; -}; -/** -Close the search panel. -*/ -const closeSearchPanel = view => { - let state = view.state.field(searchState, false); - if (!state || !state.panel) - return false; - let panel = getPanel(view, createSearchPanel); - if (panel && panel.dom.contains(view.root.activeElement)) - view.focus(); - view.dispatch({ effects: togglePanel$1.of(false) }); - return true; -}; -/** -Default search-related key bindings. - - - Mod-f: [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSearchPanel) - - F3, Mod-g: [`findNext`](https://codemirror.net/6/docs/ref/#search.findNext) - - Shift-F3, Shift-Mod-g: [`findPrevious`](https://codemirror.net/6/docs/ref/#search.findPrevious) - - Mod-Alt-g: [`gotoLine`](https://codemirror.net/6/docs/ref/#search.gotoLine) - - Mod-d: [`selectNextOccurrence`](https://codemirror.net/6/docs/ref/#search.selectNextOccurrence) -*/ -const searchKeymap = [ - { key: "Mod-f", run: openSearchPanel, scope: "editor search-panel" }, - { key: "F3", run: findNext, shift: findPrevious, scope: "editor search-panel", preventDefault: true }, - { key: "Mod-g", run: findNext, shift: findPrevious, scope: "editor search-panel", preventDefault: true }, - { key: "Escape", run: closeSearchPanel, scope: "editor search-panel" }, - { key: "Mod-Shift-l", run: selectSelectionMatches }, - { key: "Mod-Alt-g", run: gotoLine }, - { key: "Mod-d", run: selectNextOccurrence, preventDefault: true }, -]; -class SearchPanel { - constructor(view) { - this.view = view; - let query = this.query = view.state.field(searchState).query.spec; - this.commit = this.commit.bind(this); - this.searchField = crelt("input", { - value: query.search, - placeholder: phrase(view, "Find"), - "aria-label": phrase(view, "Find"), - class: "cm-textfield", - name: "search", - form: "", - "main-field": "true", - onchange: this.commit, - onkeyup: this.commit - }); - this.replaceField = crelt("input", { - value: query.replace, - placeholder: phrase(view, "Replace"), - "aria-label": phrase(view, "Replace"), - class: "cm-textfield", - name: "replace", - form: "", - onchange: this.commit, - onkeyup: this.commit - }); - this.caseField = crelt("input", { - type: "checkbox", - name: "case", - form: "", - checked: query.caseSensitive, - onchange: this.commit - }); - this.reField = crelt("input", { - type: "checkbox", - name: "re", - form: "", - checked: query.regexp, - onchange: this.commit - }); - this.wordField = crelt("input", { - type: "checkbox", - name: "word", - form: "", - checked: query.wholeWord, - onchange: this.commit - }); - function button(name, onclick, content) { - return crelt("button", { class: "cm-button", name, onclick, type: "button" }, content); - } - this.dom = crelt("div", { onkeydown: (e) => this.keydown(e), class: "cm-search" }, [ - this.searchField, - button("next", () => findNext(view), [phrase(view, "next")]), - button("prev", () => findPrevious(view), [phrase(view, "previous")]), - button("select", () => selectMatches(view), [phrase(view, "all")]), - crelt("label", null, [this.caseField, phrase(view, "match case")]), - crelt("label", null, [this.reField, phrase(view, "regexp")]), - crelt("label", null, [this.wordField, phrase(view, "by word")]), - ...view.state.readOnly ? [] : [ - crelt("br"), - this.replaceField, - button("replace", () => replaceNext(view), [phrase(view, "replace")]), - button("replaceAll", () => replaceAll(view), [phrase(view, "replace all")]) - ], - crelt("button", { - name: "close", - onclick: () => closeSearchPanel(view), - "aria-label": phrase(view, "close"), - type: "button" - }, ["×"]) - ]); - } - commit() { - let query = new SearchQuery({ - search: this.searchField.value, - caseSensitive: this.caseField.checked, - regexp: this.reField.checked, - wholeWord: this.wordField.checked, - replace: this.replaceField.value, - }); - if (!query.eq(this.query)) { - this.query = query; - this.view.dispatch({ effects: setSearchQuery.of(query) }); +} +// Assumes the top item has one or more selectionAfter values +function popSelection(branch) { + let last = branch[branch.length - 1]; + let newBranch = branch.slice(); + newBranch[branch.length - 1] = last.setSelAfter(last.selectionsAfter.slice(0, last.selectionsAfter.length - 1)); + return newBranch; +} +// Add a mapping to the top event in the given branch. If this maps +// away all the changes and effects in that item, drop it and +// propagate the mapping to the next item. +function addMappingToBranch(branch, mapping) { + if (!branch.length) + return branch; + let length = branch.length, selections = none; + while (length) { + let event = mapEvent(branch[length - 1], mapping, selections); + if (event.changes && !event.changes.empty || event.effects.length) { // Event survived mapping + let result = branch.slice(0, length); + result[length - 1] = event; + return result; } - } - keydown(e) { - if (runScopeHandlers(this.view, e, "search-panel")) { - e.preventDefault(); + else { // Drop this event, since there's no changes or effects left + mapping = event.mapped; + length--; + selections = event.selectionsAfter; } - else if (e.keyCode == 13 && e.target == this.searchField) { - e.preventDefault(); - (e.shiftKey ? findPrevious : findNext)(this.view); + } + return selections.length ? [HistEvent.selection(selections)] : none; +} +function mapEvent(event, mapping, extraSelections) { + let selections = conc(event.selectionsAfter.length ? event.selectionsAfter.map(s => s.map(mapping)) : none, extraSelections); + // Change-less events don't store mappings (they are always the last event in a branch) + if (!event.changes) + return HistEvent.selection(selections); + let mappedChanges = event.changes.map(mapping), before = mapping.mapDesc(event.changes, true); + let fullMapping = event.mapped ? event.mapped.composeDesc(before) : before; + return new HistEvent(mappedChanges, StateEffect.mapEffects(event.effects, mapping), fullMapping, event.startSelection.map(before), selections); +} +const joinableUserEvent = /^(input\.type|delete)($|\.)/; +class HistoryState { + constructor(done, undone, prevTime = 0, prevUserEvent = undefined) { + this.done = done; + this.undone = undone; + this.prevTime = prevTime; + this.prevUserEvent = prevUserEvent; + } + isolate() { + return this.prevTime ? new HistoryState(this.done, this.undone) : this; + } + addChanges(event, time, userEvent, config, tr) { + let done = this.done, lastEvent = done[done.length - 1]; + if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes && + (!userEvent || joinableUserEvent.test(userEvent)) && + ((!lastEvent.selectionsAfter.length && + time - this.prevTime < config.newGroupDelay && + config.joinToEvent(tr, isAdjacent(lastEvent.changes, event.changes))) || + // For compose (but not compose.start) events, always join with previous event + userEvent == "input.type.compose")) { + done = updateBranch(done, done.length - 1, config.minDepth, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none)); } - else if (e.keyCode == 13 && e.target == this.replaceField) { - e.preventDefault(); - replaceNext(this.view); + else { + done = updateBranch(done, done.length, config.minDepth, event); } + return new HistoryState(done, none, time, userEvent); } - update(update) { - for (let tr of update.transactions) - for (let effect of tr.effects) { - if (effect.is(setSearchQuery) && !effect.value.eq(this.query)) - this.setQuery(effect.value); - } + addSelection(selection, time, userEvent, newGroupDelay) { + let last = this.done.length ? this.done[this.done.length - 1].selectionsAfter : none; + if (last.length > 0 && + time - this.prevTime < newGroupDelay && + userEvent == this.prevUserEvent && userEvent && /^select($|\.)/.test(userEvent) && + eqSelectionShape(last[last.length - 1], selection)) + return this; + return new HistoryState(addSelection(this.done, selection), this.undone, time, userEvent); } - setQuery(query) { - this.query = query; - this.searchField.value = query.search; - this.replaceField.value = query.replace; - this.caseField.checked = query.caseSensitive; - this.reField.checked = query.regexp; - this.wordField.checked = query.wholeWord; + addMapping(mapping) { + return new HistoryState(addMappingToBranch(this.done, mapping), addMappingToBranch(this.undone, mapping), this.prevTime, this.prevUserEvent); } - mount() { - this.searchField.select(); + pop(side, state, onlySelection) { + let branch = side == 0 /* BranchName.Done */ ? this.done : this.undone; + if (branch.length == 0) + return null; + let event = branch[branch.length - 1], selection = event.selectionsAfter[0] || state.selection; + if (onlySelection && event.selectionsAfter.length) { + return state.update({ + selection: event.selectionsAfter[event.selectionsAfter.length - 1], + annotations: fromHistory.of({ side, rest: popSelection(branch), selection }), + userEvent: side == 0 /* BranchName.Done */ ? "select.undo" : "select.redo", + scrollIntoView: true + }); + } + else if (!event.changes) { + return null; + } + else { + let rest = branch.length == 1 ? none : branch.slice(0, branch.length - 1); + if (event.mapped) + rest = addMappingToBranch(rest, event.mapped); + return state.update({ + changes: event.changes, + selection: event.startSelection, + effects: event.effects, + annotations: fromHistory.of({ side, rest, selection }), + filter: false, + userEvent: side == 0 /* BranchName.Done */ ? "undo" : "redo", + scrollIntoView: true + }); + } } - get pos() { return 80; } - get top() { return this.view.state.facet(searchConfigFacet).top; } } -function phrase(view, phrase) { return view.state.phrase(phrase); } -const AnnounceMargin = 30; -const Break = /[\s\.,:;?!]/; -function announceMatch(view, { from, to }) { - let line = view.state.doc.lineAt(from), lineEnd = view.state.doc.lineAt(to).to; - let start = Math.max(line.from, from - AnnounceMargin), end = Math.min(lineEnd, to + AnnounceMargin); - let text = view.state.sliceDoc(start, end); - if (start != line.from) { - for (let i = 0; i < AnnounceMargin; i++) - if (!Break.test(text[i + 1]) && Break.test(text[i])) { - text = text.slice(i); - break; - } - } - if (end != lineEnd) { - for (let i = text.length - 1; i > text.length - AnnounceMargin; i--) - if (!Break.test(text[i - 1]) && Break.test(text[i])) { - text = text.slice(0, i); - break; - } +HistoryState.empty = /*@__PURE__*/new HistoryState(none, none); +/** +Default key bindings for the undo history. + +- Mod-z: [`undo`](https://codemirror.net/6/docs/ref/#commands.undo). +- Mod-y (Mod-Shift-z on macOS) + Ctrl-Shift-z on Linux: [`redo`](https://codemirror.net/6/docs/ref/#commands.redo). +- Mod-u: [`undoSelection`](https://codemirror.net/6/docs/ref/#commands.undoSelection). +- Alt-u (Mod-Shift-u on macOS): [`redoSelection`](https://codemirror.net/6/docs/ref/#commands.redoSelection). +*/ +const historyKeymap = [ + { key: "Mod-z", run: undo, preventDefault: true }, + { key: "Mod-y", mac: "Mod-Shift-z", run: redo, preventDefault: true }, + { linux: "Ctrl-Shift-z", run: redo, preventDefault: true }, + { key: "Mod-u", run: undoSelection, preventDefault: true }, + { key: "Alt-u", mac: "Mod-Shift-u", run: redoSelection, preventDefault: true } +]; + +function updateSel(sel, by) { + return EditorSelection.create(sel.ranges.map(by), sel.mainIndex); +} +function setSel(state, selection) { + return state.update({ selection, scrollIntoView: true, userEvent: "select" }); +} +function moveSel({ state, dispatch }, how) { + let selection = updateSel(state.selection, how); + if (selection.eq(state.selection, true)) + return false; + dispatch(setSel(state, selection)); + return true; +} +function rangeEnd(range, forward) { + return EditorSelection.cursor(forward ? range.to : range.from); +} +function cursorByChar(view, forward) { + return moveSel(view, range => range.empty ? view.moveByChar(range, forward) : rangeEnd(range, forward)); +} +function ltrAtCursor(view) { + return view.textDirectionAt(view.state.selection.main.head) == Direction.LTR; +} +/** +Move the selection one character to the left (which is backward in +left-to-right text, forward in right-to-left text). +*/ +const cursorCharLeft = view => cursorByChar(view, !ltrAtCursor(view)); +/** +Move the selection one character to the right. +*/ +const cursorCharRight = view => cursorByChar(view, ltrAtCursor(view)); +function cursorByGroup(view, forward) { + return moveSel(view, range => range.empty ? view.moveByGroup(range, forward) : rangeEnd(range, forward)); +} +/** +Move the selection to the left across one group of word or +non-word (but also non-space) characters. +*/ +const cursorGroupLeft = view => cursorByGroup(view, !ltrAtCursor(view)); +/** +Move the selection one group to the right. +*/ +const cursorGroupRight = view => cursorByGroup(view, ltrAtCursor(view)); +function interestingNode(state, node, bracketProp) { + if (node.type.prop(bracketProp)) + return true; + let len = node.to - node.from; + return len && (len > 2 || /[^\s,.;:]/.test(state.sliceDoc(node.from, node.to))) || node.firstChild; +} +function moveBySyntax(state, start, forward) { + let pos = syntaxTree(state).resolveInner(start.head); + let bracketProp = forward ? NodeProp.closedBy : NodeProp.openedBy; + // Scan forward through child nodes to see if there's an interesting + // node ahead. + for (let at = start.head;;) { + let next = forward ? pos.childAfter(at) : pos.childBefore(at); + if (!next) + break; + if (interestingNode(state, next, bracketProp)) + pos = next; + else + at = forward ? next.to : next.from; } - return EditorView.announce.of(`${view.state.phrase("current match")}. ${text} ${view.state.phrase("on line")} ${line.number}.`); + let bracket = pos.type.prop(bracketProp), match, newPos; + if (bracket && (match = forward ? matchBrackets(state, pos.from, 1) : matchBrackets(state, pos.to, -1)) && match.matched) + newPos = forward ? match.end.to : match.end.from; + else + newPos = forward ? pos.to : pos.from; + return EditorSelection.cursor(newPos, forward ? -1 : 1); } -const baseTheme$2 = /*@__PURE__*/EditorView.baseTheme({ - ".cm-panel.cm-search": { - padding: "2px 6px 4px", - position: "relative", - "& [name=close]": { - position: "absolute", - top: "0", - right: "4px", - backgroundColor: "inherit", - border: "none", - font: "inherit", - padding: 0, - margin: 0 - }, - "& input, & button, & label": { - margin: ".2em .6em .2em 0" - }, - "& input[type=checkbox]": { - marginRight: ".2em" - }, - "& label": { - fontSize: "80%", - whiteSpace: "pre" +/** +Move the cursor over the next syntactic element to the left. +*/ +const cursorSyntaxLeft = view => moveSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view))); +/** +Move the cursor over the next syntactic element to the right. +*/ +const cursorSyntaxRight = view => moveSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view))); +function cursorByLine(view, forward) { + return moveSel(view, range => { + if (!range.empty) + return rangeEnd(range, forward); + let moved = view.moveVertically(range, forward); + return moved.head != range.head ? moved : view.moveToLineBoundary(range, forward); + }); +} +/** +Move the selection one line up. +*/ +const cursorLineUp = view => cursorByLine(view, false); +/** +Move the selection one line down. +*/ +const cursorLineDown = view => cursorByLine(view, true); +function pageInfo(view) { + let selfScroll = view.scrollDOM.clientHeight < view.scrollDOM.scrollHeight - 2; + let marginTop = 0, marginBottom = 0, height; + if (selfScroll) { + for (let source of view.state.facet(EditorView.scrollMargins)) { + let margins = source(view); + if (margins === null || margins === void 0 ? void 0 : margins.top) + marginTop = Math.max(margins === null || margins === void 0 ? void 0 : margins.top, marginTop); + if (margins === null || margins === void 0 ? void 0 : margins.bottom) + marginBottom = Math.max(margins === null || margins === void 0 ? void 0 : margins.bottom, marginBottom); + } + height = view.scrollDOM.clientHeight - marginTop - marginBottom; + } + else { + height = (view.dom.ownerDocument.defaultView || window).innerHeight; + } + return { marginTop, marginBottom, selfScroll, + height: Math.max(view.defaultLineHeight, height - 5) }; +} +function cursorByPage(view, forward) { + let page = pageInfo(view); + let { state } = view, selection = updateSel(state.selection, range => { + return range.empty ? view.moveVertically(range, forward, page.height) + : rangeEnd(range, forward); + }); + if (selection.eq(state.selection)) + return false; + let effect; + if (page.selfScroll) { + let startPos = view.coordsAtPos(state.selection.main.head); + let scrollRect = view.scrollDOM.getBoundingClientRect(); + let scrollTop = scrollRect.top + page.marginTop, scrollBottom = scrollRect.bottom - page.marginBottom; + if (startPos && startPos.top > scrollTop && startPos.bottom < scrollBottom) + effect = EditorView.scrollIntoView(selection.main.head, { y: "start", yMargin: startPos.top - scrollTop }); + } + view.dispatch(setSel(state, selection), { effects: effect }); + return true; +} +/** +Move the selection one page up. +*/ +const cursorPageUp = view => cursorByPage(view, false); +/** +Move the selection one page down. +*/ +const cursorPageDown = view => cursorByPage(view, true); +function moveByLineBoundary(view, start, forward) { + let line = view.lineBlockAt(start.head), moved = view.moveToLineBoundary(start, forward); + if (moved.head == start.head && moved.head != (forward ? line.to : line.from)) + moved = view.moveToLineBoundary(start, forward, false); + if (!forward && moved.head == line.from && line.length) { + let space = /^\s*/.exec(view.state.sliceDoc(line.from, Math.min(line.from + 100, line.to)))[0].length; + if (space && start.head != line.from + space) + moved = EditorSelection.cursor(line.from + space); + } + return moved; +} +/** +Move the selection to the next line wrap point, or to the end of +the line if there isn't one left on this line. +*/ +const cursorLineBoundaryForward = view => moveSel(view, range => moveByLineBoundary(view, range, true)); +/** +Move the selection to previous line wrap point, or failing that to +the start of the line. If the line is indented, and the cursor +isn't already at the end of the indentation, this will move to the +end of the indentation instead of the start of the line. +*/ +const cursorLineBoundaryBackward = view => moveSel(view, range => moveByLineBoundary(view, range, false)); +/** +Move the selection one line wrap point to the left. +*/ +const cursorLineBoundaryLeft = view => moveSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view))); +/** +Move the selection one line wrap point to the right. +*/ +const cursorLineBoundaryRight = view => moveSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view))); +/** +Move the selection to the start of the line. +*/ +const cursorLineStart = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1)); +/** +Move the selection to the end of the line. +*/ +const cursorLineEnd = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to, -1)); +function toMatchingBracket(state, dispatch, extend) { + let found = false, selection = updateSel(state.selection, range => { + let matching = matchBrackets(state, range.head, -1) + || matchBrackets(state, range.head, 1) + || (range.head > 0 && matchBrackets(state, range.head - 1, 1)) + || (range.head < state.doc.length && matchBrackets(state, range.head + 1, -1)); + if (!matching || !matching.end) + return range; + found = true; + let head = matching.start.from == range.head ? matching.end.to : matching.end.from; + return EditorSelection.cursor(head); + }); + if (!found) + return false; + dispatch(setSel(state, selection)); + return true; +} +/** +Move the selection to the bracket matching the one it is currently +on, if any. +*/ +const cursorMatchingBracket = ({ state, dispatch }) => toMatchingBracket(state, dispatch); +function extendSel(view, how) { + let selection = updateSel(view.state.selection, range => { + let head = how(range); + return EditorSelection.range(range.anchor, head.head, head.goalColumn, head.bidiLevel || undefined); + }); + if (selection.eq(view.state.selection)) + return false; + view.dispatch(setSel(view.state, selection)); + return true; +} +function selectByChar(view, forward) { + return extendSel(view, range => view.moveByChar(range, forward)); +} +/** +Move the selection head one character to the left, while leaving +the anchor in place. +*/ +const selectCharLeft = view => selectByChar(view, !ltrAtCursor(view)); +/** +Move the selection head one character to the right. +*/ +const selectCharRight = view => selectByChar(view, ltrAtCursor(view)); +function selectByGroup(view, forward) { + return extendSel(view, range => view.moveByGroup(range, forward)); +} +/** +Move the selection head one [group](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) to +the left. +*/ +const selectGroupLeft = view => selectByGroup(view, !ltrAtCursor(view)); +/** +Move the selection head one group to the right. +*/ +const selectGroupRight = view => selectByGroup(view, ltrAtCursor(view)); +/** +Move the selection head over the next syntactic element to the left. +*/ +const selectSyntaxLeft = view => extendSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view))); +/** +Move the selection head over the next syntactic element to the right. +*/ +const selectSyntaxRight = view => extendSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view))); +function selectByLine(view, forward) { + return extendSel(view, range => view.moveVertically(range, forward)); +} +/** +Move the selection head one line up. +*/ +const selectLineUp = view => selectByLine(view, false); +/** +Move the selection head one line down. +*/ +const selectLineDown = view => selectByLine(view, true); +function selectByPage(view, forward) { + return extendSel(view, range => view.moveVertically(range, forward, pageInfo(view).height)); +} +/** +Move the selection head one page up. +*/ +const selectPageUp = view => selectByPage(view, false); +/** +Move the selection head one page down. +*/ +const selectPageDown = view => selectByPage(view, true); +/** +Move the selection head to the next line boundary. +*/ +const selectLineBoundaryForward = view => extendSel(view, range => moveByLineBoundary(view, range, true)); +/** +Move the selection head to the previous line boundary. +*/ +const selectLineBoundaryBackward = view => extendSel(view, range => moveByLineBoundary(view, range, false)); +/** +Move the selection head one line boundary to the left. +*/ +const selectLineBoundaryLeft = view => extendSel(view, range => moveByLineBoundary(view, range, !ltrAtCursor(view))); +/** +Move the selection head one line boundary to the right. +*/ +const selectLineBoundaryRight = view => extendSel(view, range => moveByLineBoundary(view, range, ltrAtCursor(view))); +/** +Move the selection head to the start of the line. +*/ +const selectLineStart = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from)); +/** +Move the selection head to the end of the line. +*/ +const selectLineEnd = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to)); +/** +Move the selection to the start of the document. +*/ +const cursorDocStart = ({ state, dispatch }) => { + dispatch(setSel(state, { anchor: 0 })); + return true; +}; +/** +Move the selection to the end of the document. +*/ +const cursorDocEnd = ({ state, dispatch }) => { + dispatch(setSel(state, { anchor: state.doc.length })); + return true; +}; +/** +Move the selection head to the start of the document. +*/ +const selectDocStart = ({ state, dispatch }) => { + dispatch(setSel(state, { anchor: state.selection.main.anchor, head: 0 })); + return true; +}; +/** +Move the selection head to the end of the document. +*/ +const selectDocEnd = ({ state, dispatch }) => { + dispatch(setSel(state, { anchor: state.selection.main.anchor, head: state.doc.length })); + return true; +}; +/** +Select the entire document. +*/ +const selectAll = ({ state, dispatch }) => { + dispatch(state.update({ selection: { anchor: 0, head: state.doc.length }, userEvent: "select" })); + return true; +}; +/** +Expand the selection to cover entire lines. +*/ +const selectLine = ({ state, dispatch }) => { + let ranges = selectedLineBlocks(state).map(({ from, to }) => EditorSelection.range(from, Math.min(to + 1, state.doc.length))); + dispatch(state.update({ selection: EditorSelection.create(ranges), userEvent: "select" })); + return true; +}; +/** +Select the next syntactic construct that is larger than the +selection. Note that this will only work insofar as the language +[provider](https://codemirror.net/6/docs/ref/#language.language) you use builds up a full +syntax tree. +*/ +const selectParentSyntax = ({ state, dispatch }) => { + let selection = updateSel(state.selection, range => { + var _a; + let stack = syntaxTree(state).resolveStack(range.from, 1); + for (let cur = stack; cur; cur = cur.next) { + let { node } = cur; + if (((node.from < range.from && node.to >= range.to) || + (node.to > range.to && node.from <= range.from)) && + ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent)) + return EditorSelection.range(node.to, node.from); + } + return range; + }); + dispatch(setSel(state, selection)); + return true; +}; +/** +Simplify the current selection. When multiple ranges are selected, +reduce it to its main range. Otherwise, if the selection is +non-empty, convert it to a cursor selection. +*/ +const simplifySelection = ({ state, dispatch }) => { + let cur = state.selection, selection = null; + if (cur.ranges.length > 1) + selection = EditorSelection.create([cur.main]); + else if (!cur.main.empty) + selection = EditorSelection.create([EditorSelection.cursor(cur.main.head)]); + if (!selection) + return false; + dispatch(setSel(state, selection)); + return true; +}; +function deleteBy(target, by) { + if (target.state.readOnly) + return false; + let event = "delete.selection", { state } = target; + let changes = state.changeByRange(range => { + let { from, to } = range; + if (from == to) { + let towards = by(range); + if (towards < from) { + event = "delete.backward"; + towards = skipAtomic(target, towards, false); + } + else if (towards > from) { + event = "delete.forward"; + towards = skipAtomic(target, towards, true); + } + from = Math.min(from, towards); + to = Math.max(to, towards); + } + else { + from = skipAtomic(target, from, false); + to = skipAtomic(target, to, true); + } + return from == to ? { range } : { changes: { from, to }, range: EditorSelection.cursor(from, from < range.head ? -1 : 1) }; + }); + if (changes.changes.empty) + return false; + target.dispatch(state.update(changes, { + scrollIntoView: true, + userEvent: event, + effects: event == "delete.selection" ? EditorView.announce.of(state.phrase("Selection deleted")) : undefined + })); + return true; +} +function skipAtomic(target, pos, forward) { + if (target instanceof EditorView) + for (let ranges of target.state.facet(EditorView.atomicRanges).map(f => f(target))) + ranges.between(pos, pos, (from, to) => { + if (from < pos && to > pos) + pos = forward ? to : from; + }); + return pos; +} +const deleteByChar = (target, forward, byIndentUnit) => deleteBy(target, range => { + let pos = range.from, { state } = target, line = state.doc.lineAt(pos), before, targetPos; + if (byIndentUnit && !forward && pos > line.from && pos < line.from + 200 && + !/[^ \t]/.test(before = line.text.slice(0, pos - line.from))) { + if (before[before.length - 1] == "\t") + return pos - 1; + let col = countColumn(before, state.tabSize), drop = col % getIndentUnit(state) || getIndentUnit(state); + for (let i = 0; i < drop && before[before.length - 1 - i] == " "; i++) + pos--; + targetPos = pos; + } + else { + targetPos = findClusterBreak(line.text, pos - line.from, forward, forward) + line.from; + if (targetPos == pos && line.number != (forward ? state.doc.lines : 1)) + targetPos += forward ? 1 : -1; + else if (!forward && /[\ufe00-\ufe0f]/.test(line.text.slice(targetPos - line.from, pos - line.from))) + targetPos = findClusterBreak(line.text, targetPos - line.from, false, false) + line.from; + } + return targetPos; +}); +/** +Delete the selection, or, for cursor selections, the character or +indentation unit before the cursor. +*/ +const deleteCharBackward = view => deleteByChar(view, false, true); +/** +Delete the selection or the character after the cursor. +*/ +const deleteCharForward = view => deleteByChar(view, true, false); +const deleteByGroup = (target, forward) => deleteBy(target, range => { + let pos = range.head, { state } = target, line = state.doc.lineAt(pos); + let categorize = state.charCategorizer(pos); + for (let cat = null;;) { + if (pos == (forward ? line.to : line.from)) { + if (pos == range.head && line.number != (forward ? state.doc.lines : 1)) + pos += forward ? 1 : -1; + break; + } + let next = findClusterBreak(line.text, pos - line.from, forward) + line.from; + let nextChar = line.text.slice(Math.min(pos, next) - line.from, Math.max(pos, next) - line.from); + let nextCat = categorize(nextChar); + if (cat != null && nextCat != cat) + break; + if (nextChar != " " || pos != range.head) + cat = nextCat; + pos = next; + } + return pos; +}); +/** +Delete the selection or backward until the end of the next +[group](https://codemirror.net/6/docs/ref/#view.EditorView.moveByGroup), only skipping groups of +whitespace when they consist of a single space. +*/ +const deleteGroupBackward = target => deleteByGroup(target, false); +/** +Delete the selection or forward until the end of the next group. +*/ +const deleteGroupForward = target => deleteByGroup(target, true); +/** +Delete the selection, or, if it is a cursor selection, delete to +the end of the line. If the cursor is directly at the end of the +line, delete the line break after it. +*/ +const deleteToLineEnd = view => deleteBy(view, range => { + let lineEnd = view.lineBlockAt(range.head).to; + return range.head < lineEnd ? lineEnd : Math.min(view.state.doc.length, range.head + 1); +}); +/** +Delete the selection, or, if it is a cursor selection, delete to +the start of the line or the next line wrap before the cursor. +*/ +const deleteLineBoundaryBackward = view => deleteBy(view, range => { + let lineStart = view.moveToLineBoundary(range, false).head; + return range.head > lineStart ? lineStart : Math.max(0, range.head - 1); +}); +/** +Delete the selection, or, if it is a cursor selection, delete to +the end of the line or the next line wrap after the cursor. +*/ +const deleteLineBoundaryForward = view => deleteBy(view, range => { + let lineStart = view.moveToLineBoundary(range, true).head; + return range.head < lineStart ? lineStart : Math.min(view.state.doc.length, range.head + 1); +}); +/** +Replace each selection range with a line break, leaving the cursor +on the line before the break. +*/ +const splitLine = ({ state, dispatch }) => { + if (state.readOnly) + return false; + let changes = state.changeByRange(range => { + return { changes: { from: range.from, to: range.to, insert: Text.of(["", ""]) }, + range: EditorSelection.cursor(range.from) }; + }); + dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" })); + return true; +}; +/** +Flip the characters before and after the cursor(s). +*/ +const transposeChars = ({ state, dispatch }) => { + if (state.readOnly) + return false; + let changes = state.changeByRange(range => { + if (!range.empty || range.from == 0 || range.from == state.doc.length) + return { range }; + let pos = range.from, line = state.doc.lineAt(pos); + let from = pos == line.from ? pos - 1 : findClusterBreak(line.text, pos - line.from, false) + line.from; + let to = pos == line.to ? pos + 1 : findClusterBreak(line.text, pos - line.from, true) + line.from; + return { changes: { from, to, insert: state.doc.slice(pos, to).append(state.doc.slice(from, pos)) }, + range: EditorSelection.cursor(to) }; + }); + if (changes.changes.empty) + return false; + dispatch(state.update(changes, { scrollIntoView: true, userEvent: "move.character" })); + return true; +}; +function selectedLineBlocks(state) { + let blocks = [], upto = -1; + for (let range of state.selection.ranges) { + let startLine = state.doc.lineAt(range.from), endLine = state.doc.lineAt(range.to); + if (!range.empty && range.to == endLine.from) + endLine = state.doc.lineAt(range.to - 1); + if (upto >= startLine.number) { + let prev = blocks[blocks.length - 1]; + prev.to = endLine.to; + prev.ranges.push(range); + } + else { + blocks.push({ from: startLine.from, to: endLine.to, ranges: [range] }); + } + upto = endLine.number + 1; + } + return blocks; +} +function moveLine(state, dispatch, forward) { + if (state.readOnly) + return false; + let changes = [], ranges = []; + for (let block of selectedLineBlocks(state)) { + if (forward ? block.to == state.doc.length : block.from == 0) + continue; + let nextLine = state.doc.lineAt(forward ? block.to + 1 : block.from - 1); + let size = nextLine.length + 1; + if (forward) { + changes.push({ from: block.to, to: nextLine.to }, { from: block.from, insert: nextLine.text + state.lineBreak }); + for (let r of block.ranges) + ranges.push(EditorSelection.range(Math.min(state.doc.length, r.anchor + size), Math.min(state.doc.length, r.head + size))); + } + else { + changes.push({ from: nextLine.from, to: block.from }, { from: block.to, insert: state.lineBreak + nextLine.text }); + for (let r of block.ranges) + ranges.push(EditorSelection.range(r.anchor - size, r.head - size)); + } + } + if (!changes.length) + return false; + dispatch(state.update({ + changes, + scrollIntoView: true, + selection: EditorSelection.create(ranges, state.selection.mainIndex), + userEvent: "move.line" + })); + return true; +} +/** +Move the selected lines up one line. +*/ +const moveLineUp = ({ state, dispatch }) => moveLine(state, dispatch, false); +/** +Move the selected lines down one line. +*/ +const moveLineDown = ({ state, dispatch }) => moveLine(state, dispatch, true); +function copyLine(state, dispatch, forward) { + if (state.readOnly) + return false; + let changes = []; + for (let block of selectedLineBlocks(state)) { + if (forward) + changes.push({ from: block.from, insert: state.doc.slice(block.from, block.to) + state.lineBreak }); + else + changes.push({ from: block.to, insert: state.lineBreak + state.doc.slice(block.from, block.to) }); + } + dispatch(state.update({ changes, scrollIntoView: true, userEvent: "input.copyline" })); + return true; +} +/** +Create a copy of the selected lines. Keep the selection in the top copy. +*/ +const copyLineUp = ({ state, dispatch }) => copyLine(state, dispatch, false); +/** +Create a copy of the selected lines. Keep the selection in the bottom copy. +*/ +const copyLineDown = ({ state, dispatch }) => copyLine(state, dispatch, true); +/** +Delete selected lines. +*/ +const deleteLine = view => { + if (view.state.readOnly) + return false; + let { state } = view, changes = state.changes(selectedLineBlocks(state).map(({ from, to }) => { + if (from > 0) + from--; + else if (to < state.doc.length) + to++; + return { from, to }; + })); + let selection = updateSel(state.selection, range => { + let dist = undefined; + if (view.lineWrapping) { + let block = view.lineBlockAt(range.head), pos = view.coordsAtPos(range.head, range.assoc || 1); + if (pos) + dist = (block.bottom + view.documentTop) - pos.bottom + view.defaultLineHeight / 2; + } + return view.moveVertically(range, true, dist); + }).map(changes); + view.dispatch({ changes, selection, scrollIntoView: true, userEvent: "delete.line" }); + return true; +}; +function isBetweenBrackets(state, pos) { + if (/\(\)|\[\]|\{\}/.test(state.sliceDoc(pos - 1, pos + 1))) + return { from: pos, to: pos }; + let context = syntaxTree(state).resolveInner(pos); + let before = context.childBefore(pos), after = context.childAfter(pos), closedBy; + if (before && after && before.to <= pos && after.from >= pos && + (closedBy = before.type.prop(NodeProp.closedBy)) && closedBy.indexOf(after.name) > -1 && + state.doc.lineAt(before.to).from == state.doc.lineAt(after.from).from && + !/\S/.test(state.sliceDoc(before.to, after.from))) + return { from: before.to, to: after.from }; + return null; +} +/** +Replace the selection with a newline and indent the newly created +line(s). If the current line consists only of whitespace, this +will also delete that whitespace. When the cursor is between +matching brackets, an additional newline will be inserted after +the cursor. +*/ +const insertNewlineAndIndent = /*@__PURE__*/newlineAndIndent(false); +/** +Create a blank, indented line below the current line. +*/ +const insertBlankLine = /*@__PURE__*/newlineAndIndent(true); +function newlineAndIndent(atEof) { + return ({ state, dispatch }) => { + if (state.readOnly) + return false; + let changes = state.changeByRange(range => { + let { from, to } = range, line = state.doc.lineAt(from); + let explode = !atEof && from == to && isBetweenBrackets(state, from); + if (atEof) + from = to = (to <= line.to ? line : state.doc.lineAt(to)).to; + let cx = new IndentContext(state, { simulateBreak: from, simulateDoubleBreak: !!explode }); + let indent = getIndentation(cx, from); + if (indent == null) + indent = countColumn(/^\s*/.exec(state.doc.lineAt(from).text)[0], state.tabSize); + while (to < line.to && /\s/.test(line.text[to - line.from])) + to++; + if (explode) + ({ from, to } = explode); + else if (from > line.from && from < line.from + 100 && !/\S/.test(line.text.slice(0, from))) + from = line.from; + let insert = ["", indentString(state, indent)]; + if (explode) + insert.push(indentString(state, cx.lineIndent(line.from, -1))); + return { changes: { from, to, insert: Text.of(insert) }, + range: EditorSelection.cursor(from + 1 + insert[1].length) }; + }); + dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" })); + return true; + }; +} +function changeBySelectedLine(state, f) { + let atLine = -1; + return state.changeByRange(range => { + let changes = []; + for (let pos = range.from; pos <= range.to;) { + let line = state.doc.lineAt(pos); + if (line.number > atLine && (range.empty || range.to > line.from)) { + f(line, changes, range); + atLine = line.number; + } + pos = line.to + 1; } - }, - "&light .cm-searchMatch": { backgroundColor: "#ffff0054" }, - "&dark .cm-searchMatch": { backgroundColor: "#00ffff8a" }, - "&light .cm-searchMatch-selected": { backgroundColor: "#ff6a0054" }, - "&dark .cm-searchMatch-selected": { backgroundColor: "#ff00ff8a" } -}); -const searchExtensions = [ - searchState, - /*@__PURE__*/Prec.low(searchHighlighter), - baseTheme$2 + let changeSet = state.changes(changes); + return { changes, + range: EditorSelection.range(changeSet.mapPos(range.anchor, 1), changeSet.mapPos(range.head, 1)) }; + }); +} +/** +Auto-indent the selected lines. This uses the [indentation service +facet](https://codemirror.net/6/docs/ref/#language.indentService) as source for auto-indent +information. +*/ +const indentSelection = ({ state, dispatch }) => { + if (state.readOnly) + return false; + let updated = Object.create(null); + let context = new IndentContext(state, { overrideIndentation: start => { + let found = updated[start]; + return found == null ? -1 : found; + } }); + let changes = changeBySelectedLine(state, (line, changes, range) => { + let indent = getIndentation(context, line.from); + if (indent == null) + return; + if (!/\S/.test(line.text)) + indent = 0; + let cur = /^\s*/.exec(line.text)[0]; + let norm = indentString(state, indent); + if (cur != norm || range.from < line.from + cur.length) { + updated[line.from] = indent; + changes.push({ from: line.from, to: line.from + cur.length, insert: norm }); + } + }); + if (!changes.changes.empty) + dispatch(state.update(changes, { userEvent: "indent" })); + return true; +}; +/** +Add a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation to all selected +lines. +*/ +const indentMore = ({ state, dispatch }) => { + if (state.readOnly) + return false; + dispatch(state.update(changeBySelectedLine(state, (line, changes) => { + changes.push({ from: line.from, insert: state.facet(indentUnit) }); + }), { userEvent: "input.indent" })); + return true; +}; +/** +Remove a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation from all +selected lines. +*/ +const indentLess = ({ state, dispatch }) => { + if (state.readOnly) + return false; + dispatch(state.update(changeBySelectedLine(state, (line, changes) => { + let space = /^\s*/.exec(line.text)[0]; + if (!space) + return; + let col = countColumn(space, state.tabSize), keep = 0; + let insert = indentString(state, Math.max(0, col - getIndentUnit(state))); + while (keep < space.length && keep < insert.length && space.charCodeAt(keep) == insert.charCodeAt(keep)) + keep++; + changes.push({ from: line.from + keep, to: line.from + space.length, insert: insert.slice(keep) }); + }), { userEvent: "delete.dedent" })); + return true; +}; +/** +Enables or disables +[tab-focus mode](https://codemirror.net/6/docs/ref/#view.EditorView.setTabFocusMode). While on, this +prevents the editor's key bindings from capturing Tab or +Shift-Tab, making it possible for the user to move focus out of +the editor with the keyboard. +*/ +const toggleTabFocusMode = view => { + view.setTabFocusMode(); + return true; +}; +/** +Array of key bindings containing the Emacs-style bindings that are +available on macOS by default. + + - Ctrl-b: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift) + - Ctrl-f: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift) + - Ctrl-p: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift) + - Ctrl-n: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift) + - Ctrl-a: [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift) + - Ctrl-e: [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift) + - Ctrl-d: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward) + - Ctrl-h: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward) + - Ctrl-k: [`deleteToLineEnd`](https://codemirror.net/6/docs/ref/#commands.deleteToLineEnd) + - Ctrl-Alt-h: [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward) + - Ctrl-o: [`splitLine`](https://codemirror.net/6/docs/ref/#commands.splitLine) + - Ctrl-t: [`transposeChars`](https://codemirror.net/6/docs/ref/#commands.transposeChars) + - Ctrl-v: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) + - Alt-v: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) +*/ +const emacsStyleKeymap = [ + { key: "Ctrl-b", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true }, + { key: "Ctrl-f", run: cursorCharRight, shift: selectCharRight }, + { key: "Ctrl-p", run: cursorLineUp, shift: selectLineUp }, + { key: "Ctrl-n", run: cursorLineDown, shift: selectLineDown }, + { key: "Ctrl-a", run: cursorLineStart, shift: selectLineStart }, + { key: "Ctrl-e", run: cursorLineEnd, shift: selectLineEnd }, + { key: "Ctrl-d", run: deleteCharForward }, + { key: "Ctrl-h", run: deleteCharBackward }, + { key: "Ctrl-k", run: deleteToLineEnd }, + { key: "Ctrl-Alt-h", run: deleteGroupBackward }, + { key: "Ctrl-o", run: splitLine }, + { key: "Ctrl-t", run: transposeChars }, + { key: "Ctrl-v", run: cursorPageDown }, ]; +/** +An array of key bindings closely sticking to platform-standard or +widely used bindings. (This includes the bindings from +[`emacsStyleKeymap`](https://codemirror.net/6/docs/ref/#commands.emacsStyleKeymap), with their `key` +property changed to `mac`.) + + - ArrowLeft: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift) + - ArrowRight: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift) + - Ctrl-ArrowLeft (Alt-ArrowLeft on macOS): [`cursorGroupLeft`](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) ([`selectGroupLeft`](https://codemirror.net/6/docs/ref/#commands.selectGroupLeft) with Shift) + - Ctrl-ArrowRight (Alt-ArrowRight on macOS): [`cursorGroupRight`](https://codemirror.net/6/docs/ref/#commands.cursorGroupRight) ([`selectGroupRight`](https://codemirror.net/6/docs/ref/#commands.selectGroupRight) with Shift) + - Cmd-ArrowLeft (on macOS): [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift) + - Cmd-ArrowRight (on macOS): [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift) + - ArrowUp: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift) + - ArrowDown: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift) + - Cmd-ArrowUp (on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift) + - Cmd-ArrowDown (on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift) + - Ctrl-ArrowUp (on macOS): [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift) + - Ctrl-ArrowDown (on macOS): [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift) + - PageUp: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift) + - PageDown: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift) + - Home: [`cursorLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryBackward) ([`selectLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryBackward) with Shift) + - End: [`cursorLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryForward) ([`selectLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryForward) with Shift) + - Ctrl-Home (Cmd-Home on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift) + - Ctrl-End (Cmd-Home on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift) + - Enter: [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent) + - Ctrl-a (Cmd-a on macOS): [`selectAll`](https://codemirror.net/6/docs/ref/#commands.selectAll) + - Backspace: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward) + - Delete: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward) + - Ctrl-Backspace (Alt-Backspace on macOS): [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward) + - Ctrl-Delete (Alt-Delete on macOS): [`deleteGroupForward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupForward) + - Cmd-Backspace (macOS): [`deleteLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.deleteLineBoundaryBackward). + - Cmd-Delete (macOS): [`deleteLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.deleteLineBoundaryForward). +*/ +const standardKeymap = /*@__PURE__*/[ + { key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true }, + { key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft, preventDefault: true }, + { mac: "Cmd-ArrowLeft", run: cursorLineBoundaryLeft, shift: selectLineBoundaryLeft, preventDefault: true }, + { key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true }, + { key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight, preventDefault: true }, + { mac: "Cmd-ArrowRight", run: cursorLineBoundaryRight, shift: selectLineBoundaryRight, preventDefault: true }, + { key: "ArrowUp", run: cursorLineUp, shift: selectLineUp, preventDefault: true }, + { mac: "Cmd-ArrowUp", run: cursorDocStart, shift: selectDocStart }, + { mac: "Ctrl-ArrowUp", run: cursorPageUp, shift: selectPageUp }, + { key: "ArrowDown", run: cursorLineDown, shift: selectLineDown, preventDefault: true }, + { mac: "Cmd-ArrowDown", run: cursorDocEnd, shift: selectDocEnd }, + { mac: "Ctrl-ArrowDown", run: cursorPageDown, shift: selectPageDown }, + { key: "PageUp", run: cursorPageUp, shift: selectPageUp }, + { key: "PageDown", run: cursorPageDown, shift: selectPageDown }, + { key: "Home", run: cursorLineBoundaryBackward, shift: selectLineBoundaryBackward, preventDefault: true }, + { key: "Mod-Home", run: cursorDocStart, shift: selectDocStart }, + { key: "End", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward, preventDefault: true }, + { key: "Mod-End", run: cursorDocEnd, shift: selectDocEnd }, + { key: "Enter", run: insertNewlineAndIndent }, + { key: "Mod-a", run: selectAll }, + { key: "Backspace", run: deleteCharBackward, shift: deleteCharBackward }, + { key: "Delete", run: deleteCharForward }, + { key: "Mod-Backspace", mac: "Alt-Backspace", run: deleteGroupBackward }, + { key: "Mod-Delete", mac: "Alt-Delete", run: deleteGroupForward }, + { mac: "Mod-Backspace", run: deleteLineBoundaryBackward }, + { mac: "Mod-Delete", run: deleteLineBoundaryForward } +].concat(/*@__PURE__*/emacsStyleKeymap.map(b => ({ mac: b.key, run: b.run, shift: b.shift }))); +/** +The default keymap. Includes all bindings from +[`standardKeymap`](https://codemirror.net/6/docs/ref/#commands.standardKeymap) plus the following: + +- Alt-ArrowLeft (Ctrl-ArrowLeft on macOS): [`cursorSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxLeft) ([`selectSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxLeft) with Shift) +- Alt-ArrowRight (Ctrl-ArrowRight on macOS): [`cursorSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxRight) ([`selectSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxRight) with Shift) +- Alt-ArrowUp: [`moveLineUp`](https://codemirror.net/6/docs/ref/#commands.moveLineUp) +- Alt-ArrowDown: [`moveLineDown`](https://codemirror.net/6/docs/ref/#commands.moveLineDown) +- Shift-Alt-ArrowUp: [`copyLineUp`](https://codemirror.net/6/docs/ref/#commands.copyLineUp) +- Shift-Alt-ArrowDown: [`copyLineDown`](https://codemirror.net/6/docs/ref/#commands.copyLineDown) +- Escape: [`simplifySelection`](https://codemirror.net/6/docs/ref/#commands.simplifySelection) +- Ctrl-Enter (Cmd-Enter on macOS): [`insertBlankLine`](https://codemirror.net/6/docs/ref/#commands.insertBlankLine) +- Alt-l (Ctrl-l on macOS): [`selectLine`](https://codemirror.net/6/docs/ref/#commands.selectLine) +- Ctrl-i (Cmd-i on macOS): [`selectParentSyntax`](https://codemirror.net/6/docs/ref/#commands.selectParentSyntax) +- Ctrl-[ (Cmd-[ on macOS): [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess) +- Ctrl-] (Cmd-] on macOS): [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore) +- Ctrl-Alt-\\ (Cmd-Alt-\\ on macOS): [`indentSelection`](https://codemirror.net/6/docs/ref/#commands.indentSelection) +- Shift-Ctrl-k (Shift-Cmd-k on macOS): [`deleteLine`](https://codemirror.net/6/docs/ref/#commands.deleteLine) +- Shift-Ctrl-\\ (Shift-Cmd-\\ on macOS): [`cursorMatchingBracket`](https://codemirror.net/6/docs/ref/#commands.cursorMatchingBracket) +- Ctrl-/ (Cmd-/ on macOS): [`toggleComment`](https://codemirror.net/6/docs/ref/#commands.toggleComment). +- Shift-Alt-a: [`toggleBlockComment`](https://codemirror.net/6/docs/ref/#commands.toggleBlockComment). +- Ctrl-m (Alt-Shift-m on macOS): [`toggleTabFocusMode`](https://codemirror.net/6/docs/ref/#commands.toggleTabFocusMode). +*/ +const defaultKeymap = /*@__PURE__*/[ + { key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: cursorSyntaxLeft, shift: selectSyntaxLeft }, + { key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: cursorSyntaxRight, shift: selectSyntaxRight }, + { key: "Alt-ArrowUp", run: moveLineUp }, + { key: "Shift-Alt-ArrowUp", run: copyLineUp }, + { key: "Alt-ArrowDown", run: moveLineDown }, + { key: "Shift-Alt-ArrowDown", run: copyLineDown }, + { key: "Escape", run: simplifySelection }, + { key: "Mod-Enter", run: insertBlankLine }, + { key: "Alt-l", mac: "Ctrl-l", run: selectLine }, + { key: "Mod-i", run: selectParentSyntax, preventDefault: true }, + { key: "Mod-[", run: indentLess }, + { key: "Mod-]", run: indentMore }, + { key: "Mod-Alt-\\", run: indentSelection }, + { key: "Shift-Mod-k", run: deleteLine }, + { key: "Shift-Mod-\\", run: cursorMatchingBracket }, + { key: "Mod-/", run: toggleComment }, + { key: "Alt-A", run: toggleBlockComment }, + { key: "Ctrl-m", mac: "Shift-Alt-m", run: toggleTabFocusMode }, +].concat(standardKeymap); class SelectedDiagnostic { constructor(from, to, diagnostic) { @@ -33036,6 +33045,7 @@ async function makeCodeMirrorEditor(parent, filename) { themeConfig.of([getCodeMirrorTheme()]), EditorView.lineWrapping, javascript(), + search({ top: true }), readOnly, ], parent, diff --git a/main.js.map b/main.js.map index 16005bc8..f7c5d687 100644 --- a/main.js.map +++ b/main.js.map @@ -1 +1 @@ -{"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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