@pierre/diffs 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/File.d.ts +1 -0
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +18 -9
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +4 -0
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +48 -21
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +1 -0
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +3 -0
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +1 -0
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +3 -0
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/edit/index.d.ts +3 -3
- package/dist/editor/command.js +2 -1
- package/dist/editor/command.js.map +1 -1
- package/dist/editor/editStack.d.ts +2 -2
- package/dist/editor/editStack.d.ts.map +1 -1
- package/dist/editor/editStack.js.map +1 -1
- package/dist/editor/editor.d.ts +2 -2
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +26 -7
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/pieceTable.d.ts +1 -2
- package/dist/editor/pieceTable.d.ts.map +1 -1
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/platform.d.ts +3 -11
- package/dist/editor/platform.d.ts.map +1 -1
- package/dist/editor/platform.js +2 -28
- package/dist/editor/platform.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +2 -1
- package/dist/editor/searchPanel.d.ts.map +1 -1
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +2 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/textDocument.d.ts +4 -14
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +7 -0
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/ssr/index.d.ts +2 -2
- package/dist/types.d.ts +22 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/guardWebKitScrollDuringRebuild.d.ts +20 -0
- package/dist/utils/guardWebKitScrollDuringRebuild.d.ts.map +1 -0
- package/dist/utils/guardWebKitScrollDuringRebuild.js +34 -0
- package/dist/utils/guardWebKitScrollDuringRebuild.js.map +1 -0
- package/dist/utils/platform.d.ts +14 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +32 -0
- package/dist/utils/platform.js.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pieceTable.d.ts","names":[],"sources":["../../src/editor/pieceTable.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"pieceTable.d.ts","names":[],"sources":["../../src/editor/pieceTable.ts"],"mappings":";;;;;;AAqHA;;;;;;;cAAa,UAAA;EAAA;EAiBX,WAAA,CAAY,YAAA;EAAA,IAQR,SAAA;EAIJ,OAAA,CAAQ,KAAA,GAAQ,KAAA;EAShB,WAAA,CAAY,IAAA,UAAc,gBAAA;EAkB1B,aAAA,CAAc,IAAA,UAAc,gBAAA;EAqC5B,YAAA,CAAa,KAAA,UAAe,GAAA,UAAa,OAAA;EAsCzC,MAAA,CAAO,MAAA;EAWP,QAAA,CAAS,MAAA;EA2BT,+BAAA,CACE,MAAA,UACA,QAAA,YAAoB,KAAA,UAAe,GAAA;EA0CrC,MAAA,CAAO,YAAA,EAAc,YAAA,IAAgB,KAAA,UAAe,GAAA;EAsFpD,MAAA,CAAO,IAAA,UAAc,MAAA;EASrB,MAAA,CAAO,MAAA,UAAgB,MAAA;EAavB,UAAA,CAAW,KAAA,WAAgB,gBAAA;EAiB3B,UAAA,CAAW,MAAA,WAAiB,QAAA;EAY5B,WAAA,CAAY,OAAA,sBAA6B,QAAA;EAgBzC,QAAA,CAAS,QAAA,EAAU,QAAA;AAAA;;;;;iBA6qBL,0BAAA,CACd,UAAA,GAAa,MAAA,aAAmB,QAAA,EAChC,QAAA,GAAW,QAAA,EAAU,QAAA,aACrB,WAAA,GAAc,IAAA,qBACd,YAAA,EAAc,YAAA,EACd,UAAA,UACA,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pieceTable.js","names":["#original","#createPiece","#root","#createNode","#length","#lineCount","#textFromPieces","#lastVisitedLine","#getLineOffset","#lastVisitedLineLength","#findPieceAtOffset","#bufferFor","#nextNode","#forEachPieceSegment","#collectSearchMatchesLineByLine","#replaceRangeIncremental","#invalidateCaches","#lineAtOffset","#lineBreakOffset","#lastPosition","#pieceLineBreakOffset","#walk","#add","#split","#dropPrefix","#mergeNodes","#appendCoalescing","#popLeftmost","#priorityState","#nextPriority","#setLeft","#setRight"],"sources":["../../src/editor/pieceTable.ts"],"sourcesContent":["import type { Position, Range } from '../types';\nimport { computeLineOffsets } from '../utils/computeFileOffsets';\nimport type { SearchParams } from './searchPanel';\nimport type { ResolvedTextEdit } from './textDocument';\n\nconst MAX_FIND_MATCHES = 100000;\nconst LINE_FEED = 10;\nconst CARRIAGE_RETURN = 13;\n// TODO(ije): use Intl.Segmenter instead of regex for word separators\nconst WORD_SEPARATORS = '`~!@#$%^&*()-=+[{]}\\\\|;:\\'\",.<>/?' as const;\n\n// A piece is a segment of text that is either original or added.\nclass Piece {\n static Original = 0;\n static Added = 1;\n\n constructor(\n public readonly source: number,\n public readonly offset: number,\n public readonly length: number,\n public readonly lineOffsetStart: number,\n public readonly lineOffsetEnd: number,\n public readonly hasVirtualTrailingCRBreak: boolean,\n public readonly firstCharCode: number,\n public readonly lastCharCode: number\n ) {}\n\n // A slice ending between a backing-buffer CRLF needs its own lone-CR break\n // until the tree reconnects it to a piece beginning with LF.\n get lineBreakCount(): number {\n return (\n this.lineOffsetEnd -\n this.lineOffsetStart +\n (this.hasVirtualTrailingCRBreak ? 1 : 0)\n );\n }\n}\n\n// A text buffer is a string with its line offsets.\nclass TextBuffer {\n lineOffsets: number[];\n\n constructor(public text: string) {\n this.lineOffsets = computeLineOffsets(text);\n }\n\n // the append operation is efficient because it only appends\n // elements to the lineOffsets array in the end\n append(text: string): number {\n const offset = this.text.length;\n for (let i = 0; i < text.length; i++) {\n const charCode = text.charCodeAt(i);\n if (charCode !== LINE_FEED && charCode !== CARRIAGE_RETURN) {\n continue;\n }\n if (\n charCode === CARRIAGE_RETURN &&\n text.charCodeAt(i + 1) === LINE_FEED\n ) {\n i++;\n }\n this.lineOffsets.push(offset + i + 1);\n }\n this.text += text;\n return offset;\n }\n}\n\n// A node in the balanced piece tree. `priority` keeps the tree balanced as a\n// treap (see PieceTable): the tree is a max-heap on priority while staying a\n// binary search tree on document offset.\nclass PieceNode {\n left: PieceNode | null = null;\n right: PieceNode | null = null;\n parent: PieceNode | null = null;\n priority = 0;\n\n constructor(\n public piece: Piece,\n public subtreeLength: number = piece.length,\n public subtreeLineBreakCount: number = piece.lineBreakCount,\n public subtreeFirstCharCode: number = piece.firstCharCode,\n public subtreeLastCharCode: number = piece.lastCharCode\n ) {}\n\n updateSubtreeLength(): void {\n this.subtreeLength =\n (this.left?.subtreeLength ?? 0) +\n this.piece.length +\n (this.right?.subtreeLength ?? 0);\n // Pieces count their edge characters in isolation. Collapse a CRLF only\n // when the two characters are actually adjacent in this subtree.\n this.subtreeLineBreakCount =\n (this.left?.subtreeLineBreakCount ?? 0) +\n this.piece.lineBreakCount +\n (this.right?.subtreeLineBreakCount ?? 0) -\n (formsCRLF(this.left?.subtreeLastCharCode, this.piece.firstCharCode)\n ? 1\n : 0) -\n (formsCRLF(this.piece.lastCharCode, this.right?.subtreeFirstCharCode)\n ? 1\n : 0);\n this.subtreeFirstCharCode =\n this.left?.subtreeFirstCharCode ?? this.piece.firstCharCode;\n this.subtreeLastCharCode =\n this.right?.subtreeLastCharCode ?? this.piece.lastCharCode;\n }\n}\n\n/**\n * A piece table is a data structure that allows for efficient insertion and deletion of text.\n * It is a tree of pieces, where each piece is a segment of text that is either original or added.\n * The tree is a treap (a binary search tree that also keeps each node's random priority in heap\n * order, which keeps the tree balanced without an explicit rebalancing pass). Each edit reshapes\n * only the nodes along one root-to-leaf path via split and merge in O(log P), instead of\n * rebuilding all P pieces.\n * Inspired by https://code.visualstudio.com/blogs/2018/03/23/text-buffer-reimplementation\n */\nexport class PieceTable {\n #original: TextBuffer;\n #add = new TextBuffer('');\n #root: PieceNode | null = null;\n #length = 0;\n #lineCount = 0;\n #lastVisitedLine: [number, boolean, string] | null = null;\n #lastVisitedLineLength: [number, boolean, number] | null = null;\n // Exact inverse of the latest positionAt lookup; edits invalidate it.\n #lastPosition: [line: number, character: number, offset: number] | null =\n null;\n // Seeds the treap priorities. 0x9e3779b9 is the 32-bit golden-ratio\n // constant (2^32 / phi), a well-mixed value commonly used to seed hashes\n // and PRNGs; any fixed nonzero seed works here. A fixed seed keeps the\n // tree shape, and thus performance, deterministic across runs.\n #priorityState = 0x9e3779b9;\n\n constructor(originalText: string) {\n this.#original = new TextBuffer(originalText);\n const piece = this.#createPiece(Piece.Original, 0, originalText.length);\n this.#root = piece.length > 0 ? this.#createNode(piece) : null;\n this.#length = this.#root?.subtreeLength ?? 0;\n this.#lineCount = (this.#root?.subtreeLineBreakCount ?? 0) + 1;\n }\n\n get lineCount(): number {\n return this.#lineCount;\n }\n\n getText(range?: Range): string {\n if (range === undefined) {\n return this.#textFromPieces();\n }\n const start = this.offsetAt(range.start);\n const end = this.offsetAt(range.end);\n return this.getTextSlice(start, end);\n }\n\n getLineText(line: number, includeLineBreak = false): string {\n if (\n this.#lastVisitedLine !== null &&\n this.#lastVisitedLine[0] === line &&\n this.#lastVisitedLine[1] === includeLineBreak\n ) {\n return this.#lastVisitedLine[2];\n }\n const offset = this.#getLineOffset(line);\n if (offset === undefined) {\n throw new Error(`Line index out of range: ${line}`);\n }\n const text = this.getTextSlice(offset[0], offset[1], !includeLineBreak);\n this.#lastVisitedLine = [line, includeLineBreak, text];\n this.#lastVisitedLineLength = [line, includeLineBreak, text.length];\n return text;\n }\n\n getLineLength(line: number, includeLineBreak = false): number {\n const lastVisitedLineLength = this.#lastVisitedLineLength;\n const lastVisitedLine = this.#lastVisitedLine;\n if (\n lastVisitedLineLength !== null &&\n lastVisitedLineLength[0] === line &&\n lastVisitedLineLength[1] === includeLineBreak\n ) {\n return lastVisitedLineLength[2];\n }\n if (\n lastVisitedLine !== null &&\n lastVisitedLine[0] === line &&\n lastVisitedLine[1] === includeLineBreak\n ) {\n const length = lastVisitedLine[2].length;\n this.#lastVisitedLineLength = [line, includeLineBreak, length];\n return length;\n }\n const offset = this.#getLineOffset(line);\n if (offset === undefined) {\n throw new Error(`Line index out of range: ${line}`);\n }\n const [start, end] = offset;\n let length = end - start;\n if (!includeLineBreak) {\n while (\n length > 0 &&\n isEOL(this.charAt(start + length - 1).charCodeAt(0))\n ) {\n length--;\n }\n }\n this.#lastVisitedLineLength = [line, includeLineBreak, length];\n return length;\n }\n\n getTextSlice(start: number, end: number, trimEOF = false): string {\n if (start >= end) {\n return '';\n }\n\n const sliceStart = clamp(start, 0, this.#length);\n const sliceEnd = clamp(end, sliceStart, this.#length);\n if (sliceStart >= sliceEnd) {\n return '';\n }\n\n const location = this.#findPieceAtOffset(sliceStart);\n if (location === undefined) {\n return '';\n }\n\n const chunks: string[] = [];\n let [node, offsetInPiece] = location as [PieceNode | null, number];\n let remaining = sliceEnd - sliceStart;\n while (node !== null && remaining > 0) {\n const takeLength = Math.min(node.piece.length - offsetInPiece, remaining);\n const buffer = this.#bufferFor(node.piece.source);\n const start = node.piece.offset + offsetInPiece;\n let end = start + takeLength;\n if (trimEOF) {\n while (end > start && isEOL(buffer.text.charCodeAt(end - 1))) {\n end--;\n }\n }\n chunks.push(buffer.text.slice(start, end));\n remaining -= takeLength;\n offsetInPiece = 0;\n node = this.#nextNode(node);\n }\n\n return chunks.join('');\n }\n\n charAt(offset: number): string {\n const location = this.#findPieceAtOffset(offset);\n if (location === undefined) {\n return '';\n }\n\n const [node, offsetInPiece] = location;\n const buffer = this.#bufferFor(node.piece.source);\n return buffer.text.charAt(node.piece.offset + offsetInPiece);\n }\n\n includes(needle: string): boolean {\n if (needle.length === 0) {\n return true;\n }\n\n const prefixTable = createPrefixTable(needle);\n let matched = 0;\n let found = false;\n this.#forEachPieceSegment((segment) => {\n for (let offset = segment.start; offset < segment.end; offset++) {\n const charCode = segment.text.charCodeAt(offset);\n while (matched > 0 && charCode !== needle.charCodeAt(matched)) {\n matched = prefixTable[matched - 1];\n }\n if (charCode === needle.charCodeAt(matched)) {\n matched++;\n }\n if (matched === needle.length) {\n found = true;\n return false;\n }\n }\n return true;\n });\n return found;\n }\n\n findNextNonOverlappingSubstring(\n needle: string,\n occupied: readonly [start: number, end: number][]\n ): number | undefined {\n if (needle.length === 0 || needle.length > this.#length) {\n return undefined;\n }\n\n const ranges = normalizeRanges(occupied, this.#length);\n const pivot = ranges.reduce((max, [, end]) => Math.max(max, end), 0);\n const prefixTable = createPrefixTable(needle);\n let matched = 0;\n let documentOffset = 0;\n let wrappedOffset: number | undefined;\n let foundOffset: number | undefined;\n\n this.#forEachPieceSegment((segment) => {\n for (let offset = segment.start; offset < segment.end; offset++) {\n const charCode = segment.text.charCodeAt(offset);\n while (matched > 0 && charCode !== needle.charCodeAt(matched)) {\n matched = prefixTable[matched - 1];\n }\n if (charCode === needle.charCodeAt(matched)) {\n matched++;\n }\n if (matched === needle.length) {\n const start = documentOffset - needle.length + 1;\n if (!rangeOverlaps(ranges, start, start + needle.length)) {\n if (start >= pivot) {\n foundOffset = start;\n return false;\n }\n wrappedOffset ??= start;\n }\n matched = prefixTable[matched - 1];\n }\n documentOffset++;\n }\n return true;\n });\n\n return foundOffset ?? wrappedOffset;\n }\n\n search(searchParams: SearchParams): [start: number, end: number][] {\n if (searchParams.text.length === 0 || this.#length === 0) {\n return [];\n }\n\n // Search currently operates line-by-line, so newline-spanning patterns are unsupported.\n if (\n searchParams.text.includes('\\n') ||\n searchParams.text.includes('\\r') ||\n (searchParams.regex &&\n (searchParams.text.includes('\\\\n') ||\n searchParams.text.includes('\\\\r')))\n ) {\n return [];\n }\n\n let pattern: RegExp;\n try {\n pattern = compileSearchRegExp(\n searchParams.text,\n searchParams.regex,\n searchParams.caseSensitive\n );\n } catch {\n return [];\n }\n\n return this.#collectSearchMatchesLineByLine(\n pattern,\n searchParams.wholeWord,\n MAX_FIND_MATCHES\n );\n }\n\n #collectSearchMatchesLineByLine(\n pattern: RegExp,\n wholeWord: boolean,\n limit: number\n ): [number, number][] {\n const out: [number, number][] = [];\n // Search visits the whole document, so flatten it once instead of making\n // several treap descents for every line and whole-word boundary.\n const documentText = this.#textFromPieces();\n const docLength = documentText.length;\n const lineOffsets = computeLineOffsets(documentText);\n\n // Reuse the single compiled pattern across every line, resetting its\n // lastIndex before each line, instead of allocating a fresh RegExp per\n // line. The pattern is global, so lastIndex tracks progress within a line.\n for (let line = 0; line < lineOffsets.length; line++) {\n const lineStart = lineOffsets[line];\n let lineEnd = lineOffsets[line + 1] ?? docLength;\n while (\n lineEnd > lineStart &&\n isEOL(documentText.charCodeAt(lineEnd - 1))\n ) {\n lineEnd--;\n }\n const lineText = documentText.slice(lineStart, lineEnd);\n pattern.lastIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = pattern.exec(lineText)) !== null) {\n const rel = match.index;\n const fragment = match[0];\n if (fragment.length === 0) {\n pattern.lastIndex = advancePastEmptyMatch(lineText, rel);\n continue;\n }\n const docStart = lineStart + rel;\n if (\n !wholeWord ||\n isWholeWordAtDocOffsets(documentText, docStart, fragment.length)\n ) {\n out.push([docStart, docStart + fragment.length]);\n if (out.length >= limit) {\n return out;\n }\n }\n if (rel === pattern.lastIndex) {\n pattern.lastIndex = advancePastEmptyMatch(lineText, rel);\n }\n }\n }\n return out;\n }\n\n insert(text: string, offset: number): void {\n if (text.length === 0) {\n return;\n }\n const start = clamp(offset, 0, this.#length);\n this.#replaceRangeIncremental(start, start, text);\n this.#invalidateCaches();\n }\n\n delete(offset: number, length: number): void {\n if (length <= 0 || this.#length === 0) {\n return;\n }\n const start = clamp(offset, 0, this.#length);\n const end = clamp(start + length, start, this.#length);\n if (start === end) {\n return;\n }\n this.#replaceRangeIncremental(start, end, '');\n this.#invalidateCaches();\n }\n\n applyEdits(edits: readonly ResolvedTextEdit[]): void {\n if (edits.length === 0) {\n return;\n }\n // Edits arrive sorted ascending and non-overlapping (TextDocument enforces\n // this). Applying them from last to first keeps each remaining edit's\n // offsets valid, since edits at higher offsets never shift lower ones, and\n // every edit becomes an O(log P) incremental replace.\n for (let i = edits.length - 1; i >= 0; i--) {\n const edit = edits[i];\n const start = clamp(edit.start, 0, this.#length);\n const end = clamp(edit.end, start, this.#length);\n this.#replaceRangeIncremental(start, end, edit.text);\n }\n this.#invalidateCaches();\n }\n\n positionAt(offset: number): Position {\n const clampedOffset = clamp(offset, 0, this.#length);\n if (this.#length === 0) {\n return { line: 0, character: 0 };\n }\n const line = this.#lineAtOffset(clampedOffset);\n const lineStart = line === 0 ? 0 : this.#lineBreakOffset(line - 1);\n const character = clampedOffset - lineStart;\n this.#lastPosition = [line, character, clampedOffset];\n return { line, character };\n }\n\n positionsAt(offsets: readonly number[]): Position[] {\n const positions: Position[] = Array.from({ length: offsets.length });\n if (offsets.length === 0) {\n return positions;\n }\n if (this.#length === 0) {\n return positions.fill({ line: 0, character: 0 });\n }\n\n for (let i = 0; i < offsets.length; i++) {\n positions[i] = this.positionAt(offsets[i]);\n }\n\n return positions;\n }\n\n offsetAt(position: Position): number {\n if (position.line < 0 || this.#length === 0) {\n return 0;\n }\n if (position.line >= this.#lineCount) {\n throw new Error(`Line index out of range: ${position.line}`);\n }\n const lastPosition = this.#lastPosition;\n if (\n lastPosition !== null &&\n lastPosition[0] === position.line &&\n lastPosition[1] === position.character\n ) {\n return lastPosition[2];\n }\n const offset = this.#getLineOffset(position.line);\n if (offset === undefined) {\n throw new Error(`Line index out of range: ${position.line}`);\n }\n const character = clamp(position.character, 0, offset[1] - offset[0]);\n return offset[0] + character;\n }\n\n #findPieceAtOffset(\n offset: number\n ): [node: PieceNode, offsetInPiece: number] | undefined {\n if (offset < 0 || offset >= this.#length) {\n return undefined;\n }\n\n let node = this.#root;\n let remaining = offset;\n while (node !== null) {\n const leftLength = node.left?.subtreeLength ?? 0;\n if (remaining < leftLength) {\n node = node.left;\n continue;\n }\n\n remaining -= leftLength;\n if (remaining < node.piece.length) {\n return [node, remaining];\n }\n\n remaining -= node.piece.length;\n node = node.right;\n }\n\n return undefined;\n }\n\n #nextNode(node: PieceNode): PieceNode | null {\n if (node.right !== null) {\n let next = node.right;\n while (next.left !== null) {\n next = next.left;\n }\n return next;\n }\n\n let current = node;\n while (current.parent !== null && current === current.parent.right) {\n current = current.parent;\n }\n return current.parent;\n }\n\n #getLineOffset(line: number): [start: number, end: number] | undefined {\n if (line < 0) {\n throw new Error(`Line index out of range: ${line}`);\n }\n if (this.#length === 0) {\n if (line === 0) {\n return [0, 0];\n }\n throw new Error(`Line index out of range: ${line}`);\n }\n if (line >= this.#lineCount) {\n throw new Error(`Line index out of range: ${line}`);\n }\n\n const start = line === 0 ? 0 : this.#lineBreakOffset(line - 1);\n const end =\n line < this.#lineCount - 1 ? this.#lineBreakOffset(line) : this.#length;\n return [start, end];\n }\n\n #lineAtOffset(offset: number): number {\n let node = this.#root;\n let remaining = clamp(offset, 0, this.#length);\n let line = 0;\n\n while (node !== null) {\n const leftLength = node.left?.subtreeLength ?? 0;\n if (remaining < leftLength) {\n node = node.left;\n continue;\n }\n\n line +=\n (node.left?.subtreeLineBreakCount ?? 0) -\n (formsCRLF(node.left?.subtreeLastCharCode, node.piece.firstCharCode)\n ? 1\n : 0);\n remaining -= leftLength;\n if (remaining <= node.piece.length) {\n const buffer = this.#bufferFor(node.piece.source);\n const lineOffsetEnd = Math.min(\n upperBound(buffer.lineOffsets, node.piece.offset + remaining),\n node.piece.lineOffsetEnd\n );\n line += lineOffsetEnd - node.piece.lineOffsetStart;\n if (\n remaining === node.piece.length &&\n node.piece.hasVirtualTrailingCRBreak\n ) {\n line++;\n }\n if (\n remaining === node.piece.length &&\n formsCRLF(\n node.piece.lastCharCode,\n this.#nextNode(node)?.piece.firstCharCode\n )\n ) {\n line--;\n }\n return line;\n }\n\n line +=\n node.piece.lineBreakCount -\n (formsCRLF(node.piece.lastCharCode, node.right?.subtreeFirstCharCode)\n ? 1\n : 0);\n remaining -= node.piece.length;\n node = node.right;\n }\n\n return this.#lineCount - 1;\n }\n\n #lineBreakOffset(lineBreakIndex: number): number {\n let node = this.#root;\n let remaining = lineBreakIndex;\n let documentOffset = 0;\n let followingCharCode: number | undefined;\n\n while (node !== null) {\n const leftLineBreakCount =\n (node.left?.subtreeLineBreakCount ?? 0) -\n (formsCRLF(node.left?.subtreeLastCharCode, node.piece.firstCharCode)\n ? 1\n : 0);\n if (remaining < leftLineBreakCount) {\n followingCharCode = node.piece.firstCharCode;\n node = node.left;\n continue;\n }\n\n const leftLength = node.left?.subtreeLength ?? 0;\n documentOffset += leftLength;\n remaining -= leftLineBreakCount;\n\n const nextCharCode =\n node.right?.subtreeFirstCharCode ?? followingCharCode;\n const pieceLineBreakCount =\n node.piece.lineBreakCount -\n (formsCRLF(node.piece.lastCharCode, nextCharCode) ? 1 : 0);\n if (remaining < pieceLineBreakCount) {\n return (\n documentOffset + this.#pieceLineBreakOffset(node.piece, remaining)\n );\n }\n\n documentOffset += node.piece.length;\n remaining -= pieceLineBreakCount;\n node = node.right;\n }\n\n return this.#length;\n }\n\n #pieceLineBreakOffset(piece: Piece, lineBreakIndex: number): number {\n const bufferLineBreakCount = piece.lineOffsetEnd - piece.lineOffsetStart;\n if (lineBreakIndex < bufferLineBreakCount) {\n const bufferLineOffset = this.#bufferFor(piece.source).lineOffsets[\n piece.lineOffsetStart + lineBreakIndex\n ];\n return bufferLineOffset - piece.offset;\n }\n return piece.length;\n }\n\n #textFromPieces(): string {\n const chunks: string[] = [];\n this.#forEachPieceSegment((segment) => {\n chunks.push(segment.text.slice(segment.start, segment.end));\n });\n return chunks.join('');\n }\n\n #forEachPieceSegment(\n callback: (segment: {\n readonly start: number;\n readonly end: number;\n readonly text: string;\n readonly lineOffsets: number[];\n readonly lineOffsetStart: number;\n readonly lineOffsetEnd: number;\n }) => boolean | void\n ): void {\n this.#walk(this.#root, (node) => {\n const buffer = this.#bufferFor(node.piece.source);\n return callback({\n text: buffer.text,\n lineOffsets: buffer.lineOffsets,\n lineOffsetStart: node.piece.lineOffsetStart,\n lineOffsetEnd: node.piece.lineOffsetEnd,\n start: node.piece.offset,\n end: node.piece.offset + node.piece.length,\n });\n });\n }\n\n #bufferFor(source: number): TextBuffer {\n return source === Piece.Original ? this.#original : this.#add;\n }\n\n #createPiece(source: number, offset: number, length: number): Piece {\n const buffer = this.#bufferFor(source);\n const end = offset + length;\n const lineOffsetStart = upperBound(buffer.lineOffsets, offset);\n const lineOffsetEnd = upperBound(buffer.lineOffsets, end);\n const lastCharCode = buffer.text.charCodeAt(end - 1);\n return new Piece(\n source,\n offset,\n length,\n lineOffsetStart,\n lineOffsetEnd,\n lastCharCode === CARRIAGE_RETURN &&\n buffer.lineOffsets[lineOffsetEnd - 1] !== end,\n buffer.text.charCodeAt(offset),\n lastCharCode\n );\n }\n\n // Replaces document range [start, end) with `text` by splitting at the start,\n // dropping the deleted prefix from the remainder, and joining the inserted\n // piece back in. Each tree operation touches only one root-to-leaf path, so\n // the edit is O(log P) instead of rebuilding all P pieces. `start`/`end` must\n // be clamped into [0, length] with start <= end.\n #replaceRangeIncremental(start: number, end: number, text: string): void {\n if (start === end && text.length === 0) {\n return;\n }\n\n const [left, rest] = this.#split(this.#root, start);\n const right = this.#dropPrefix(rest, end - start);\n\n let root: PieceNode | null;\n if (text.length > 0) {\n const insertedPiece = this.#createPiece(\n Piece.Added,\n this.#add.append(text),\n text.length\n );\n // The inserted text is fresh at the end of the add buffer, so it can only\n // sit next to the piece on its left, never the one on its right.\n root = this.#mergeNodes(\n this.#appendCoalescing(left, insertedPiece),\n right\n );\n } else {\n // Pure deletion: the pieces now meeting at the seam may be contiguous in\n // the same buffer, so re-attach the right side's first piece through the\n // coalescing append to merge them when possible.\n const [seamPiece, restRight] = this.#popLeftmost(right);\n root =\n seamPiece === undefined\n ? left\n : this.#mergeNodes(\n this.#appendCoalescing(left, seamPiece),\n restRight\n );\n }\n\n if (root !== null) {\n root.parent = null;\n }\n this.#root = root;\n this.#length = root?.subtreeLength ?? 0;\n this.#lineCount = (root?.subtreeLineBreakCount ?? 0) + 1;\n }\n\n // Public mutations clear read caches once, including multi-edit batches.\n #invalidateCaches(): void {\n this.#lastVisitedLine = null;\n this.#lastVisitedLineLength = null;\n this.#lastPosition = null;\n }\n\n #nextPriority(): number {\n this.#priorityState =\n (Math.imul(this.#priorityState, 1664525) + 1013904223) >>> 0;\n return this.#priorityState;\n }\n\n #createNode(piece: Piece): PieceNode {\n const node = new PieceNode(piece);\n node.priority = this.#nextPriority();\n return node;\n }\n\n // Attaches `child` as a side of `node`, keeping the parent pointer in sync so\n // read-side iteration (#nextNode) can still walk back up the tree.\n #setLeft(node: PieceNode, child: PieceNode | null): void {\n node.left = child;\n if (child !== null) {\n child.parent = node;\n }\n }\n\n #setRight(node: PieceNode, child: PieceNode | null): void {\n node.right = child;\n if (child !== null) {\n child.parent = node;\n }\n }\n\n // Splits the subtree into [0, offset) and [offset, length). When the offset\n // falls inside a piece, that piece is sliced in two so the split lands on a\n // clean boundary. Internal parent pointers stay correct; the caller fixes the\n // returned roots' own parents when it reattaches or stores them.\n #split(\n node: PieceNode | null,\n offset: number\n ): [left: PieceNode | null, right: PieceNode | null] {\n if (node === null) {\n return [null, null];\n }\n if (offset <= 0) {\n return [null, node];\n }\n if (offset >= node.subtreeLength) {\n return [node, null];\n }\n\n const leftLength = node.left?.subtreeLength ?? 0;\n if (offset <= leftLength) {\n const [left, right] = this.#split(node.left, offset);\n this.#setLeft(node, right);\n node.updateSubtreeLength();\n return [left, node];\n }\n\n const pieceLength = node.piece.length;\n if (offset >= leftLength + pieceLength) {\n const [left, right] = this.#split(\n node.right,\n offset - leftLength - pieceLength\n );\n this.#setRight(node, left);\n node.updateSubtreeLength();\n return [node, right];\n }\n\n // The offset is strictly inside this node's piece: slice it in two. Both\n // halves inherit this node's priority, which keeps the heap valid because\n // this node already outranked both of its children.\n const inPiece = offset - leftLength;\n const leftNode = new PieceNode(\n this.#createPiece(node.piece.source, node.piece.offset, inPiece)\n );\n const rightNode = new PieceNode(\n this.#createPiece(\n node.piece.source,\n node.piece.offset + inPiece,\n pieceLength - inPiece\n )\n );\n leftNode.priority = node.priority;\n rightNode.priority = node.priority;\n this.#setLeft(leftNode, node.left);\n this.#setRight(rightNode, node.right);\n leftNode.updateSubtreeLength();\n rightNode.updateSubtreeLength();\n return [leftNode, rightNode];\n }\n\n // Discards [0, offset), allocating only the surviving half of a cut piece.\n #dropPrefix(node: PieceNode | null, offset: number): PieceNode | null {\n if (node === null || offset >= node.subtreeLength) {\n return null;\n }\n if (offset <= 0) {\n return node;\n }\n\n const leftLength = node.left?.subtreeLength ?? 0;\n if (offset <= leftLength) {\n this.#setLeft(node, this.#dropPrefix(node.left, offset));\n node.updateSubtreeLength();\n return node;\n }\n\n const pieceEnd = leftLength + node.piece.length;\n if (offset >= pieceEnd) {\n return this.#dropPrefix(node.right, offset - pieceEnd);\n }\n\n const inPiece = offset - leftLength;\n const rightNode = new PieceNode(\n this.#createPiece(\n node.piece.source,\n node.piece.offset + inPiece,\n node.piece.length - inPiece\n )\n );\n rightNode.priority = node.priority;\n this.#setRight(rightNode, node.right);\n rightNode.updateSubtreeLength();\n return rightNode;\n }\n\n // Joins two subtrees where every offset in `left` precedes every offset in\n // `right`, taking the higher-priority root so the result stays balanced.\n #mergeNodes(\n left: PieceNode | null,\n right: PieceNode | null\n ): PieceNode | null {\n if (left === null) {\n return right;\n }\n if (right === null) {\n return left;\n }\n if (left.priority >= right.priority) {\n this.#setRight(left, this.#mergeNodes(left.right, right));\n left.updateSubtreeLength();\n return left;\n }\n this.#setLeft(right, this.#mergeNodes(left, right.left));\n right.updateSubtreeLength();\n return right;\n }\n\n // Appends `piece` after every node in `tree`. Compatible adjacent pieces in\n // the same buffer are merged in place, keeping sequential typing compact.\n #appendCoalescing(tree: PieceNode | null, piece: Piece): PieceNode {\n if (tree === null) {\n return this.#createNode(piece);\n }\n let last = tree;\n while (last.right !== null) {\n last = last.right;\n }\n if (canCoalescePieces(last.piece, piece)) {\n last.piece = coalesceTwoPieces(last.piece, piece);\n // The last piece grew, so refresh aggregates from it up to the root.\n for (let node: PieceNode | null = last; node !== null; ) {\n node.updateSubtreeLength();\n if (node === tree) {\n break;\n }\n node = node.parent;\n }\n return tree;\n }\n // `tree` is non-null here, so merging in the new node always yields a node.\n return this.#mergeNodes(tree, this.#createNode(piece)) as PieceNode;\n }\n\n // Removes and returns the first piece of the tree along with the remaining\n // tree, so a deletion seam can re-merge the piece that becomes adjacent to\n // the one on the other side of the deletion.\n #popLeftmost(\n tree: PieceNode | null\n ): [piece: Piece | undefined, rest: PieceNode | null] {\n if (tree === null) {\n return [undefined, null];\n }\n if (tree.left === null) {\n return [tree.piece, tree.right];\n }\n const [piece, newLeft] = this.#popLeftmost(tree.left);\n this.#setLeft(tree, newLeft);\n tree.updateSubtreeLength();\n return [piece, tree];\n }\n\n #walk(\n node: PieceNode | null,\n visit: (node: PieceNode) => boolean | void\n ): boolean {\n if (node === null) {\n return true;\n }\n if (!this.#walk(node.left, visit)) {\n return false;\n }\n if (visit(node) === false) {\n return false;\n }\n return this.#walk(node.right, visit);\n }\n}\n\nfunction isEOL(charCode: number): boolean {\n return charCode === /* \\n */ 10 || charCode === /* \\r */ 13;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction createPrefixTable(text: string): number[] {\n const table = Array.from<number>({ length: text.length }).fill(0);\n let matched = 0;\n for (let i = 1; i < text.length; i++) {\n const charCode = text.charCodeAt(i);\n while (matched > 0 && charCode !== text.charCodeAt(matched)) {\n matched = table[matched - 1];\n }\n if (charCode === text.charCodeAt(matched)) {\n matched++;\n }\n table[i] = matched;\n }\n return table;\n}\n\nfunction normalizeRanges(\n ranges: readonly [start: number, end: number][],\n length: number\n): [start: number, end: number][] {\n const normalized: [start: number, end: number][] = [];\n for (const [rawStart, rawEnd] of ranges) {\n const start = clamp(rawStart, 0, length);\n const end = clamp(rawEnd, start, length);\n if (start < end) {\n normalized.push([start, end]);\n }\n }\n normalized.sort((a, b) => a[0] - b[0]);\n\n const merged: [start: number, end: number][] = [];\n for (const range of normalized) {\n const previous = merged[merged.length - 1];\n if (previous !== undefined && range[0] <= previous[1]) {\n previous[1] = Math.max(previous[1], range[1]);\n continue;\n }\n merged.push(range);\n }\n return merged;\n}\n\nfunction rangeOverlaps(\n ranges: readonly [start: number, end: number][],\n start: number,\n end: number\n): boolean {\n let low = 0;\n let high = ranges.length;\n while (low < high) {\n const mid = low + Math.floor((high - low) / 2);\n if (ranges[mid][1] <= start) {\n low = mid + 1;\n } else {\n high = mid;\n }\n }\n\n const range = ranges[low];\n return range !== undefined && range[0] < end;\n}\n\n// CRLF seams stay explicit because separately appended buffer chunks may each\n// record a break there; the tree aggregate reconciles the document-level pair.\nfunction canCoalescePieces(prev: Piece, next: Piece): boolean {\n return (\n prev.source === next.source &&\n prev.offset + prev.length === next.offset &&\n !formsCRLF(prev.lastCharCode, next.firstCharCode)\n );\n}\n\n// Joins two adjacent pieces (see canCoalescePieces) into one. Keeping the table\n// compact after every edit is what stops the piece count from growing without\n// bound during normal typing.\nfunction coalesceTwoPieces(prev: Piece, next: Piece): Piece {\n return new Piece(\n prev.source,\n prev.offset,\n prev.length + next.length,\n prev.lineOffsetStart,\n next.lineOffsetEnd,\n next.hasVirtualTrailingCRBreak,\n prev.firstCharCode,\n next.lastCharCode\n );\n}\n\nfunction formsCRLF(\n leftCharCode: number | undefined,\n rightCharCode: number | undefined\n): boolean {\n return leftCharCode === CARRIAGE_RETURN && rightCharCode === LINE_FEED;\n}\n\n// Returns the index of the first element in the array that is greater than the target.\nfunction upperBound(values: number[], target: number): number {\n let lo = 0;\n let hi = values.length;\n while (lo < hi) {\n const mid = lo + Math.floor((hi - lo) / 2);\n if (values[mid] <= target) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n return lo;\n}\n\nfunction escapeRegExp(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction isWordSeparatorCharCode(charCode: number): boolean {\n if (charCode <= 32 || charCode === 127) {\n return true;\n }\n const ch = String.fromCharCode(charCode);\n return WORD_SEPARATORS.includes(ch);\n}\n\n// Checks if the given text is a whole word by checking if the\n// characters before and after are word separators.\nfunction isWholeWordAtDocOffsets(\n text: string,\n docStart: number,\n length: number\n): boolean {\n const beforeOk =\n docStart <= 0 || isWordSeparatorCharCode(text.charCodeAt(docStart - 1));\n const afterOk =\n docStart + length >= text.length ||\n isWordSeparatorCharCode(text.charCodeAt(docStart + length));\n return beforeOk && afterOk;\n}\n\nfunction compileSearchRegExp(\n source: string,\n isRegex: boolean,\n caseSensitive: boolean\n): RegExp {\n const body = isRegex ? source : escapeRegExp(source);\n const flags = `g${caseSensitive ? '' : 'i'}${isRegex ? 'm' : ''}`;\n return new RegExp(body, flags);\n}\n\n/** Expands `$&`, `$1`, `$$`, etc. in a regex replace string using a match. */\nfunction expandReplaceString(\n replacement: string,\n match: RegExpExecArray\n): string {\n return replacement.replace(/\\$([$&]|\\d+)/g, (_token, group: string) => {\n if (group === '$') {\n return '$';\n }\n if (group === '&') {\n return match[0] ?? '';\n }\n const index = Number(group);\n return match[index] ?? '';\n });\n}\n\n/**\n * Builds the text to insert for one search match, including regex capture\n * substitution when regex mode is enabled.\n */\nexport function buildSearchReplacementText(\n positionAt: (offset: number) => Position,\n offsetAt: (position: Position) => number,\n getLineText: (line: number) => string,\n searchParams: SearchParams,\n matchStart: number,\n matchEnd: number\n): string {\n if (!searchParams.regex) {\n return searchParams.replaceText;\n }\n\n const position = positionAt(matchStart);\n const lineText = getLineText(position.line);\n const lineStart = offsetAt({ line: position.line, character: 0 });\n const relStart = matchStart - lineStart;\n\n let pattern: RegExp;\n try {\n pattern = compileSearchRegExp(\n searchParams.text,\n true,\n searchParams.caseSensitive\n );\n } catch {\n return searchParams.replaceText;\n }\n\n // Re-run at the original line offset so lookaround can inspect context\n // outside the matched range while captures still come from this exact hit.\n pattern.lastIndex = relStart;\n const match = pattern.exec(lineText);\n if (\n match === null ||\n match.index !== relStart ||\n match[0].length !== matchEnd - matchStart\n ) {\n return searchParams.replaceText;\n }\n return expandReplaceString(searchParams.replaceText, match);\n}\n\nfunction advancePastEmptyMatch(text: string, index: number): number {\n if (index + 1 < text.length) {\n const first = text.charCodeAt(index);\n const second = text.charCodeAt(index + 1);\n if (\n first >= 0xd800 &&\n first <= 0xdbff &&\n second >= 0xdc00 &&\n second <= 0xdfff\n ) {\n return index + 2;\n }\n }\n return index + 1;\n}\n"],"mappings":";;AAKA,MAAM,mBAAmB;AACzB,MAAM,YAAY;AAClB,MAAM,kBAAkB;AAExB,MAAM,kBAAkB;AAGxB,IAAM,QAAN,MAAY;CAKQ;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAXlB,OAAO,WAAW;CAClB,OAAO,QAAQ;CAEf,YACE,QACA,QACA,QACA,iBACA,eACA,2BACA,eACA,cACA;EARgB,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,kBAAA;EACA,KAAA,gBAAA;EACA,KAAA,4BAAA;EACA,KAAA,gBAAA;EACA,KAAA,eAAA;CACf;CAIH,IAAI,iBAAyB;EAC3B,OACE,KAAK,gBACL,KAAK,mBACJ,KAAK,4BAA4B,IAAI;CAE1C;AACF;AAGA,IAAM,aAAN,MAAiB;CAGI;CAFnB;CAEA,YAAY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AACjB"}
|
|
1
|
+
{"version":3,"file":"pieceTable.js","names":["#original","#createPiece","#root","#createNode","#length","#lineCount","#textFromPieces","#lastVisitedLine","#getLineOffset","#lastVisitedLineLength","#findPieceAtOffset","#bufferFor","#nextNode","#forEachPieceSegment","#collectSearchMatchesLineByLine","#replaceRangeIncremental","#invalidateCaches","#lineAtOffset","#lineBreakOffset","#lastPosition","#pieceLineBreakOffset","#walk","#add","#split","#dropPrefix","#mergeNodes","#appendCoalescing","#popLeftmost","#priorityState","#nextPriority","#setLeft","#setRight"],"sources":["../../src/editor/pieceTable.ts"],"sourcesContent":["import type { Position, Range, ResolvedTextEdit } from '../types';\nimport { computeLineOffsets } from '../utils/computeFileOffsets';\nimport type { SearchParams } from './searchPanel';\n\nconst MAX_FIND_MATCHES = 100000;\nconst LINE_FEED = 10;\nconst CARRIAGE_RETURN = 13;\n// TODO(ije): use Intl.Segmenter instead of regex for word separators\nconst WORD_SEPARATORS = '`~!@#$%^&*()-=+[{]}\\\\|;:\\'\",.<>/?' as const;\n\n// A piece is a segment of text that is either original or added.\nclass Piece {\n static Original = 0;\n static Added = 1;\n\n constructor(\n public readonly source: number,\n public readonly offset: number,\n public readonly length: number,\n public readonly lineOffsetStart: number,\n public readonly lineOffsetEnd: number,\n public readonly hasVirtualTrailingCRBreak: boolean,\n public readonly firstCharCode: number,\n public readonly lastCharCode: number\n ) {}\n\n // A slice ending between a backing-buffer CRLF needs its own lone-CR break\n // until the tree reconnects it to a piece beginning with LF.\n get lineBreakCount(): number {\n return (\n this.lineOffsetEnd -\n this.lineOffsetStart +\n (this.hasVirtualTrailingCRBreak ? 1 : 0)\n );\n }\n}\n\n// A text buffer is a string with its line offsets.\nclass TextBuffer {\n lineOffsets: number[];\n\n constructor(public text: string) {\n this.lineOffsets = computeLineOffsets(text);\n }\n\n // the append operation is efficient because it only appends\n // elements to the lineOffsets array in the end\n append(text: string): number {\n const offset = this.text.length;\n for (let i = 0; i < text.length; i++) {\n const charCode = text.charCodeAt(i);\n if (charCode !== LINE_FEED && charCode !== CARRIAGE_RETURN) {\n continue;\n }\n if (\n charCode === CARRIAGE_RETURN &&\n text.charCodeAt(i + 1) === LINE_FEED\n ) {\n i++;\n }\n this.lineOffsets.push(offset + i + 1);\n }\n this.text += text;\n return offset;\n }\n}\n\n// A node in the balanced piece tree. `priority` keeps the tree balanced as a\n// treap (see PieceTable): the tree is a max-heap on priority while staying a\n// binary search tree on document offset.\nclass PieceNode {\n left: PieceNode | null = null;\n right: PieceNode | null = null;\n parent: PieceNode | null = null;\n priority = 0;\n\n constructor(\n public piece: Piece,\n public subtreeLength: number = piece.length,\n public subtreeLineBreakCount: number = piece.lineBreakCount,\n public subtreeFirstCharCode: number = piece.firstCharCode,\n public subtreeLastCharCode: number = piece.lastCharCode\n ) {}\n\n updateSubtreeLength(): void {\n this.subtreeLength =\n (this.left?.subtreeLength ?? 0) +\n this.piece.length +\n (this.right?.subtreeLength ?? 0);\n // Pieces count their edge characters in isolation. Collapse a CRLF only\n // when the two characters are actually adjacent in this subtree.\n this.subtreeLineBreakCount =\n (this.left?.subtreeLineBreakCount ?? 0) +\n this.piece.lineBreakCount +\n (this.right?.subtreeLineBreakCount ?? 0) -\n (formsCRLF(this.left?.subtreeLastCharCode, this.piece.firstCharCode)\n ? 1\n : 0) -\n (formsCRLF(this.piece.lastCharCode, this.right?.subtreeFirstCharCode)\n ? 1\n : 0);\n this.subtreeFirstCharCode =\n this.left?.subtreeFirstCharCode ?? this.piece.firstCharCode;\n this.subtreeLastCharCode =\n this.right?.subtreeLastCharCode ?? this.piece.lastCharCode;\n }\n}\n\n/**\n * A piece table is a data structure that allows for efficient insertion and deletion of text.\n * It is a tree of pieces, where each piece is a segment of text that is either original or added.\n * The tree is a treap (a binary search tree that also keeps each node's random priority in heap\n * order, which keeps the tree balanced without an explicit rebalancing pass). Each edit reshapes\n * only the nodes along one root-to-leaf path via split and merge in O(log P), instead of\n * rebuilding all P pieces.\n * Inspired by https://code.visualstudio.com/blogs/2018/03/23/text-buffer-reimplementation\n */\nexport class PieceTable {\n #original: TextBuffer;\n #add = new TextBuffer('');\n #root: PieceNode | null = null;\n #length = 0;\n #lineCount = 0;\n #lastVisitedLine: [number, boolean, string] | null = null;\n #lastVisitedLineLength: [number, boolean, number] | null = null;\n // Exact inverse of the latest positionAt lookup; edits invalidate it.\n #lastPosition: [line: number, character: number, offset: number] | null =\n null;\n // Seeds the treap priorities. 0x9e3779b9 is the 32-bit golden-ratio\n // constant (2^32 / phi), a well-mixed value commonly used to seed hashes\n // and PRNGs; any fixed nonzero seed works here. A fixed seed keeps the\n // tree shape, and thus performance, deterministic across runs.\n #priorityState = 0x9e3779b9;\n\n constructor(originalText: string) {\n this.#original = new TextBuffer(originalText);\n const piece = this.#createPiece(Piece.Original, 0, originalText.length);\n this.#root = piece.length > 0 ? this.#createNode(piece) : null;\n this.#length = this.#root?.subtreeLength ?? 0;\n this.#lineCount = (this.#root?.subtreeLineBreakCount ?? 0) + 1;\n }\n\n get lineCount(): number {\n return this.#lineCount;\n }\n\n getText(range?: Range): string {\n if (range === undefined) {\n return this.#textFromPieces();\n }\n const start = this.offsetAt(range.start);\n const end = this.offsetAt(range.end);\n return this.getTextSlice(start, end);\n }\n\n getLineText(line: number, includeLineBreak = false): string {\n if (\n this.#lastVisitedLine !== null &&\n this.#lastVisitedLine[0] === line &&\n this.#lastVisitedLine[1] === includeLineBreak\n ) {\n return this.#lastVisitedLine[2];\n }\n const offset = this.#getLineOffset(line);\n if (offset === undefined) {\n throw new Error(`Line index out of range: ${line}`);\n }\n const text = this.getTextSlice(offset[0], offset[1], !includeLineBreak);\n this.#lastVisitedLine = [line, includeLineBreak, text];\n this.#lastVisitedLineLength = [line, includeLineBreak, text.length];\n return text;\n }\n\n getLineLength(line: number, includeLineBreak = false): number {\n const lastVisitedLineLength = this.#lastVisitedLineLength;\n const lastVisitedLine = this.#lastVisitedLine;\n if (\n lastVisitedLineLength !== null &&\n lastVisitedLineLength[0] === line &&\n lastVisitedLineLength[1] === includeLineBreak\n ) {\n return lastVisitedLineLength[2];\n }\n if (\n lastVisitedLine !== null &&\n lastVisitedLine[0] === line &&\n lastVisitedLine[1] === includeLineBreak\n ) {\n const length = lastVisitedLine[2].length;\n this.#lastVisitedLineLength = [line, includeLineBreak, length];\n return length;\n }\n const offset = this.#getLineOffset(line);\n if (offset === undefined) {\n throw new Error(`Line index out of range: ${line}`);\n }\n const [start, end] = offset;\n let length = end - start;\n if (!includeLineBreak) {\n while (\n length > 0 &&\n isEOL(this.charAt(start + length - 1).charCodeAt(0))\n ) {\n length--;\n }\n }\n this.#lastVisitedLineLength = [line, includeLineBreak, length];\n return length;\n }\n\n getTextSlice(start: number, end: number, trimEOF = false): string {\n if (start >= end) {\n return '';\n }\n\n const sliceStart = clamp(start, 0, this.#length);\n const sliceEnd = clamp(end, sliceStart, this.#length);\n if (sliceStart >= sliceEnd) {\n return '';\n }\n\n const location = this.#findPieceAtOffset(sliceStart);\n if (location === undefined) {\n return '';\n }\n\n const chunks: string[] = [];\n let [node, offsetInPiece] = location as [PieceNode | null, number];\n let remaining = sliceEnd - sliceStart;\n while (node !== null && remaining > 0) {\n const takeLength = Math.min(node.piece.length - offsetInPiece, remaining);\n const buffer = this.#bufferFor(node.piece.source);\n const start = node.piece.offset + offsetInPiece;\n let end = start + takeLength;\n if (trimEOF) {\n while (end > start && isEOL(buffer.text.charCodeAt(end - 1))) {\n end--;\n }\n }\n chunks.push(buffer.text.slice(start, end));\n remaining -= takeLength;\n offsetInPiece = 0;\n node = this.#nextNode(node);\n }\n\n return chunks.join('');\n }\n\n charAt(offset: number): string {\n const location = this.#findPieceAtOffset(offset);\n if (location === undefined) {\n return '';\n }\n\n const [node, offsetInPiece] = location;\n const buffer = this.#bufferFor(node.piece.source);\n return buffer.text.charAt(node.piece.offset + offsetInPiece);\n }\n\n includes(needle: string): boolean {\n if (needle.length === 0) {\n return true;\n }\n\n const prefixTable = createPrefixTable(needle);\n let matched = 0;\n let found = false;\n this.#forEachPieceSegment((segment) => {\n for (let offset = segment.start; offset < segment.end; offset++) {\n const charCode = segment.text.charCodeAt(offset);\n while (matched > 0 && charCode !== needle.charCodeAt(matched)) {\n matched = prefixTable[matched - 1];\n }\n if (charCode === needle.charCodeAt(matched)) {\n matched++;\n }\n if (matched === needle.length) {\n found = true;\n return false;\n }\n }\n return true;\n });\n return found;\n }\n\n findNextNonOverlappingSubstring(\n needle: string,\n occupied: readonly [start: number, end: number][]\n ): number | undefined {\n if (needle.length === 0 || needle.length > this.#length) {\n return undefined;\n }\n\n const ranges = normalizeRanges(occupied, this.#length);\n const pivot = ranges.reduce((max, [, end]) => Math.max(max, end), 0);\n const prefixTable = createPrefixTable(needle);\n let matched = 0;\n let documentOffset = 0;\n let wrappedOffset: number | undefined;\n let foundOffset: number | undefined;\n\n this.#forEachPieceSegment((segment) => {\n for (let offset = segment.start; offset < segment.end; offset++) {\n const charCode = segment.text.charCodeAt(offset);\n while (matched > 0 && charCode !== needle.charCodeAt(matched)) {\n matched = prefixTable[matched - 1];\n }\n if (charCode === needle.charCodeAt(matched)) {\n matched++;\n }\n if (matched === needle.length) {\n const start = documentOffset - needle.length + 1;\n if (!rangeOverlaps(ranges, start, start + needle.length)) {\n if (start >= pivot) {\n foundOffset = start;\n return false;\n }\n wrappedOffset ??= start;\n }\n matched = prefixTable[matched - 1];\n }\n documentOffset++;\n }\n return true;\n });\n\n return foundOffset ?? wrappedOffset;\n }\n\n search(searchParams: SearchParams): [start: number, end: number][] {\n if (searchParams.text.length === 0 || this.#length === 0) {\n return [];\n }\n\n // Search currently operates line-by-line, so newline-spanning patterns are unsupported.\n if (\n searchParams.text.includes('\\n') ||\n searchParams.text.includes('\\r') ||\n (searchParams.regex &&\n (searchParams.text.includes('\\\\n') ||\n searchParams.text.includes('\\\\r')))\n ) {\n return [];\n }\n\n let pattern: RegExp;\n try {\n pattern = compileSearchRegExp(\n searchParams.text,\n searchParams.regex,\n searchParams.caseSensitive\n );\n } catch {\n return [];\n }\n\n return this.#collectSearchMatchesLineByLine(\n pattern,\n searchParams.wholeWord,\n MAX_FIND_MATCHES\n );\n }\n\n #collectSearchMatchesLineByLine(\n pattern: RegExp,\n wholeWord: boolean,\n limit: number\n ): [number, number][] {\n const out: [number, number][] = [];\n // Search visits the whole document, so flatten it once instead of making\n // several treap descents for every line and whole-word boundary.\n const documentText = this.#textFromPieces();\n const docLength = documentText.length;\n const lineOffsets = computeLineOffsets(documentText);\n\n // Reuse the single compiled pattern across every line, resetting its\n // lastIndex before each line, instead of allocating a fresh RegExp per\n // line. The pattern is global, so lastIndex tracks progress within a line.\n for (let line = 0; line < lineOffsets.length; line++) {\n const lineStart = lineOffsets[line];\n let lineEnd = lineOffsets[line + 1] ?? docLength;\n while (\n lineEnd > lineStart &&\n isEOL(documentText.charCodeAt(lineEnd - 1))\n ) {\n lineEnd--;\n }\n const lineText = documentText.slice(lineStart, lineEnd);\n pattern.lastIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = pattern.exec(lineText)) !== null) {\n const rel = match.index;\n const fragment = match[0];\n if (fragment.length === 0) {\n pattern.lastIndex = advancePastEmptyMatch(lineText, rel);\n continue;\n }\n const docStart = lineStart + rel;\n if (\n !wholeWord ||\n isWholeWordAtDocOffsets(documentText, docStart, fragment.length)\n ) {\n out.push([docStart, docStart + fragment.length]);\n if (out.length >= limit) {\n return out;\n }\n }\n if (rel === pattern.lastIndex) {\n pattern.lastIndex = advancePastEmptyMatch(lineText, rel);\n }\n }\n }\n return out;\n }\n\n insert(text: string, offset: number): void {\n if (text.length === 0) {\n return;\n }\n const start = clamp(offset, 0, this.#length);\n this.#replaceRangeIncremental(start, start, text);\n this.#invalidateCaches();\n }\n\n delete(offset: number, length: number): void {\n if (length <= 0 || this.#length === 0) {\n return;\n }\n const start = clamp(offset, 0, this.#length);\n const end = clamp(start + length, start, this.#length);\n if (start === end) {\n return;\n }\n this.#replaceRangeIncremental(start, end, '');\n this.#invalidateCaches();\n }\n\n applyEdits(edits: readonly ResolvedTextEdit[]): void {\n if (edits.length === 0) {\n return;\n }\n // Edits arrive sorted ascending and non-overlapping (TextDocument enforces\n // this). Applying them from last to first keeps each remaining edit's\n // offsets valid, since edits at higher offsets never shift lower ones, and\n // every edit becomes an O(log P) incremental replace.\n for (let i = edits.length - 1; i >= 0; i--) {\n const edit = edits[i];\n const start = clamp(edit.start, 0, this.#length);\n const end = clamp(edit.end, start, this.#length);\n this.#replaceRangeIncremental(start, end, edit.text);\n }\n this.#invalidateCaches();\n }\n\n positionAt(offset: number): Position {\n const clampedOffset = clamp(offset, 0, this.#length);\n if (this.#length === 0) {\n return { line: 0, character: 0 };\n }\n const line = this.#lineAtOffset(clampedOffset);\n const lineStart = line === 0 ? 0 : this.#lineBreakOffset(line - 1);\n const character = clampedOffset - lineStart;\n this.#lastPosition = [line, character, clampedOffset];\n return { line, character };\n }\n\n positionsAt(offsets: readonly number[]): Position[] {\n const positions: Position[] = Array.from({ length: offsets.length });\n if (offsets.length === 0) {\n return positions;\n }\n if (this.#length === 0) {\n return positions.fill({ line: 0, character: 0 });\n }\n\n for (let i = 0; i < offsets.length; i++) {\n positions[i] = this.positionAt(offsets[i]);\n }\n\n return positions;\n }\n\n offsetAt(position: Position): number {\n if (position.line < 0 || this.#length === 0) {\n return 0;\n }\n if (position.line >= this.#lineCount) {\n throw new Error(`Line index out of range: ${position.line}`);\n }\n const lastPosition = this.#lastPosition;\n if (\n lastPosition !== null &&\n lastPosition[0] === position.line &&\n lastPosition[1] === position.character\n ) {\n return lastPosition[2];\n }\n const offset = this.#getLineOffset(position.line);\n if (offset === undefined) {\n throw new Error(`Line index out of range: ${position.line}`);\n }\n const character = clamp(position.character, 0, offset[1] - offset[0]);\n return offset[0] + character;\n }\n\n #findPieceAtOffset(\n offset: number\n ): [node: PieceNode, offsetInPiece: number] | undefined {\n if (offset < 0 || offset >= this.#length) {\n return undefined;\n }\n\n let node = this.#root;\n let remaining = offset;\n while (node !== null) {\n const leftLength = node.left?.subtreeLength ?? 0;\n if (remaining < leftLength) {\n node = node.left;\n continue;\n }\n\n remaining -= leftLength;\n if (remaining < node.piece.length) {\n return [node, remaining];\n }\n\n remaining -= node.piece.length;\n node = node.right;\n }\n\n return undefined;\n }\n\n #nextNode(node: PieceNode): PieceNode | null {\n if (node.right !== null) {\n let next = node.right;\n while (next.left !== null) {\n next = next.left;\n }\n return next;\n }\n\n let current = node;\n while (current.parent !== null && current === current.parent.right) {\n current = current.parent;\n }\n return current.parent;\n }\n\n #getLineOffset(line: number): [start: number, end: number] | undefined {\n if (line < 0) {\n throw new Error(`Line index out of range: ${line}`);\n }\n if (this.#length === 0) {\n if (line === 0) {\n return [0, 0];\n }\n throw new Error(`Line index out of range: ${line}`);\n }\n if (line >= this.#lineCount) {\n throw new Error(`Line index out of range: ${line}`);\n }\n\n const start = line === 0 ? 0 : this.#lineBreakOffset(line - 1);\n const end =\n line < this.#lineCount - 1 ? this.#lineBreakOffset(line) : this.#length;\n return [start, end];\n }\n\n #lineAtOffset(offset: number): number {\n let node = this.#root;\n let remaining = clamp(offset, 0, this.#length);\n let line = 0;\n\n while (node !== null) {\n const leftLength = node.left?.subtreeLength ?? 0;\n if (remaining < leftLength) {\n node = node.left;\n continue;\n }\n\n line +=\n (node.left?.subtreeLineBreakCount ?? 0) -\n (formsCRLF(node.left?.subtreeLastCharCode, node.piece.firstCharCode)\n ? 1\n : 0);\n remaining -= leftLength;\n if (remaining <= node.piece.length) {\n const buffer = this.#bufferFor(node.piece.source);\n const lineOffsetEnd = Math.min(\n upperBound(buffer.lineOffsets, node.piece.offset + remaining),\n node.piece.lineOffsetEnd\n );\n line += lineOffsetEnd - node.piece.lineOffsetStart;\n if (\n remaining === node.piece.length &&\n node.piece.hasVirtualTrailingCRBreak\n ) {\n line++;\n }\n if (\n remaining === node.piece.length &&\n formsCRLF(\n node.piece.lastCharCode,\n this.#nextNode(node)?.piece.firstCharCode\n )\n ) {\n line--;\n }\n return line;\n }\n\n line +=\n node.piece.lineBreakCount -\n (formsCRLF(node.piece.lastCharCode, node.right?.subtreeFirstCharCode)\n ? 1\n : 0);\n remaining -= node.piece.length;\n node = node.right;\n }\n\n return this.#lineCount - 1;\n }\n\n #lineBreakOffset(lineBreakIndex: number): number {\n let node = this.#root;\n let remaining = lineBreakIndex;\n let documentOffset = 0;\n let followingCharCode: number | undefined;\n\n while (node !== null) {\n const leftLineBreakCount =\n (node.left?.subtreeLineBreakCount ?? 0) -\n (formsCRLF(node.left?.subtreeLastCharCode, node.piece.firstCharCode)\n ? 1\n : 0);\n if (remaining < leftLineBreakCount) {\n followingCharCode = node.piece.firstCharCode;\n node = node.left;\n continue;\n }\n\n const leftLength = node.left?.subtreeLength ?? 0;\n documentOffset += leftLength;\n remaining -= leftLineBreakCount;\n\n const nextCharCode =\n node.right?.subtreeFirstCharCode ?? followingCharCode;\n const pieceLineBreakCount =\n node.piece.lineBreakCount -\n (formsCRLF(node.piece.lastCharCode, nextCharCode) ? 1 : 0);\n if (remaining < pieceLineBreakCount) {\n return (\n documentOffset + this.#pieceLineBreakOffset(node.piece, remaining)\n );\n }\n\n documentOffset += node.piece.length;\n remaining -= pieceLineBreakCount;\n node = node.right;\n }\n\n return this.#length;\n }\n\n #pieceLineBreakOffset(piece: Piece, lineBreakIndex: number): number {\n const bufferLineBreakCount = piece.lineOffsetEnd - piece.lineOffsetStart;\n if (lineBreakIndex < bufferLineBreakCount) {\n const bufferLineOffset = this.#bufferFor(piece.source).lineOffsets[\n piece.lineOffsetStart + lineBreakIndex\n ];\n return bufferLineOffset - piece.offset;\n }\n return piece.length;\n }\n\n #textFromPieces(): string {\n const chunks: string[] = [];\n this.#forEachPieceSegment((segment) => {\n chunks.push(segment.text.slice(segment.start, segment.end));\n });\n return chunks.join('');\n }\n\n #forEachPieceSegment(\n callback: (segment: {\n readonly start: number;\n readonly end: number;\n readonly text: string;\n readonly lineOffsets: number[];\n readonly lineOffsetStart: number;\n readonly lineOffsetEnd: number;\n }) => boolean | void\n ): void {\n this.#walk(this.#root, (node) => {\n const buffer = this.#bufferFor(node.piece.source);\n return callback({\n text: buffer.text,\n lineOffsets: buffer.lineOffsets,\n lineOffsetStart: node.piece.lineOffsetStart,\n lineOffsetEnd: node.piece.lineOffsetEnd,\n start: node.piece.offset,\n end: node.piece.offset + node.piece.length,\n });\n });\n }\n\n #bufferFor(source: number): TextBuffer {\n return source === Piece.Original ? this.#original : this.#add;\n }\n\n #createPiece(source: number, offset: number, length: number): Piece {\n const buffer = this.#bufferFor(source);\n const end = offset + length;\n const lineOffsetStart = upperBound(buffer.lineOffsets, offset);\n const lineOffsetEnd = upperBound(buffer.lineOffsets, end);\n const lastCharCode = buffer.text.charCodeAt(end - 1);\n return new Piece(\n source,\n offset,\n length,\n lineOffsetStart,\n lineOffsetEnd,\n lastCharCode === CARRIAGE_RETURN &&\n buffer.lineOffsets[lineOffsetEnd - 1] !== end,\n buffer.text.charCodeAt(offset),\n lastCharCode\n );\n }\n\n // Replaces document range [start, end) with `text` by splitting at the start,\n // dropping the deleted prefix from the remainder, and joining the inserted\n // piece back in. Each tree operation touches only one root-to-leaf path, so\n // the edit is O(log P) instead of rebuilding all P pieces. `start`/`end` must\n // be clamped into [0, length] with start <= end.\n #replaceRangeIncremental(start: number, end: number, text: string): void {\n if (start === end && text.length === 0) {\n return;\n }\n\n const [left, rest] = this.#split(this.#root, start);\n const right = this.#dropPrefix(rest, end - start);\n\n let root: PieceNode | null;\n if (text.length > 0) {\n const insertedPiece = this.#createPiece(\n Piece.Added,\n this.#add.append(text),\n text.length\n );\n // The inserted text is fresh at the end of the add buffer, so it can only\n // sit next to the piece on its left, never the one on its right.\n root = this.#mergeNodes(\n this.#appendCoalescing(left, insertedPiece),\n right\n );\n } else {\n // Pure deletion: the pieces now meeting at the seam may be contiguous in\n // the same buffer, so re-attach the right side's first piece through the\n // coalescing append to merge them when possible.\n const [seamPiece, restRight] = this.#popLeftmost(right);\n root =\n seamPiece === undefined\n ? left\n : this.#mergeNodes(\n this.#appendCoalescing(left, seamPiece),\n restRight\n );\n }\n\n if (root !== null) {\n root.parent = null;\n }\n this.#root = root;\n this.#length = root?.subtreeLength ?? 0;\n this.#lineCount = (root?.subtreeLineBreakCount ?? 0) + 1;\n }\n\n // Public mutations clear read caches once, including multi-edit batches.\n #invalidateCaches(): void {\n this.#lastVisitedLine = null;\n this.#lastVisitedLineLength = null;\n this.#lastPosition = null;\n }\n\n #nextPriority(): number {\n this.#priorityState =\n (Math.imul(this.#priorityState, 1664525) + 1013904223) >>> 0;\n return this.#priorityState;\n }\n\n #createNode(piece: Piece): PieceNode {\n const node = new PieceNode(piece);\n node.priority = this.#nextPriority();\n return node;\n }\n\n // Attaches `child` as a side of `node`, keeping the parent pointer in sync so\n // read-side iteration (#nextNode) can still walk back up the tree.\n #setLeft(node: PieceNode, child: PieceNode | null): void {\n node.left = child;\n if (child !== null) {\n child.parent = node;\n }\n }\n\n #setRight(node: PieceNode, child: PieceNode | null): void {\n node.right = child;\n if (child !== null) {\n child.parent = node;\n }\n }\n\n // Splits the subtree into [0, offset) and [offset, length). When the offset\n // falls inside a piece, that piece is sliced in two so the split lands on a\n // clean boundary. Internal parent pointers stay correct; the caller fixes the\n // returned roots' own parents when it reattaches or stores them.\n #split(\n node: PieceNode | null,\n offset: number\n ): [left: PieceNode | null, right: PieceNode | null] {\n if (node === null) {\n return [null, null];\n }\n if (offset <= 0) {\n return [null, node];\n }\n if (offset >= node.subtreeLength) {\n return [node, null];\n }\n\n const leftLength = node.left?.subtreeLength ?? 0;\n if (offset <= leftLength) {\n const [left, right] = this.#split(node.left, offset);\n this.#setLeft(node, right);\n node.updateSubtreeLength();\n return [left, node];\n }\n\n const pieceLength = node.piece.length;\n if (offset >= leftLength + pieceLength) {\n const [left, right] = this.#split(\n node.right,\n offset - leftLength - pieceLength\n );\n this.#setRight(node, left);\n node.updateSubtreeLength();\n return [node, right];\n }\n\n // The offset is strictly inside this node's piece: slice it in two. Both\n // halves inherit this node's priority, which keeps the heap valid because\n // this node already outranked both of its children.\n const inPiece = offset - leftLength;\n const leftNode = new PieceNode(\n this.#createPiece(node.piece.source, node.piece.offset, inPiece)\n );\n const rightNode = new PieceNode(\n this.#createPiece(\n node.piece.source,\n node.piece.offset + inPiece,\n pieceLength - inPiece\n )\n );\n leftNode.priority = node.priority;\n rightNode.priority = node.priority;\n this.#setLeft(leftNode, node.left);\n this.#setRight(rightNode, node.right);\n leftNode.updateSubtreeLength();\n rightNode.updateSubtreeLength();\n return [leftNode, rightNode];\n }\n\n // Discards [0, offset), allocating only the surviving half of a cut piece.\n #dropPrefix(node: PieceNode | null, offset: number): PieceNode | null {\n if (node === null || offset >= node.subtreeLength) {\n return null;\n }\n if (offset <= 0) {\n return node;\n }\n\n const leftLength = node.left?.subtreeLength ?? 0;\n if (offset <= leftLength) {\n this.#setLeft(node, this.#dropPrefix(node.left, offset));\n node.updateSubtreeLength();\n return node;\n }\n\n const pieceEnd = leftLength + node.piece.length;\n if (offset >= pieceEnd) {\n return this.#dropPrefix(node.right, offset - pieceEnd);\n }\n\n const inPiece = offset - leftLength;\n const rightNode = new PieceNode(\n this.#createPiece(\n node.piece.source,\n node.piece.offset + inPiece,\n node.piece.length - inPiece\n )\n );\n rightNode.priority = node.priority;\n this.#setRight(rightNode, node.right);\n rightNode.updateSubtreeLength();\n return rightNode;\n }\n\n // Joins two subtrees where every offset in `left` precedes every offset in\n // `right`, taking the higher-priority root so the result stays balanced.\n #mergeNodes(\n left: PieceNode | null,\n right: PieceNode | null\n ): PieceNode | null {\n if (left === null) {\n return right;\n }\n if (right === null) {\n return left;\n }\n if (left.priority >= right.priority) {\n this.#setRight(left, this.#mergeNodes(left.right, right));\n left.updateSubtreeLength();\n return left;\n }\n this.#setLeft(right, this.#mergeNodes(left, right.left));\n right.updateSubtreeLength();\n return right;\n }\n\n // Appends `piece` after every node in `tree`. Compatible adjacent pieces in\n // the same buffer are merged in place, keeping sequential typing compact.\n #appendCoalescing(tree: PieceNode | null, piece: Piece): PieceNode {\n if (tree === null) {\n return this.#createNode(piece);\n }\n let last = tree;\n while (last.right !== null) {\n last = last.right;\n }\n if (canCoalescePieces(last.piece, piece)) {\n last.piece = coalesceTwoPieces(last.piece, piece);\n // The last piece grew, so refresh aggregates from it up to the root.\n for (let node: PieceNode | null = last; node !== null; ) {\n node.updateSubtreeLength();\n if (node === tree) {\n break;\n }\n node = node.parent;\n }\n return tree;\n }\n // `tree` is non-null here, so merging in the new node always yields a node.\n return this.#mergeNodes(tree, this.#createNode(piece)) as PieceNode;\n }\n\n // Removes and returns the first piece of the tree along with the remaining\n // tree, so a deletion seam can re-merge the piece that becomes adjacent to\n // the one on the other side of the deletion.\n #popLeftmost(\n tree: PieceNode | null\n ): [piece: Piece | undefined, rest: PieceNode | null] {\n if (tree === null) {\n return [undefined, null];\n }\n if (tree.left === null) {\n return [tree.piece, tree.right];\n }\n const [piece, newLeft] = this.#popLeftmost(tree.left);\n this.#setLeft(tree, newLeft);\n tree.updateSubtreeLength();\n return [piece, tree];\n }\n\n #walk(\n node: PieceNode | null,\n visit: (node: PieceNode) => boolean | void\n ): boolean {\n if (node === null) {\n return true;\n }\n if (!this.#walk(node.left, visit)) {\n return false;\n }\n if (visit(node) === false) {\n return false;\n }\n return this.#walk(node.right, visit);\n }\n}\n\nfunction isEOL(charCode: number): boolean {\n return charCode === /* \\n */ 10 || charCode === /* \\r */ 13;\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction createPrefixTable(text: string): number[] {\n const table = Array.from<number>({ length: text.length }).fill(0);\n let matched = 0;\n for (let i = 1; i < text.length; i++) {\n const charCode = text.charCodeAt(i);\n while (matched > 0 && charCode !== text.charCodeAt(matched)) {\n matched = table[matched - 1];\n }\n if (charCode === text.charCodeAt(matched)) {\n matched++;\n }\n table[i] = matched;\n }\n return table;\n}\n\nfunction normalizeRanges(\n ranges: readonly [start: number, end: number][],\n length: number\n): [start: number, end: number][] {\n const normalized: [start: number, end: number][] = [];\n for (const [rawStart, rawEnd] of ranges) {\n const start = clamp(rawStart, 0, length);\n const end = clamp(rawEnd, start, length);\n if (start < end) {\n normalized.push([start, end]);\n }\n }\n normalized.sort((a, b) => a[0] - b[0]);\n\n const merged: [start: number, end: number][] = [];\n for (const range of normalized) {\n const previous = merged[merged.length - 1];\n if (previous !== undefined && range[0] <= previous[1]) {\n previous[1] = Math.max(previous[1], range[1]);\n continue;\n }\n merged.push(range);\n }\n return merged;\n}\n\nfunction rangeOverlaps(\n ranges: readonly [start: number, end: number][],\n start: number,\n end: number\n): boolean {\n let low = 0;\n let high = ranges.length;\n while (low < high) {\n const mid = low + Math.floor((high - low) / 2);\n if (ranges[mid][1] <= start) {\n low = mid + 1;\n } else {\n high = mid;\n }\n }\n\n const range = ranges[low];\n return range !== undefined && range[0] < end;\n}\n\n// CRLF seams stay explicit because separately appended buffer chunks may each\n// record a break there; the tree aggregate reconciles the document-level pair.\nfunction canCoalescePieces(prev: Piece, next: Piece): boolean {\n return (\n prev.source === next.source &&\n prev.offset + prev.length === next.offset &&\n !formsCRLF(prev.lastCharCode, next.firstCharCode)\n );\n}\n\n// Joins two adjacent pieces (see canCoalescePieces) into one. Keeping the table\n// compact after every edit is what stops the piece count from growing without\n// bound during normal typing.\nfunction coalesceTwoPieces(prev: Piece, next: Piece): Piece {\n return new Piece(\n prev.source,\n prev.offset,\n prev.length + next.length,\n prev.lineOffsetStart,\n next.lineOffsetEnd,\n next.hasVirtualTrailingCRBreak,\n prev.firstCharCode,\n next.lastCharCode\n );\n}\n\nfunction formsCRLF(\n leftCharCode: number | undefined,\n rightCharCode: number | undefined\n): boolean {\n return leftCharCode === CARRIAGE_RETURN && rightCharCode === LINE_FEED;\n}\n\n// Returns the index of the first element in the array that is greater than the target.\nfunction upperBound(values: number[], target: number): number {\n let lo = 0;\n let hi = values.length;\n while (lo < hi) {\n const mid = lo + Math.floor((hi - lo) / 2);\n if (values[mid] <= target) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n return lo;\n}\n\nfunction escapeRegExp(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nfunction isWordSeparatorCharCode(charCode: number): boolean {\n if (charCode <= 32 || charCode === 127) {\n return true;\n }\n const ch = String.fromCharCode(charCode);\n return WORD_SEPARATORS.includes(ch);\n}\n\n// Checks if the given text is a whole word by checking if the\n// characters before and after are word separators.\nfunction isWholeWordAtDocOffsets(\n text: string,\n docStart: number,\n length: number\n): boolean {\n const beforeOk =\n docStart <= 0 || isWordSeparatorCharCode(text.charCodeAt(docStart - 1));\n const afterOk =\n docStart + length >= text.length ||\n isWordSeparatorCharCode(text.charCodeAt(docStart + length));\n return beforeOk && afterOk;\n}\n\nfunction compileSearchRegExp(\n source: string,\n isRegex: boolean,\n caseSensitive: boolean\n): RegExp {\n const body = isRegex ? source : escapeRegExp(source);\n const flags = `g${caseSensitive ? '' : 'i'}${isRegex ? 'm' : ''}`;\n return new RegExp(body, flags);\n}\n\n/** Expands `$&`, `$1`, `$$`, etc. in a regex replace string using a match. */\nfunction expandReplaceString(\n replacement: string,\n match: RegExpExecArray\n): string {\n return replacement.replace(/\\$([$&]|\\d+)/g, (_token, group: string) => {\n if (group === '$') {\n return '$';\n }\n if (group === '&') {\n return match[0] ?? '';\n }\n const index = Number(group);\n return match[index] ?? '';\n });\n}\n\n/**\n * Builds the text to insert for one search match, including regex capture\n * substitution when regex mode is enabled.\n */\nexport function buildSearchReplacementText(\n positionAt: (offset: number) => Position,\n offsetAt: (position: Position) => number,\n getLineText: (line: number) => string,\n searchParams: SearchParams,\n matchStart: number,\n matchEnd: number\n): string {\n if (!searchParams.regex) {\n return searchParams.replaceText;\n }\n\n const position = positionAt(matchStart);\n const lineText = getLineText(position.line);\n const lineStart = offsetAt({ line: position.line, character: 0 });\n const relStart = matchStart - lineStart;\n\n let pattern: RegExp;\n try {\n pattern = compileSearchRegExp(\n searchParams.text,\n true,\n searchParams.caseSensitive\n );\n } catch {\n return searchParams.replaceText;\n }\n\n // Re-run at the original line offset so lookaround can inspect context\n // outside the matched range while captures still come from this exact hit.\n pattern.lastIndex = relStart;\n const match = pattern.exec(lineText);\n if (\n match === null ||\n match.index !== relStart ||\n match[0].length !== matchEnd - matchStart\n ) {\n return searchParams.replaceText;\n }\n return expandReplaceString(searchParams.replaceText, match);\n}\n\nfunction advancePastEmptyMatch(text: string, index: number): number {\n if (index + 1 < text.length) {\n const first = text.charCodeAt(index);\n const second = text.charCodeAt(index + 1);\n if (\n first >= 0xd800 &&\n first <= 0xdbff &&\n second >= 0xdc00 &&\n second <= 0xdfff\n ) {\n return index + 2;\n }\n }\n return index + 1;\n}\n"],"mappings":";;AAIA,MAAM,mBAAmB;AACzB,MAAM,YAAY;AAClB,MAAM,kBAAkB;AAExB,MAAM,kBAAkB;AAGxB,IAAM,QAAN,MAAY;CAKQ;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAXlB,OAAO,WAAW;CAClB,OAAO,QAAQ;CAEf,YACE,QACA,QACA,QACA,iBACA,eACA,2BACA,eACA,cACA;EARgB,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,kBAAA;EACA,KAAA,gBAAA;EACA,KAAA,4BAAA;EACA,KAAA,gBAAA;EACA,KAAA,eAAA;CACf;CAIH,IAAI,iBAAyB;EAC3B,OACE,KAAK,gBACL,KAAK,mBACJ,KAAK,4BAA4B,IAAI;CAE1C;AACF;AAGA,IAAM,aAAN,MAAiB;CAGI;CAFnB;CAEA,YAAY,MAAqB;EAAd,KAAA,OAAA;EACjB,KAAK,cAAc,mBAAmB,IAAI;CAC5C;CAIA,OAAO,MAAsB;EAC3B,MAAM,SAAS,KAAK,KAAK;EACzB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,WAAW,KAAK,WAAW,CAAC;GAClC,IAAI,aAAa,aAAa,aAAa,iBACzC;GAEF,IACE,aAAa,mBACb,KAAK,WAAW,IAAI,CAAC,MAAM,WAE3B;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BAAkB,QAAQ,UAAkB;EACrE,IAAI,UAAU,KACZ,OAAO;EAET,IAAI,UAAU,KACZ,OAAO,MAAM,MAAM;EAGrB,OAAO,MADO,OAAO,KACJ,MAAM;CACzB,CAAC;AACH;;;;;AAMA,SAAgB,2BACd,YACA,UACA,aACA,cACA,YACA,UACQ;CACR,IAAI,CAAC,aAAa,OAChB,OAAO,aAAa;CAGtB,MAAM,WAAW,WAAW,UAAU;CACtC,MAAM,WAAW,YAAY,SAAS,IAAI;CAE1C,MAAM,WAAW,aADC,SAAS;EAAE,MAAM,SAAS;EAAM,WAAW;CAAE,CACzB;CAEtC,IAAI;CACJ,IAAI;EACF,UAAU,oBACR,aAAa,MACb,MACA,aAAa,aACf;CACF,QAAQ;EACN,OAAO,aAAa;CACtB;CAIA,QAAQ,YAAY;CACpB,MAAM,QAAQ,QAAQ,KAAK,QAAQ;CACnC,IACE,UAAU,QACV,MAAM,UAAU,YAChB,MAAM,EAAE,CAAC,WAAW,WAAW,YAE/B,OAAO,aAAa;CAEtB,OAAO,oBAAoB,aAAa,aAAa,KAAK;AAC5D;AAEA,SAAS,sBAAsB,MAAc,OAAuB;CAClE,IAAI,QAAQ,IAAI,KAAK,QAAQ;EAC3B,MAAM,QAAQ,KAAK,WAAW,KAAK;EACnC,MAAM,SAAS,KAAK,WAAW,QAAQ,CAAC;EACxC,IACE,SAAS,SACT,SAAS,SACT,UAAU,SACV,UAAU,OAEV,OAAO,QAAQ;CAEnB;CACA,OAAO,QAAQ;AACjB"}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
+
import { isLinux, isMacLike, isSafari, resetPlatformDetection } from "../utils/platform.js";
|
|
2
|
+
|
|
1
3
|
//#region src/editor/platform.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Clears the cached platform/browser detection. Detection is memoized on first
|
|
4
|
-
* call, so a test process that swaps `navigator` (e.g. to exercise Linux or
|
|
5
|
-
* Safari behavior) must reset it; otherwise the value cached by an earlier test
|
|
6
|
-
* leaks across tests and no longer matches the active navigator.
|
|
7
|
-
*/
|
|
8
|
-
declare function resetPlatformDetectionForTests(): void;
|
|
9
|
-
declare function isMacLike(): boolean;
|
|
10
|
-
declare function isLinux(): boolean;
|
|
11
|
-
declare function isSafari(): boolean;
|
|
12
4
|
declare function isPrimaryModifier({
|
|
13
5
|
metaKey,
|
|
14
6
|
ctrlKey
|
|
15
7
|
}: MouseEvent | KeyboardEvent, isMac?: boolean): boolean;
|
|
16
8
|
declare function isMoveCursorShortcut(e: KeyboardEvent): 'up' | 'down' | 'left' | 'right' | 'start' | 'textStart' | 'end' | undefined;
|
|
17
9
|
//#endregion
|
|
18
|
-
export { isLinux, isMacLike, isMoveCursorShortcut, isPrimaryModifier, isSafari,
|
|
10
|
+
export { isLinux, isMacLike, isMoveCursorShortcut, isPrimaryModifier, isSafari, resetPlatformDetection };
|
|
19
11
|
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","names":[],"sources":["../../src/editor/platform.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform.d.ts","names":[],"sources":["../../src/editor/platform.ts"],"mappings":";;;iBASgB,iBAAA;EACZ,OAAA;EAAS;AAAA,GAAW,UAAA,GAAa,aAAA,EACnC,KAAA;AAAA,iBAKc,oBAAA,CACd,CAAgB,EAAb,aAAa"}
|
package/dist/editor/platform.js
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
|
+
import { isLinux, isMacLike, isSafari, resetPlatformDetection } from "../utils/platform.js";
|
|
1
2
|
//#region src/editor/platform.ts
|
|
2
|
-
let _isMacLike = void 0;
|
|
3
|
-
let _isLinux = void 0;
|
|
4
|
-
let _isSafari = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Clears the cached platform/browser detection. Detection is memoized on first
|
|
7
|
-
* call, so a test process that swaps `navigator` (e.g. to exercise Linux or
|
|
8
|
-
* Safari behavior) must reset it; otherwise the value cached by an earlier test
|
|
9
|
-
* leaks across tests and no longer matches the active navigator.
|
|
10
|
-
*/
|
|
11
|
-
function resetPlatformDetectionForTests() {
|
|
12
|
-
_isMacLike = void 0;
|
|
13
|
-
_isLinux = void 0;
|
|
14
|
-
_isSafari = void 0;
|
|
15
|
-
}
|
|
16
|
-
function isMacLike() {
|
|
17
|
-
return _isMacLike ??= /macOS|MacIntel|iPhone|iPad|iPod/i.test(getPlatform());
|
|
18
|
-
}
|
|
19
|
-
function isLinux() {
|
|
20
|
-
return _isLinux ??= /Linux/i.test(getPlatform());
|
|
21
|
-
}
|
|
22
|
-
function isSafari() {
|
|
23
|
-
return _isSafari ??= "safari" in window && "pushNotification" in window.safari || /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
24
|
-
}
|
|
25
3
|
function isPrimaryModifier({ metaKey, ctrlKey }, isMac = isMacLike()) {
|
|
26
4
|
return isMac ? metaKey && !ctrlKey : ctrlKey && !metaKey;
|
|
27
5
|
}
|
|
@@ -47,11 +25,7 @@ function isMoveCursorShortcut(e) {
|
|
|
47
25
|
else if (e.key === "ArrowRight") return "end";
|
|
48
26
|
}
|
|
49
27
|
}
|
|
50
|
-
function getPlatform() {
|
|
51
|
-
const navigator = globalThis.navigator;
|
|
52
|
-
return navigator?.platform ?? navigator?.userAgentData?.platform ?? "unknown";
|
|
53
|
-
}
|
|
54
28
|
//#endregion
|
|
55
|
-
export { isLinux, isMacLike, isMoveCursorShortcut, isPrimaryModifier, isSafari,
|
|
29
|
+
export { isLinux, isMacLike, isMoveCursorShortcut, isPrimaryModifier, isSafari, resetPlatformDetection };
|
|
56
30
|
|
|
57
31
|
//# sourceMappingURL=platform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","names":[],"sources":["../../src/editor/platform.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"platform.js","names":[],"sources":["../../src/editor/platform.ts"],"sourcesContent":["import {\n isLinux,\n isMacLike,\n isSafari,\n resetPlatformDetection,\n} from '../utils/platform';\n\nexport { isLinux, isMacLike, isSafari, resetPlatformDetection };\n\nexport function isPrimaryModifier(\n { metaKey, ctrlKey }: MouseEvent | KeyboardEvent,\n isMac: boolean = isMacLike()\n): boolean {\n return isMac ? metaKey && !ctrlKey : ctrlKey && !metaKey;\n}\n\nexport function isMoveCursorShortcut(\n e: KeyboardEvent\n):\n | 'up'\n | 'down'\n | 'left'\n | 'right'\n | 'start'\n | 'textStart'\n | 'end'\n | undefined {\n // emacs key bindings\n if (isMacLike() && e.ctrlKey && !e.altKey && !e.metaKey) {\n switch (e.key) {\n case 'a':\n return 'start';\n case 'e':\n return 'end';\n case 'p':\n return 'up';\n case 'n':\n return 'down';\n case 'f':\n return 'right';\n case 'b':\n return 'left';\n }\n }\n\n if (!e.altKey && !e.ctrlKey && !e.metaKey) {\n if (e.key === 'ArrowUp') {\n return 'up';\n } else if (e.key === 'ArrowDown') {\n return 'down';\n } else if (e.key === 'ArrowLeft') {\n return 'left';\n } else if (e.key === 'ArrowRight') {\n return 'right';\n } else if (e.key === 'Home') {\n return 'start';\n } else if (e.key === 'End') {\n return 'end';\n }\n }\n\n if (isPrimaryModifier(e)) {\n if (e.key === 'ArrowLeft') {\n return 'textStart';\n } else if (e.key === 'ArrowRight') {\n return 'end';\n }\n }\n\n return undefined;\n}\n"],"mappings":";;AASA,SAAgB,kBACd,EAAE,SAAS,WACX,QAAiB,UAAU,GAClB;CACT,OAAO,QAAQ,WAAW,CAAC,UAAU,WAAW,CAAC;AACnD;AAEA,SAAgB,qBACd,GASY;CAEZ,IAAI,UAAU,KAAK,EAAE,WAAW,CAAC,EAAE,UAAU,CAAC,EAAE,SAC9C,QAAQ,EAAE,KAAV;EACE,KAAK,KACH,OAAO;EACT,KAAK,KACH,OAAO;EACT,KAAK,KACH,OAAO;EACT,KAAK,KACH,OAAO;EACT,KAAK,KACH,OAAO;EACT,KAAK,KACH,OAAO;CACX;CAGF,IAAI,CAAC,EAAE,UAAU,CAAC,EAAE,WAAW,CAAC,EAAE;MAC5B,EAAE,QAAQ,WACZ,OAAO;OACF,IAAI,EAAE,QAAQ,aACnB,OAAO;OACF,IAAI,EAAE,QAAQ,aACnB,OAAO;OACF,IAAI,EAAE,QAAQ,cACnB,OAAO;OACF,IAAI,EAAE,QAAQ,QACnB,OAAO;OACF,IAAI,EAAE,QAAQ,OACnB,OAAO;CAAA;CAIX,IAAI,kBAAkB,CAAC;MACjB,EAAE,QAAQ,aACZ,OAAO;OACF,IAAI,EAAE,QAAQ,cACnB,OAAO;CAAA;AAKb"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ResolvedTextEdit
|
|
1
|
+
import { ResolvedTextEdit } from "../types.js";
|
|
2
|
+
import { TextDocument } from "./textDocument.js";
|
|
2
3
|
|
|
3
4
|
//#region src/editor/searchPanel.d.ts
|
|
4
5
|
type MatchRange = [startOffset: number, endOffset: number];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchPanel.d.ts","names":[],"sources":["../../src/editor/searchPanel.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"searchPanel.d.ts","names":[],"sources":["../../src/editor/searchPanel.ts"],"mappings":";;;;KAQY,UAAA,IAAc,WAAA,UAAqB,SAAS;AAAA,KAE5C,eAAA;AAAA,UAEK,YAAA;EACf,IAAA;EACA,WAAA;EACA,aAAA;EACA,SAAA;EACA,KAAA;AAAA;AAAA,UAGe,kBAAA;EACf,YAAA,EAAc,YAAA;EACd,gBAAA,EAAkB,WAAA;EAClB,YAAA;EACA,IAAA,GAAO,eAAA;EACP,YAAA,GAAe,UAAA;EACf,aAAA,GAAgB,SAAA,EAAW,UAAA,EAAY,WAAA;EACvC,YAAA,GAAe,KAAA,EAAO,gBAAA;EACtB,QAAA,GACE,OAAA,EAAS,UAAA,IACT,OAAA;IAAY,aAAA;EAAA,MACT,UAAA;EACL,OAAA;AAAA;AAAA,cAGW,iBAAA;EAAA;EAQX,WAAA,CAAY,OAAA,EAAS,kBAAA;EA8YrB,KAAA;EAIA,QAAA,CAAS,YAAA;EAIT,aAAA,CAAc,OAAA;IAAY,aAAA;EAAA;EAI1B,OAAA,CAAQ,IAAA,EAAM,eAAe;EAO7B,KAAA;EAOA,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchPanel.js","names":["#updateMatches","#navigate","#close","#inputElement","#applyMode","#container"],"sources":["../../src/editor/searchPanel.ts"],"sourcesContent":["import { resolveFindAgainShortcut } from './command';\nimport { buildSearchReplacementText } from './pieceTable';\nimport { isPrimaryModifier } from './platform';\nimport { getEditorIconSvg, type SVGSpriteNames } from './sprite';\nimport type { ResolvedTextEdit, TextDocument } from './textDocument';\nimport { h } from './utils';\n\nexport type MatchRange = [startOffset: number, endOffset: number];\n\nexport type SearchPanelMode = 'find' | 'replace';\n\nexport interface SearchParams {\n text: string;\n replaceText: string;\n caseSensitive: boolean;\n wholeWord: boolean;\n regex: boolean;\n}\n\nexport interface SearchPanelOptions {\n textDocument: TextDocument<unknown>;\n containerElement: HTMLElement;\n defaultQuery: string;\n mode?: SearchPanelMode;\n initialMatch?: MatchRange;\n scrollToMatch: (nextMatch: MatchRange, retainFocus: boolean) => void;\n applyReplace: (edits: ResolvedTextEdit[]) => void;\n onUpdate: (\n matches: MatchRange[],\n options?: { syncSelection?: boolean }\n ) => MatchRange | undefined;\n onClose: () => void;\n}\n\nexport class SearchPanelWidget {\n #container: HTMLDivElement;\n #inputElement: HTMLInputElement;\n #updateMatches?: (options?: { syncSelection?: boolean }) => void;\n #applyMode?: (mode: SearchPanelMode) => void;\n #navigate?: (findPrevious: boolean) => void;\n #close?: () => void;\n\n constructor(options: SearchPanelOptions) {\n const {\n textDocument,\n containerElement,\n defaultQuery,\n mode = 'find',\n initialMatch,\n scrollToMatch,\n applyReplace,\n onUpdate,\n onClose,\n } = options;\n\n const searchParams: SearchParams = {\n text: defaultQuery,\n replaceText: '',\n caseSensitive: false,\n wholeWord: false,\n regex: false,\n };\n\n const matches = {\n all: [] as MatchRange[],\n current: undefined as MatchRange | undefined,\n };\n\n // Default to the empty-query \"no results\" state so it shows on open before\n // any search runs.\n const matchResultElement = h('div', {\n dataset: { matches: '', noMatches: '' },\n textContent: 'No results',\n });\n const updateMatches = (options?: { syncSelection?: boolean }) => {\n matches.all =\n searchParams.text !== '' ? textDocument.search(searchParams) : [];\n const noMatches = matches.all.length === 0;\n prevButton.disabled = noMatches;\n nextButton.disabled = noMatches;\n\n // An empty query and a query with zero hits are the same \"no results\"\n // state. Both push an empty match set through onUpdate so the editor\n // drops #matches and clears the painted highlights.\n if (noMatches) {\n matchResultElement.textContent = 'No results';\n matchResultElement.dataset.noMatches = '';\n matches.current = undefined;\n onUpdate([]);\n return;\n }\n\n delete matchResultElement.dataset.noMatches;\n if (options?.syncSelection === false) {\n const currentMatch = onUpdate(matches.all, { syncSelection: false });\n updateCurrentMatch(currentMatch);\n return;\n }\n\n updateCurrentMatch(onUpdate(matches.all));\n };\n this.#updateMatches = updateMatches;\n\n const updateCurrentMatch = (currentMatch: MatchRange | undefined) => {\n if (currentMatch === undefined) {\n matchResultElement.textContent = `${matches.all.length} results`;\n } else {\n const [start, end] = currentMatch;\n const index = matches.all.findIndex(\n (m) => m[0] === start && m[1] === end\n );\n matchResultElement.textContent = `${index + 1} of ${matches.all.length}`;\n }\n matches.current = currentMatch;\n };\n\n const updateSearchParam = <K extends keyof SearchParams>(\n key: K,\n value: SearchParams[K]\n ) => {\n searchParams[key] = value;\n updateMatches();\n };\n\n const findNextMatch = (\n findPrevious: boolean = false,\n retainFocus: boolean = false\n ) => {\n const allMatches = matches.all;\n let nextMatch: MatchRange | undefined = allMatches[0];\n if (allMatches.length > 0) {\n if (findPrevious) {\n const searchOffset = matches.current?.[0] ?? 0;\n nextMatch = allMatches.at(-1);\n for (const m of allMatches) {\n if (m[1] <= searchOffset) {\n nextMatch = m;\n } else {\n break;\n }\n }\n } else {\n const searchOffset = matches.current?.[1] ?? 0;\n for (const m of allMatches) {\n if (m[0] >= searchOffset) {\n nextMatch = m;\n break;\n }\n }\n }\n }\n if (nextMatch !== undefined) {\n updateCurrentMatch(nextMatch);\n scrollToMatch(nextMatch, retainFocus);\n }\n matches.current = nextMatch;\n };\n // Keep focus in the panel when stepping through matches from the inputs.\n this.#navigate = (findPrevious: boolean) =>\n findNextMatch(findPrevious, true);\n\n const buildReplacementEdit = (\n matchStart: number,\n matchEnd: number\n ): ResolvedTextEdit => ({\n start: matchStart,\n end: matchEnd,\n text: buildSearchReplacementText(\n (offset) => textDocument.positionAt(offset),\n (position) => textDocument.offsetAt(position),\n (line) => textDocument.getLineText(line),\n searchParams,\n matchStart,\n matchEnd\n ),\n });\n\n const replace = () => {\n if (searchParams.text === '' || matches.all.length === 0) {\n return;\n }\n\n let currentMatch = matches.current;\n if (currentMatch === undefined) {\n findNextMatch(false, true);\n currentMatch = matches.current;\n if (currentMatch === undefined) {\n return;\n }\n }\n\n const [start, end] = currentMatch;\n const edit = buildReplacementEdit(start, end);\n applyReplace([edit]);\n\n // Collapse after the replacement so the next search pass advances.\n scrollToMatch([start + edit.text.length, start + edit.text.length], true);\n matches.current = undefined;\n updateMatches();\n };\n\n const replaceAll = () => {\n if (searchParams.text === '' || matches.all.length === 0) {\n return;\n }\n\n applyReplace(\n matches.all.map(([start, end]) => buildReplacementEdit(start, end))\n );\n matches.current = undefined;\n updateMatches();\n };\n\n const close = () => {\n this.cleanup();\n onClose();\n };\n this.#close = close;\n\n // Shared builder for the panel's icon controls. Every clickable control is a\n // real <button> so it gets focus, keyboard activation, and native disabled\n // handling for free; `getEditorIconSvg` marks the glyph aria-hidden, so the\n // accessible name comes from `label` (also used as the hover title).\n const iconButton = (opts: {\n icon: SVGSpriteNames;\n label: string;\n size?: number;\n dataset?: Record<string, string>;\n onClick: () => void;\n }) =>\n h('button', {\n type: 'button',\n title: opts.label,\n ariaLabel: opts.label,\n dataset: { searchIcon: '', ...opts.dataset },\n innerHTML: getEditorIconSvg(opts.icon, opts.size ?? 16),\n onclick: opts.onClick,\n });\n\n // Builds an always-visible icon button that toggles one boolean search\n // option (case/whole-word/regex). The button reflects its on/off state via\n // `aria-pressed` so the stylesheet can highlight it and assistive tech can\n // announce it.\n const makeToggle = (\n icon: SVGSpriteNames,\n title: string,\n key: 'caseSensitive' | 'wholeWord' | 'regex'\n ) => {\n const button = iconButton({\n icon,\n label: title,\n size: 14,\n onClick: () => {\n const next = !searchParams[key];\n button.ariaPressed = String(next);\n updateSearchParam(key, next);\n },\n });\n button.ariaPressed = String(searchParams[key]);\n return button;\n };\n\n const caseSensitiveToggle = makeToggle(\n 'case',\n 'Match Case',\n 'caseSensitive'\n );\n const wholeWordToggle = makeToggle('whole-word', 'Whole Word', 'wholeWord');\n const regexToggle = makeToggle('regex', 'Regexp', 'regex');\n\n const replaceInputElement = h('input', {\n type: 'text',\n placeholder: 'Replace',\n dataset: 'replace',\n value: '',\n oninput: (e: Event) => {\n searchParams.replaceText = (e.target as HTMLInputElement).value;\n },\n onkeydown: (e: KeyboardEvent) => {\n if (e.isComposing) {\n return;\n }\n const findAgain = resolveFindAgainShortcut(e);\n if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Enter') {\n e.preventDefault();\n replace();\n } else if (findAgain !== undefined) {\n e.preventDefault();\n findNextMatch(findAgain === 'previous', true);\n }\n },\n });\n\n this.#inputElement = h('input', {\n type: 'text',\n placeholder: 'Search',\n dataset: 'search',\n value: defaultQuery,\n oninput: (e: Event) => {\n searchParams.text = (e.target as HTMLInputElement).value;\n matches.current = undefined;\n updateMatches();\n },\n onkeydown: (e: KeyboardEvent) => {\n const findAgain = resolveFindAgainShortcut(e);\n if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Enter') {\n e.preventDefault();\n findNextMatch(e.shiftKey, true);\n } else if (findAgain !== undefined) {\n // Override the native browser find-again shortcut so cmd+g steps to\n // the next match and cmd+shift+g to the previous one.\n e.preventDefault();\n findNextMatch(findAgain === 'previous', true);\n } else if (\n isPrimaryModifier(e) &&\n (e.key === 'f' || e.code === 'KeyF')\n ) {\n // Prevent the default browser search panel and switch the panel mode\n // in place (cmd+f -> find, cmd+opt+f -> find/replace).\n e.preventDefault();\n applyMode(e.altKey ? 'replace' : 'find');\n }\n },\n });\n\n // The three search-option toggles are overlaid on the right edge of the\n // find input instead of sitting beside it.\n const searchTogglesElement = h('div', {\n dataset: 'searchToggles',\n children: [caseSensitiveToggle, wholeWordToggle, regexToggle],\n });\n\n const findInputBox = h('div', {\n dataset: { inputBox: '', find: '' },\n children: [this.#inputElement, searchTogglesElement],\n });\n\n // The replace input and its action buttons are tagged as replace cells so\n // they can be hidden together when the panel is in find-only mode.\n const replaceInputBox = h('div', {\n dataset: { inputBox: '', replace: '', replaceCell: '' },\n children: [replaceInputElement],\n });\n\n const replaceActionsElement = h('div', {\n dataset: { replaceActions: '', replaceCell: '' },\n children: [\n iconButton({ icon: 'replace', label: 'Replace', onClick: replace }),\n iconButton({\n icon: 'replace-all',\n label: 'Replace All',\n onClick: replaceAll,\n }),\n ],\n });\n\n // Held so the no-results state can toggle their native disabled flag.\n const prevButton = iconButton({\n icon: 'arrow-up',\n label: 'Previous',\n onClick: () => {\n findNextMatch(true);\n },\n });\n const nextButton = iconButton({\n icon: 'arrow-down',\n label: 'Next',\n onClick: () => {\n findNextMatch();\n },\n });\n prevButton.disabled = true;\n nextButton.disabled = true;\n\n const navElement = h('div', {\n dataset: 'searchNav',\n children: [prevButton, nextButton],\n });\n\n const closeElement = iconButton({\n icon: 'close',\n label: 'Close',\n onClick: close,\n dataset: { searchClose: '' },\n });\n\n // Cells are positioned by CSS grid-template-areas (see editor.css), so DOM\n // order here only drives tab/reading order, not layout. Keep the replace\n // input directly after the find input (and its toggles) so Tab walks\n // find -> replace before reaching the nav arrows and close button.\n const gridElement = h('div', {\n dataset: { searchGrid: '', mode },\n children: [\n findInputBox,\n replaceInputBox,\n replaceActionsElement,\n matchResultElement,\n navElement,\n closeElement,\n ],\n });\n\n // Toggles the panel between find and find/replace modes by showing or\n // hiding the replace cells, then returns focus to the find input.\n const applyMode = (next: SearchPanelMode) => {\n gridElement.dataset.mode = next;\n this.#inputElement.focus();\n this.#inputElement.select();\n };\n this.#applyMode = applyMode;\n\n this.#container = h('div', {\n dataset: 'searchPanel',\n children: [\n h('div', {\n dataset: 'editorWidget',\n children: [gridElement],\n }),\n ],\n });\n\n matches.current = initialMatch;\n containerElement.before(this.#container);\n\n requestAnimationFrame(() => {\n if (initialMatch !== undefined) {\n updateMatches();\n } else {\n onUpdate([]);\n }\n this.#inputElement.select();\n });\n }\n\n focus(): void {\n this.#inputElement.focus();\n }\n\n navigate(findPrevious: boolean): void {\n this.#navigate?.(findPrevious);\n }\n\n updateMatches(options?: { syncSelection?: boolean }): void {\n this.#updateMatches?.(options);\n }\n\n setMode(mode: SearchPanelMode): void {\n this.#applyMode?.(mode);\n }\n\n // Tears the panel down the way the close button and Escape-in-input do:\n // removes the DOM and runs onClose so the editor clears its match highlights.\n // Prefer this over cleanup() for any user-initiated dismissal.\n close(): void {\n this.#close?.();\n }\n\n // DOM-only teardown. Does NOT run onClose, so it leaves the editor's match\n // highlights in place; only use it when the caller clears that state itself\n // (e.g. a full editor reset). User-initiated dismissals should call close().\n cleanup(): void {\n this.#container.remove();\n }\n}\n"],"mappings":";;;;;;AAkCA,IAAa,oBAAb,MAA+B;CAC7B;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA6B;EACvC,MAAM,EACJ,cACA,kBACA,cACA,OAAO,QACP,cACA,eACA,cACA,UACA,YACE;EAEJ,MAAM,eAA6B;GACjC,MAAM;GACN,aAAa;GACb,eAAe;GACf,WAAW;GACX,OAAO;EACT;EAEA,MAAM,UAAU;GACd,KAAK,CAAC;GACN,SAAS,KAAA;EACX;EAIA,MAAM,qBAAqB,EAAE,OAAO;GAClC,SAAS;IAAE,SAAS;IAAI,WAAW;GAAG;GACtC,aAAa;EACf,CAAC;EACD,MAAM,iBAAiB,YAA0C;GAC/D,Q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,YAAY;IAAI;GAAK;GAChC,UAAU;IACR;IACA;IACA;IACA;IACA;IACA;GACF;EACF,CAAC;EAID,MAAM,aAAa,SAA0B;GAC3C,YAAY,QAAQ,OAAO;GAC3B,KAAKA,cAAc,MAAM;GACzB,KAAKA,cAAc,OAAO;EAC5B;EACA,KAAKC,aAAa;EAElB,KAAKC,aAAa,EAAE,OAAO;GACzB,SAAS;GACT,UAAU,CACR,EAAE,OAAO;IACP,SAAS;IACT,UAAU,CAAC,WAAW;GACxB,CAAC,CACH;EACF,CAAC;EAED,QAAQ,UAAU;EAClB,iBAAiB,OAAO,KAAKA,UAAU;EAEvC,4BAA4B;GAC1B,IAAI,iBAAiB,KAAA,GACnB,cAAc;QAEd,SAAS,CAAC,CAAC;GAEb,KAAKF,cAAc,OAAO;EAC5B,CAAC;CACH;CAEA,QAAc;EACZ,KAAKA,cAAc,MAAM;CAC3B;CAEA,SAAS,cAA6B;EACpC,KAAKF,YAAY,YAAY;CAC/B;CAEA,cAAc,SAA6C;EACzD,KAAKD,iBAAiB,OAAO;CAC/B;CAEA,QAAQ,MAA6B;EACnC,KAAKI,aAAa,IAAI;CACxB;CAKA,QAAc;EACZ,KAAKF,SAAS;CAChB;CAKA,UAAgB;EACd,KAAKG,WAAW,OAAO;CACzB;AACF"}
|
|
1
|
+
{"version":3,"file":"searchPanel.js","names":["#updateMatches","#navigate","#close","#inputElement","#applyMode","#container"],"sources":["../../src/editor/searchPanel.ts"],"sourcesContent":["import type { ResolvedTextEdit } from '../types';\nimport { resolveFindAgainShortcut } from './command';\nimport { buildSearchReplacementText } from './pieceTable';\nimport { isPrimaryModifier } from './platform';\nimport { getEditorIconSvg, type SVGSpriteNames } from './sprite';\nimport type { TextDocument } from './textDocument';\nimport { h } from './utils';\n\nexport type MatchRange = [startOffset: number, endOffset: number];\n\nexport type SearchPanelMode = 'find' | 'replace';\n\nexport interface SearchParams {\n text: string;\n replaceText: string;\n caseSensitive: boolean;\n wholeWord: boolean;\n regex: boolean;\n}\n\nexport interface SearchPanelOptions {\n textDocument: TextDocument<unknown>;\n containerElement: HTMLElement;\n defaultQuery: string;\n mode?: SearchPanelMode;\n initialMatch?: MatchRange;\n scrollToMatch: (nextMatch: MatchRange, retainFocus: boolean) => void;\n applyReplace: (edits: ResolvedTextEdit[]) => void;\n onUpdate: (\n matches: MatchRange[],\n options?: { syncSelection?: boolean }\n ) => MatchRange | undefined;\n onClose: () => void;\n}\n\nexport class SearchPanelWidget {\n #container: HTMLDivElement;\n #inputElement: HTMLInputElement;\n #updateMatches?: (options?: { syncSelection?: boolean }) => void;\n #applyMode?: (mode: SearchPanelMode) => void;\n #navigate?: (findPrevious: boolean) => void;\n #close?: () => void;\n\n constructor(options: SearchPanelOptions) {\n const {\n textDocument,\n containerElement,\n defaultQuery,\n mode = 'find',\n initialMatch,\n scrollToMatch,\n applyReplace,\n onUpdate,\n onClose,\n } = options;\n\n const searchParams: SearchParams = {\n text: defaultQuery,\n replaceText: '',\n caseSensitive: false,\n wholeWord: false,\n regex: false,\n };\n\n const matches = {\n all: [] as MatchRange[],\n current: undefined as MatchRange | undefined,\n };\n\n // Default to the empty-query \"no results\" state so it shows on open before\n // any search runs.\n const matchResultElement = h('div', {\n dataset: { matches: '', noMatches: '' },\n textContent: 'No results',\n });\n const updateMatches = (options?: { syncSelection?: boolean }) => {\n matches.all =\n searchParams.text !== '' ? textDocument.search(searchParams) : [];\n const noMatches = matches.all.length === 0;\n prevButton.disabled = noMatches;\n nextButton.disabled = noMatches;\n\n // An empty query and a query with zero hits are the same \"no results\"\n // state. Both push an empty match set through onUpdate so the editor\n // drops #matches and clears the painted highlights.\n if (noMatches) {\n matchResultElement.textContent = 'No results';\n matchResultElement.dataset.noMatches = '';\n matches.current = undefined;\n onUpdate([]);\n return;\n }\n\n delete matchResultElement.dataset.noMatches;\n if (options?.syncSelection === false) {\n const currentMatch = onUpdate(matches.all, { syncSelection: false });\n updateCurrentMatch(currentMatch);\n return;\n }\n\n updateCurrentMatch(onUpdate(matches.all));\n };\n this.#updateMatches = updateMatches;\n\n const updateCurrentMatch = (currentMatch: MatchRange | undefined) => {\n if (currentMatch === undefined) {\n matchResultElement.textContent = `${matches.all.length} results`;\n } else {\n const [start, end] = currentMatch;\n const index = matches.all.findIndex(\n (m) => m[0] === start && m[1] === end\n );\n matchResultElement.textContent = `${index + 1} of ${matches.all.length}`;\n }\n matches.current = currentMatch;\n };\n\n const updateSearchParam = <K extends keyof SearchParams>(\n key: K,\n value: SearchParams[K]\n ) => {\n searchParams[key] = value;\n updateMatches();\n };\n\n const findNextMatch = (\n findPrevious: boolean = false,\n retainFocus: boolean = false\n ) => {\n const allMatches = matches.all;\n let nextMatch: MatchRange | undefined = allMatches[0];\n if (allMatches.length > 0) {\n if (findPrevious) {\n const searchOffset = matches.current?.[0] ?? 0;\n nextMatch = allMatches.at(-1);\n for (const m of allMatches) {\n if (m[1] <= searchOffset) {\n nextMatch = m;\n } else {\n break;\n }\n }\n } else {\n const searchOffset = matches.current?.[1] ?? 0;\n for (const m of allMatches) {\n if (m[0] >= searchOffset) {\n nextMatch = m;\n break;\n }\n }\n }\n }\n if (nextMatch !== undefined) {\n updateCurrentMatch(nextMatch);\n scrollToMatch(nextMatch, retainFocus);\n }\n matches.current = nextMatch;\n };\n // Keep focus in the panel when stepping through matches from the inputs.\n this.#navigate = (findPrevious: boolean) =>\n findNextMatch(findPrevious, true);\n\n const buildReplacementEdit = (\n matchStart: number,\n matchEnd: number\n ): ResolvedTextEdit => ({\n start: matchStart,\n end: matchEnd,\n text: buildSearchReplacementText(\n (offset) => textDocument.positionAt(offset),\n (position) => textDocument.offsetAt(position),\n (line) => textDocument.getLineText(line),\n searchParams,\n matchStart,\n matchEnd\n ),\n });\n\n const replace = () => {\n if (searchParams.text === '' || matches.all.length === 0) {\n return;\n }\n\n let currentMatch = matches.current;\n if (currentMatch === undefined) {\n findNextMatch(false, true);\n currentMatch = matches.current;\n if (currentMatch === undefined) {\n return;\n }\n }\n\n const [start, end] = currentMatch;\n const edit = buildReplacementEdit(start, end);\n applyReplace([edit]);\n\n // Collapse after the replacement so the next search pass advances.\n scrollToMatch([start + edit.text.length, start + edit.text.length], true);\n matches.current = undefined;\n updateMatches();\n };\n\n const replaceAll = () => {\n if (searchParams.text === '' || matches.all.length === 0) {\n return;\n }\n\n applyReplace(\n matches.all.map(([start, end]) => buildReplacementEdit(start, end))\n );\n matches.current = undefined;\n updateMatches();\n };\n\n const close = () => {\n this.cleanup();\n onClose();\n };\n this.#close = close;\n\n // Shared builder for the panel's icon controls. Every clickable control is a\n // real <button> so it gets focus, keyboard activation, and native disabled\n // handling for free; `getEditorIconSvg` marks the glyph aria-hidden, so the\n // accessible name comes from `label` (also used as the hover title).\n const iconButton = (opts: {\n icon: SVGSpriteNames;\n label: string;\n size?: number;\n dataset?: Record<string, string>;\n onClick: () => void;\n }) =>\n h('button', {\n type: 'button',\n title: opts.label,\n ariaLabel: opts.label,\n dataset: { searchIcon: '', ...opts.dataset },\n innerHTML: getEditorIconSvg(opts.icon, opts.size ?? 16),\n onclick: opts.onClick,\n });\n\n // Builds an always-visible icon button that toggles one boolean search\n // option (case/whole-word/regex). The button reflects its on/off state via\n // `aria-pressed` so the stylesheet can highlight it and assistive tech can\n // announce it.\n const makeToggle = (\n icon: SVGSpriteNames,\n title: string,\n key: 'caseSensitive' | 'wholeWord' | 'regex'\n ) => {\n const button = iconButton({\n icon,\n label: title,\n size: 14,\n onClick: () => {\n const next = !searchParams[key];\n button.ariaPressed = String(next);\n updateSearchParam(key, next);\n },\n });\n button.ariaPressed = String(searchParams[key]);\n return button;\n };\n\n const caseSensitiveToggle = makeToggle(\n 'case',\n 'Match Case',\n 'caseSensitive'\n );\n const wholeWordToggle = makeToggle('whole-word', 'Whole Word', 'wholeWord');\n const regexToggle = makeToggle('regex', 'Regexp', 'regex');\n\n const replaceInputElement = h('input', {\n type: 'text',\n placeholder: 'Replace',\n dataset: 'replace',\n value: '',\n oninput: (e: Event) => {\n searchParams.replaceText = (e.target as HTMLInputElement).value;\n },\n onkeydown: (e: KeyboardEvent) => {\n if (e.isComposing) {\n return;\n }\n const findAgain = resolveFindAgainShortcut(e);\n if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Enter') {\n e.preventDefault();\n replace();\n } else if (findAgain !== undefined) {\n e.preventDefault();\n findNextMatch(findAgain === 'previous', true);\n }\n },\n });\n\n this.#inputElement = h('input', {\n type: 'text',\n placeholder: 'Search',\n dataset: 'search',\n value: defaultQuery,\n oninput: (e: Event) => {\n searchParams.text = (e.target as HTMLInputElement).value;\n matches.current = undefined;\n updateMatches();\n },\n onkeydown: (e: KeyboardEvent) => {\n const findAgain = resolveFindAgainShortcut(e);\n if (e.key === 'Escape') {\n e.preventDefault();\n close();\n } else if (e.key === 'Enter') {\n e.preventDefault();\n findNextMatch(e.shiftKey, true);\n } else if (findAgain !== undefined) {\n // Override the native browser find-again shortcut so cmd+g steps to\n // the next match and cmd+shift+g to the previous one.\n e.preventDefault();\n findNextMatch(findAgain === 'previous', true);\n } else if (\n isPrimaryModifier(e) &&\n (e.key === 'f' || e.code === 'KeyF')\n ) {\n // Prevent the default browser search panel and switch the panel mode\n // in place (cmd+f -> find, cmd+opt+f -> find/replace).\n e.preventDefault();\n applyMode(e.altKey ? 'replace' : 'find');\n }\n },\n });\n\n // The three search-option toggles are overlaid on the right edge of the\n // find input instead of sitting beside it.\n const searchTogglesElement = h('div', {\n dataset: 'searchToggles',\n children: [caseSensitiveToggle, wholeWordToggle, regexToggle],\n });\n\n const findInputBox = h('div', {\n dataset: { inputBox: '', find: '' },\n children: [this.#inputElement, searchTogglesElement],\n });\n\n // The replace input and its action buttons are tagged as replace cells so\n // they can be hidden together when the panel is in find-only mode.\n const replaceInputBox = h('div', {\n dataset: { inputBox: '', replace: '', replaceCell: '' },\n children: [replaceInputElement],\n });\n\n const replaceActionsElement = h('div', {\n dataset: { replaceActions: '', replaceCell: '' },\n children: [\n iconButton({ icon: 'replace', label: 'Replace', onClick: replace }),\n iconButton({\n icon: 'replace-all',\n label: 'Replace All',\n onClick: replaceAll,\n }),\n ],\n });\n\n // Held so the no-results state can toggle their native disabled flag.\n const prevButton = iconButton({\n icon: 'arrow-up',\n label: 'Previous',\n onClick: () => {\n findNextMatch(true);\n },\n });\n const nextButton = iconButton({\n icon: 'arrow-down',\n label: 'Next',\n onClick: () => {\n findNextMatch();\n },\n });\n prevButton.disabled = true;\n nextButton.disabled = true;\n\n const navElement = h('div', {\n dataset: 'searchNav',\n children: [prevButton, nextButton],\n });\n\n const closeElement = iconButton({\n icon: 'close',\n label: 'Close',\n onClick: close,\n dataset: { searchClose: '' },\n });\n\n // Cells are positioned by CSS grid-template-areas (see editor.css), so DOM\n // order here only drives tab/reading order, not layout. Keep the replace\n // input directly after the find input (and its toggles) so Tab walks\n // find -> replace before reaching the nav arrows and close button.\n const gridElement = h('div', {\n dataset: { searchGrid: '', mode },\n children: [\n findInputBox,\n replaceInputBox,\n replaceActionsElement,\n matchResultElement,\n navElement,\n closeElement,\n ],\n });\n\n // Toggles the panel between find and find/replace modes by showing or\n // hiding the replace cells, then returns focus to the find input.\n const applyMode = (next: SearchPanelMode) => {\n gridElement.dataset.mode = next;\n this.#inputElement.focus();\n this.#inputElement.select();\n };\n this.#applyMode = applyMode;\n\n this.#container = h('div', {\n dataset: 'searchPanel',\n children: [\n h('div', {\n dataset: 'editorWidget',\n children: [gridElement],\n }),\n ],\n });\n\n matches.current = initialMatch;\n containerElement.before(this.#container);\n\n requestAnimationFrame(() => {\n if (initialMatch !== undefined) {\n updateMatches();\n } else {\n onUpdate([]);\n }\n this.#inputElement.select();\n });\n }\n\n focus(): void {\n this.#inputElement.focus();\n }\n\n navigate(findPrevious: boolean): void {\n this.#navigate?.(findPrevious);\n }\n\n updateMatches(options?: { syncSelection?: boolean }): void {\n this.#updateMatches?.(options);\n }\n\n setMode(mode: SearchPanelMode): void {\n this.#applyMode?.(mode);\n }\n\n // Tears the panel down the way the close button and Escape-in-input do:\n // removes the DOM and runs onClose so the editor clears its match highlights.\n // Prefer this over cleanup() for any user-initiated dismissal.\n close(): void {\n this.#close?.();\n }\n\n // DOM-only teardown. Does NOT run onClose, so it leaves the editor's match\n // highlights in place; only use it when the caller clears that state itself\n // (e.g. a full editor reset). User-initiated dismissals should call close().\n cleanup(): void {\n this.#container.remove();\n }\n}\n"],"mappings":";;;;;;AAmCA,IAAa,oBAAb,MAA+B;CAC7B;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAA6B;EACvC,MAAM,EACJ,cACA,kBACA,cACA,OAAO,QACP,cACA,eACA,cACA,UACA,YACE;EAEJ,MAAM,eAA6B;GACjC,MAAM;GACN,aAAa;GACb,eAAe;GACf,WAAW;GACX,OAAO;EACT;EAEA,MAAM,UAAU;GACd,KAAK,CAAC;GACN,SAAS,KAAA;EACX;EAIA,MAAM,qBAAqB,EAAE,OAAO;GAClC,SAAS;IAAE,SAAS;IAAI,WAAW;GAAG;GACtC,aAAa;EACf,CAAC;EACD,MAAM,iBAAiB,YAA0C;GAC/D,QAAQ,MACN,aAAa,SAAS,KAAK,aAAa,OAAO,YAAY,IAAI,CAAC;GAClE,MAAM,YAAY,QAAQ,IAAI,WAAW;GACzC,WAAW,WAAW;GACtB,WAAW,WAAW;GAKtB,IAAI,WAAW;IACb,mBAAmB,cAAc;IACjC,mBAAmB,QAAQ,YAAY;IACvC,QAAQ,UAAU,KAAA;IAClB,SAAS,CAAC,CAAC;IACX;GACF;GAEA,OAAO,mBAAmB,QAAQ;GAClC,IAAI,SAAS,kBAAkB,OAAO;IAEpC,mBADqB,SAAS,QAAQ,KAAK,EAAE,eAAe,MAAM,CACpC,CAAC;IAC/B;GACF;GAEA,mBAAmB,SAAS,QAAQ,GAAG,CAAC;EAC1C;EACA,KAAKA,iBAAiB;EAEtB,MAAM,sBAAsB,iBAAyC;GACnE,IAAI,iBAAiB,KAAA,GACnB,mBAAmB,cAAc,GAAG,QAAQ,IAAI,OAAO;QAClD;IACL,MAAM,CAAC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F,YAAY,YAAY;CAC/B;CAEA,cAAc,SAA6C;EACzD,KAAKD,iBAAiB,OAAO;CAC/B;CAEA,QAAQ,MAA6B;EACnC,KAAKI,aAAa,IAAI;CACxB;CAKA,QAAc;EACZ,KAAKF,SAAS;CAChB;CAKA,UAAgB;EACd,KAAKG,WAAW,OAAO;CACzB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DiffLineAnnotation, EditorSelection, Position, Range, SelectionDirection, TextEdit } from "../types.js";
|
|
2
|
-
import {
|
|
1
|
+
import { DiffLineAnnotation, EditorSelection, Position, Range, ResolvedTextEdit, SelectionDirection, TextEdit } from "../types.js";
|
|
2
|
+
import { TextDocument, TextDocumentChange } from "./textDocument.js";
|
|
3
3
|
|
|
4
4
|
//#region src/editor/selection.d.ts
|
|
5
5
|
declare const DirectionBackward = -1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.d.ts","names":[],"sources":["../../src/editor/selection.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"selection.d.ts","names":[],"sources":["../../src/editor/selection.ts"],"mappings":";;;;cAiBa,iBAAA;AAAA,cACA,aAAA;AAAA,cACA,gBAAA;AAAA,UAgBI,iBAAA;EACf,kBAAA,IAAsB,IAAA,aAAiB,SAAA;EAnBX;AAAA;AAC9B;;;;AAA0B;EA0BxB,qBAAA,GAAwB,qBAAqB;AAAA;;;AAzBlB;iBAsCb,gBAAA,CACd,KAAA,EAAO,WAAA,EACP,SAAA,GAAW,kBAAA,GACV,eAAA;;;;iBAgBa,kBAAA,CACd,YAAA,EAAc,YAAA,WACd,SAAA,EAAW,eAAA,EACX,OAAA,UACA,OAAA,aACE,KAAA,EAAO,QAAA,IAAY,aAAA,EAAe,eAAA;;;;;;AArCS;KA6GnC,qBAAA,IACV,IAAA,UACA,SAAwB;;;;iBAMV,aAAA,CACd,YAAA,EAAc,YAAA,WACd,UAAA,EAAY,eAAA,IACZ,QAAA,oEACA,OAAA,GAA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