@singapore-editor/find 0.1.1 → 0.2.11
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/LICENSE +22 -0
- package/README.md +25 -8
- package/dist/findController.d.ts.map +1 -1
- package/dist/findController.js +4 -9
- package/dist/findController.js.map +1 -1
- package/dist/findIcons.d.ts +22 -22
- package/dist/findIcons.d.ts.map +1 -1
- package/dist/findIcons.js +1 -2
- package/dist/findWidget.d.ts +4 -1
- package/dist/findWidget.d.ts.map +1 -1
- package/dist/findWidget.js +26 -24
- package/dist/findWidget.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +3 -3
- package/dist/plugin.js.map +1 -1
- package/dist/replacePattern.d.ts.map +1 -1
- package/dist/replacePattern.js +1 -2
- package/dist/search.js +2 -3
- package/dist/search.js.map +1 -1
- package/package.json +26 -8
package/dist/findWidget.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findWidget.js","names":[],"sources":["../src/findWidget.ts"],"sourcesContent":["import type { EditorFindWidgetState } from './findController'\nimport { createFindIcon, FIND_ICONS, type FindIcon } from './findIcons'\nimport { FIND_MATCHES_LIMIT } from './search'\n\nconst EDITOR_THEME_VARIABLES = [\n '--editor-background',\n '--editor-foreground',\n '--editor-caret-color',\n] as const\n\nexport type EditorFindWidgetOptions = {\n readonly onSearchInput: (value: string) => void\n readonly onReplaceInput: (value: string) => void\n readonly onToggleReplace: () => void\n readonly onPrevious: () => void\n readonly onNext: () => void\n readonly onClose: () => void\n readonly onToggleCase: () => void\n readonly onToggleWholeWord: () => void\n readonly onToggleRegex: () => void\n readonly onToggleScope: () => void\n readonly onTogglePreserveCase: () => void\n readonly onReplaceOne: () => void\n readonly onReplaceAll: () => void\n}\n\nexport class EditorFindWidget {\n private readonly root: HTMLDivElement\n private readonly findInput: HTMLInputElement\n private readonly replaceInput: HTMLInputElement\n private readonly replaceRow: HTMLDivElement\n private readonly count: HTMLSpanElement\n private readonly replaceToggleButton: HTMLButtonElement\n private readonly caseButton: HTMLButtonElement\n private readonly wordButton: HTMLButtonElement\n private readonly regexButton: HTMLButtonElement\n private readonly scopeButton: HTMLButtonElement\n private readonly preserveButton: HTMLButtonElement\n\n public constructor(\n container: HTMLElement,\n private readonly themeSource: HTMLElement,\n private readonly options: EditorFindWidgetOptions,\n ) {\n const document = container.ownerDocument\n const position = container.ownerDocument.defaultView?.getComputedStyle(container).position\n if (!position || position === 'static') container.style.position = 'relative'\n this.root = document.createElement('div')\n this.findInput = document.createElement('input')\n this.replaceInput = document.createElement('input')\n this.replaceRow = document.createElement('div')\n this.count = document.createElement('span')\n this.replaceToggleButton = createFindButton(\n document,\n FIND_ICONS.replaceToggle,\n 'Toggle Replace',\n )\n this.replaceToggleButton.classList.add('editor-find-replace-toggle')\n this.caseButton = createFindButton(document, FIND_ICONS.caseSensitive, 'Match Case')\n this.wordButton = createFindButton(document, FIND_ICONS.wholeWord, 'Whole Word')\n this.regexButton = createFindButton(document, FIND_ICONS.regex, 'Use Regular Expression')\n this.scopeButton = createFindButton(document, FIND_ICONS.scope, 'Find in Selection')\n this.preserveButton = createFindButton(document, FIND_ICONS.preserveCase, 'Preserve Case')\n this.build(document)\n container.appendChild(this.root)\n }\n\n public show(replaceVisible: boolean): void {\n syncEditorThemeVariables(this.root, this.themeSource)\n this.root.hidden = false\n this.replaceRow.hidden = !replaceVisible\n }\n\n public hide(): void {\n this.root.hidden = true\n }\n\n // The stylesheet anchors the widget a fixed inset from the container's\n // trailing edge, which is also where a minimap parks. Margin keeps that inset\n // authoritative and shifts the whole widget inboard of the claimed strip.\n public setTrailingInset(width: number): void {\n this.root.style.marginRight = width > 0 ? `${Math.ceil(width)}px` : ''\n }\n\n public update(state: EditorFindWidgetState): void {\n syncEditorThemeVariables(this.root, this.themeSource)\n if (this.findInput.value !== state.searchString) this.findInput.value = state.searchString\n if (this.replaceInput.value !== state.replaceString)\n this.replaceInput.value = state.replaceString\n this.replaceRow.hidden = !state.replaceRevealed\n setToggleExpanded(this.replaceToggleButton, state.replaceRevealed, 'Replace')\n this.count.textContent = resultCountText(state.matchesPosition, state.matchesCount)\n this.count.title = state.highlightsTruncated\n ? TRUNCATED_HIGHLIGHTS_TITLE\n : this.count.textContent\n setTogglePressed(this.caseButton, state.matchCase, 'Match Case')\n setTogglePressed(this.wordButton, state.wholeWord, 'Match Whole Word')\n setTogglePressed(this.regexButton, state.isRegex, 'Use Regular Expression')\n setTogglePressed(this.scopeButton, state.inSelection, 'Find in Selection')\n setTogglePressed(this.preserveButton, state.preserveCase, 'Preserve Case')\n }\n\n public focusFindInput(): void {\n this.findInput.focus()\n this.findInput.select()\n }\n\n public focusReplaceInput(): void {\n this.replaceInput.focus()\n this.replaceInput.select()\n }\n\n public dispose(): void {\n this.root.remove()\n }\n\n private build(document: Document): void {\n this.root.className = 'editor-find-widget'\n this.root.hidden = true\n // Layer from the editor's shared stacking scale so the widget keeps its\n // place as other surfaces claim tiers; the literal is the standalone\n // fallback for hosts that ship this stylesheet without the editor's.\n this.root.style.zIndex = 'var(--editor-z-overlay-widget, 20)'\n this.findInput.className = 'editor-find-input'\n this.findInput.type = 'text'\n this.findInput.placeholder = 'Find'\n this.findInput.title = 'Find'\n this.findInput.spellcheck = false\n this.findInput.autocomplete = 'off'\n this.findInput.setAttribute('aria-label', 'Find')\n this.replaceInput.className = 'editor-find-input editor-find-input-standalone'\n this.replaceInput.type = 'text'\n this.replaceInput.placeholder = 'Replace'\n this.replaceInput.title = 'Replace'\n this.replaceInput.spellcheck = false\n this.replaceInput.autocomplete = 'off'\n this.replaceInput.setAttribute('aria-label', 'Replace')\n this.replaceRow.className = 'editor-find-row editor-find-replace-row'\n this.count.className = 'editor-find-count'\n\n this.root.append(this.findRow(document), this.replaceRow)\n this.installHandlers()\n }\n\n private findRow(document: Document): HTMLDivElement {\n const row = document.createElement('div')\n row.className = 'editor-find-row'\n row.append(\n this.replaceToggleButton,\n this.findInputFrame(document),\n this.count,\n this.scopeButton,\n createFindButton(document, FIND_ICONS.previous, 'Previous Match', this.options.onPrevious),\n createFindButton(document, FIND_ICONS.next, 'Next Match', this.options.onNext),\n createFindButton(document, FIND_ICONS.close, 'Close', this.options.onClose),\n )\n this.replaceRow.append(\n this.replaceInput,\n this.preserveButton,\n createFindButton(document, FIND_ICONS.replace, 'Replace', this.options.onReplaceOne),\n createFindButton(document, FIND_ICONS.replaceAll, 'Replace All', this.options.onReplaceAll),\n )\n return row\n }\n\n private findInputFrame(document: Document): HTMLDivElement {\n const frame = document.createElement('div')\n const controls = document.createElement('div')\n frame.className = 'editor-find-input-frame'\n controls.className = 'editor-find-input-controls'\n controls.append(this.caseButton, this.wordButton, this.regexButton)\n frame.append(this.findInput, controls)\n return frame\n }\n\n private installHandlers(): void {\n this.root.addEventListener('keydown', (event) => this.handleKeyDown(event))\n this.findInput.addEventListener('input', () => this.options.onSearchInput(this.findInput.value))\n this.replaceInput.addEventListener('input', () =>\n this.options.onReplaceInput(this.replaceInput.value),\n )\n this.caseButton.addEventListener('click', this.options.onToggleCase)\n this.wordButton.addEventListener('click', this.options.onToggleWholeWord)\n this.regexButton.addEventListener('click', this.options.onToggleRegex)\n this.replaceToggleButton.addEventListener('click', this.options.onToggleReplace)\n this.scopeButton.addEventListener('click', this.options.onToggleScope)\n this.preserveButton.addEventListener('click', this.options.onTogglePreserveCase)\n }\n\n private handleKeyDown(event: KeyboardEvent): void {\n event.stopPropagation()\n const shouldClose = [isFindToggleKey(event), event.key === 'Escape'].some(Boolean)\n if (shouldClose) {\n event.preventDefault()\n this.options.onClose()\n return\n }\n\n if (event.key !== 'Enter') return\n event.preventDefault()\n if (event.target === this.replaceInput && !event.shiftKey) {\n this.options.onReplaceOne()\n return\n }\n if (event.shiftKey) this.options.onPrevious()\n else this.options.onNext()\n }\n}\n\nfunction createFindButton(\n document: Document,\n icon: FindIcon,\n title: string,\n onClick?: () => void,\n): HTMLButtonElement {\n const button = document.createElement('button')\n button.type = 'button'\n button.className = 'editor-find-button'\n button.appendChild(createFindIcon(document, icon))\n setNativeTooltip(button, title)\n if (onClick) button.addEventListener('click', onClick)\n return button\n}\n\nfunction syncEditorThemeVariables(target: HTMLElement, source: HTMLElement): void {\n const style = source.ownerDocument.defaultView?.getComputedStyle(source)\n if (!style) return\n\n for (const variable of EDITOR_THEME_VARIABLES) {\n const value =\n source.style.getPropertyValue(variable).trim() || style.getPropertyValue(variable).trim()\n if (value) target.style.setProperty(variable, value)\n }\n}\n\nfunction setTogglePressed(button: HTMLButtonElement, pressed: boolean, label: string): void {\n button.classList.toggle('active', pressed)\n button.setAttribute('aria-pressed', pressed ? 'true' : 'false')\n setNativeTooltip(button, toggleTooltip(label, pressed))\n}\n\nfunction setToggleExpanded(button: HTMLButtonElement, expanded: boolean, label: string): void {\n button.classList.toggle('active', expanded)\n button.setAttribute('aria-expanded', expanded ? 'true' : 'false')\n setNativeTooltip(button, expanded ? `Hide ${label}` : `Show ${label}`)\n}\n\nfunction setNativeTooltip(element: HTMLElement, value: string): void {\n element.title = value\n element.setAttribute('aria-label', value)\n}\n\nfunction isFindToggleKey(event: KeyboardEvent): boolean {\n if (event.key.toLowerCase() !== 'f') return false\n if (event.altKey || event.shiftKey) return false\n return event.metaKey || event.ctrlKey\n}\n\nfunction toggleTooltip(label: string, active: boolean): string {\n return active ? `${label} (On)` : `${label} (Off)`\n}\n\nfunction resultCountText(position: number, count: number): string {\n if (count === 0) return 'No results'\n return `${position || '?'} of ${count}`\n}\n\n// The count is exact; what stops at the cap is the painting, and saying so is the\n// only sign a reader gets that an unpainted match further down is still a match.\nconst TRUNCATED_HIGHLIGHTS_TITLE = `Only the first ${FIND_MATCHES_LIMIT} results are highlighted. Every result is counted, and Find Next, Replace All and Select All Matches cover the entire text.`\n"],"mappings":";;;AAIA,IAAM,yBAAyB;CAC7B;CACA;CACA;AACF;AAkBA,IAAa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,OAAO;CACzC,OAAO,aAAa,gBAAgB,UAAU,SAAS,OAAO;CAC9D,iBAAiB,QAAQ,cAAc,OAAO,OAAO,CAAC;AACxD;AAEA,SAAS,kBAAkB,QAA2B,UAAmB,OAAqB;CAC5F,OAAO,UAAU,OAAO,UAAU,QAAQ;CAC1C,OAAO,aAAa,iBAAiB,WAAW,SAAS,OAAO;CAChE,iBAAiB,QAAQ,WAAW,QAAQ,UAAU,QAAQ,OAAO;AACvE;AAEA,SAAS,iBAAiB,SAAsB,OAAqB;CACnE,QAAQ,QAAQ;CAChB,QAAQ,aAAa,cAAc,KAAK;AAC1C;AAEA,SAAS,gBAAgB,OAA+B;CACtD,IAAI,MAAM,IAAI,YAAY,MAAM,KAAK,OAAO;CAC5C,IAAI,MAAM,UAAU,MAAM,UAAU,OAAO;CAC3C,OAAO,MAAM,WAAW,MAAM;AAChC;AAEA,SAAS,cAAc,OAAe,QAAyB;CAC7D,OAAO,SAAS,GAAG,MAAM,SAAS,GAAG,MAAM;AAC7C;AAEA,SAAS,gBAAgB,UAAkB,OAAuB;CAChE,IAAI,UAAU,GAAG,OAAO;CACxB,OAAO,GAAG,YAAY,IAAI,MAAM;AAClC;AAIA,IAAM,6BAA6B,kBAAkB,mBAAmB"}
|
|
1
|
+
{"version":3,"file":"findWidget.js","names":[],"sources":["../src/findWidget.ts"],"sourcesContent":["import './style.css'\nimport { createEditorWidgetKeymap } from '@singapore-editor/core/extensions'\nimport type {\n EditorViewContributionContext,\n EditorDisposable,\n} from '@singapore-editor/core/extensions'\nimport type { EditorFindWidgetState } from './findController'\nimport { createFindIcon, FIND_ICONS, type FindIcon } from './findIcons'\nimport { FIND_MATCHES_LIMIT } from './search'\n\nconst EDITOR_THEME_VARIABLES = [\n '--editor-background',\n '--editor-foreground',\n '--editor-caret-color',\n] as const\n\nexport type EditorFindWidgetOptions = {\n readonly registerKeymapNode?: EditorViewContributionContext['registerKeymapNode']\n readonly onSearchInput: (value: string) => void\n readonly onReplaceInput: (value: string) => void\n readonly onToggleReplace: () => void\n readonly onPrevious: () => void\n readonly onNext: () => void\n readonly onClose: () => void\n readonly onToggleCase: () => void\n readonly onToggleWholeWord: () => void\n readonly onToggleRegex: () => void\n readonly onToggleScope: () => void\n readonly onTogglePreserveCase: () => void\n readonly onReplaceOne: () => void\n readonly onReplaceAll: () => void\n}\n\nexport class EditorFindWidget {\n private readonly hotkeys: EditorDisposable[] = []\n private readonly root: HTMLDivElement\n private readonly findInput: HTMLInputElement\n private readonly replaceInput: HTMLInputElement\n private readonly replaceRow: HTMLDivElement\n private readonly count: HTMLSpanElement\n private readonly replaceToggleButton: HTMLButtonElement\n private readonly caseButton: HTMLButtonElement\n private readonly wordButton: HTMLButtonElement\n private readonly regexButton: HTMLButtonElement\n private readonly scopeButton: HTMLButtonElement\n private readonly preserveButton: HTMLButtonElement\n\n public constructor(\n container: HTMLElement,\n private readonly themeSource: HTMLElement,\n private readonly options: EditorFindWidgetOptions,\n ) {\n const document = container.ownerDocument\n const position = container.ownerDocument.defaultView?.getComputedStyle(container).position\n if (!position || position === 'static') container.style.position = 'relative'\n this.root = document.createElement('div')\n this.findInput = document.createElement('input')\n this.replaceInput = document.createElement('input')\n this.replaceRow = document.createElement('div')\n this.count = document.createElement('span')\n this.replaceToggleButton = createFindButton(\n document,\n FIND_ICONS.replaceToggle,\n 'Toggle Replace',\n )\n this.replaceToggleButton.classList.add('editor-find-replace-toggle')\n this.caseButton = createFindButton(document, FIND_ICONS.caseSensitive, 'Match Case')\n this.wordButton = createFindButton(document, FIND_ICONS.wholeWord, 'Whole Word')\n this.regexButton = createFindButton(document, FIND_ICONS.regex, 'Use Regular Expression')\n this.scopeButton = createFindButton(document, FIND_ICONS.scope, 'Find in Selection')\n this.preserveButton = createFindButton(document, FIND_ICONS.preserveCase, 'Preserve Case')\n this.build(document)\n container.appendChild(this.root)\n }\n\n public show(replaceVisible: boolean): void {\n syncEditorThemeVariables(this.root, this.themeSource)\n this.root.hidden = false\n this.replaceRow.hidden = !replaceVisible\n }\n\n public hide(): void {\n this.root.hidden = true\n }\n\n // The stylesheet anchors the widget a fixed inset from the container's\n // trailing edge, which is also where a minimap parks. Margin keeps that inset\n // authoritative and shifts the whole widget inboard of the claimed strip.\n public setTrailingInset(width: number): void {\n this.root.style.marginRight = width > 0 ? `${Math.ceil(width)}px` : ''\n }\n\n public update(state: EditorFindWidgetState): void {\n syncEditorThemeVariables(this.root, this.themeSource)\n if (this.findInput.value !== state.searchString) this.findInput.value = state.searchString\n if (this.replaceInput.value !== state.replaceString)\n this.replaceInput.value = state.replaceString\n this.replaceRow.hidden = !state.replaceRevealed\n setToggleExpanded(this.replaceToggleButton, state.replaceRevealed, 'Replace')\n this.count.textContent = resultCountText(state.matchesPosition, state.matchesCount)\n this.count.title = state.highlightsTruncated\n ? TRUNCATED_HIGHLIGHTS_TITLE\n : this.count.textContent\n setTogglePressed(this.caseButton, state.matchCase, 'Match Case')\n setTogglePressed(this.wordButton, state.wholeWord, 'Match Whole Word')\n setTogglePressed(this.regexButton, state.isRegex, 'Use Regular Expression')\n setTogglePressed(this.scopeButton, state.inSelection, 'Find in Selection')\n setTogglePressed(this.preserveButton, state.preserveCase, 'Preserve Case')\n }\n\n public focusFindInput(): void {\n this.findInput.focus()\n this.findInput.select()\n }\n\n public focusReplaceInput(): void {\n this.replaceInput.focus()\n this.replaceInput.select()\n }\n\n public dispose(): void {\n for (const registration of this.hotkeys) registration.dispose()\n this.root.remove()\n }\n\n private build(document: Document): void {\n this.root.className = 'editor-find-widget'\n this.root.hidden = true\n // Layer from the editor's shared stacking scale so the widget keeps its\n // place as other surfaces claim tiers; the literal is the standalone\n // fallback for hosts that ship this stylesheet without the editor's.\n this.root.style.zIndex = 'var(--editor-z-overlay-widget, 20)'\n this.findInput.className = 'editor-find-input'\n this.findInput.type = 'text'\n this.findInput.placeholder = 'Find'\n this.findInput.title = 'Find'\n this.findInput.spellcheck = false\n this.findInput.autocomplete = 'off'\n this.findInput.setAttribute('aria-label', 'Find')\n this.replaceInput.className = 'editor-find-input editor-find-input-standalone'\n this.replaceInput.type = 'text'\n this.replaceInput.placeholder = 'Replace'\n this.replaceInput.title = 'Replace'\n this.replaceInput.spellcheck = false\n this.replaceInput.autocomplete = 'off'\n this.replaceInput.setAttribute('aria-label', 'Replace')\n this.replaceRow.className = 'editor-find-row editor-find-replace-row'\n this.count.className = 'editor-find-count'\n\n this.root.append(this.findRow(document), this.replaceRow)\n this.installHandlers()\n }\n\n private findRow(document: Document): HTMLDivElement {\n const row = document.createElement('div')\n row.className = 'editor-find-row'\n row.append(\n this.replaceToggleButton,\n this.findInputFrame(document),\n this.count,\n this.scopeButton,\n createFindButton(document, FIND_ICONS.previous, 'Previous Match', this.options.onPrevious),\n createFindButton(document, FIND_ICONS.next, 'Next Match', this.options.onNext),\n createFindButton(document, FIND_ICONS.close, 'Close', this.options.onClose),\n )\n this.replaceRow.append(\n this.replaceInput,\n this.preserveButton,\n createFindButton(document, FIND_ICONS.replace, 'Replace', this.options.onReplaceOne),\n createFindButton(document, FIND_ICONS.replaceAll, 'Replace All', this.options.onReplaceAll),\n )\n return row\n }\n\n private findInputFrame(document: Document): HTMLDivElement {\n const frame = document.createElement('div')\n const controls = document.createElement('div')\n frame.className = 'editor-find-input-frame'\n controls.className = 'editor-find-input-controls'\n controls.append(this.caseButton, this.wordButton, this.regexButton)\n frame.append(this.findInput, controls)\n return frame\n }\n\n private installHandlers(): void {\n const standalone = this.options.registerKeymapNode ? null : createEditorWidgetKeymap(this.root)\n if (standalone) this.hotkeys.push(standalone)\n const register = this.options.registerKeymapNode ?? standalone?.registerKeymapNode\n if (register) {\n const commands = {\n closeFind: () => this.options.onClose(),\n findNext: () => this.options.onNext(),\n findPrevious: () => this.options.onPrevious(),\n replaceOne: () => this.options.onReplaceOne(),\n }\n this.hotkeys.push(\n register({ element: this.root, context: 'EditorWidget FindWidget', commands }),\n )\n this.hotkeys.push(\n register({\n element: this.replaceInput,\n context: 'EditorWidget FindWidget ReplaceInput',\n commands,\n }),\n )\n }\n this.findInput.addEventListener('input', () => this.options.onSearchInput(this.findInput.value))\n this.replaceInput.addEventListener('input', () =>\n this.options.onReplaceInput(this.replaceInput.value),\n )\n this.caseButton.addEventListener('click', this.options.onToggleCase)\n this.wordButton.addEventListener('click', this.options.onToggleWholeWord)\n this.regexButton.addEventListener('click', this.options.onToggleRegex)\n this.replaceToggleButton.addEventListener('click', this.options.onToggleReplace)\n this.scopeButton.addEventListener('click', this.options.onToggleScope)\n this.preserveButton.addEventListener('click', this.options.onTogglePreserveCase)\n }\n}\n\nfunction createFindButton(\n document: Document,\n icon: FindIcon,\n title: string,\n onClick?: () => void,\n): HTMLButtonElement {\n const button = document.createElement('button')\n button.type = 'button'\n button.className = 'editor-find-button'\n button.appendChild(createFindIcon(document, icon))\n setNativeTooltip(button, title)\n if (onClick) button.addEventListener('click', onClick)\n return button\n}\n\nfunction syncEditorThemeVariables(target: HTMLElement, source: HTMLElement): void {\n const style = source.ownerDocument.defaultView?.getComputedStyle(source)\n if (!style) return\n\n for (const variable of EDITOR_THEME_VARIABLES) {\n const value =\n source.style.getPropertyValue(variable).trim() || style.getPropertyValue(variable).trim()\n if (value) target.style.setProperty(variable, value)\n }\n}\n\nfunction setTogglePressed(button: HTMLButtonElement, pressed: boolean, label: string): void {\n button.classList.toggle('active', pressed)\n button.setAttribute('aria-pressed', pressed ? 'true' : 'false')\n setNativeTooltip(button, toggleTooltip(label, pressed))\n}\n\nfunction setToggleExpanded(button: HTMLButtonElement, expanded: boolean, label: string): void {\n button.classList.toggle('active', expanded)\n button.setAttribute('aria-expanded', expanded ? 'true' : 'false')\n setNativeTooltip(button, expanded ? `Hide ${label}` : `Show ${label}`)\n}\n\nfunction setNativeTooltip(element: HTMLElement, value: string): void {\n element.title = value\n element.setAttribute('aria-label', value)\n}\n\nfunction toggleTooltip(label: string, active: boolean): string {\n return active ? `${label} (On)` : `${label} (Off)`\n}\n\nfunction resultCountText(position: number, count: number): string {\n if (count === 0) return 'No results'\n return `${position || '?'} of ${count}`\n}\n\n// The count is exact; what stops at the cap is the painting, and saying so is the\n// only sign a reader gets that an unpainted match further down is still a match.\nconst TRUNCATED_HIGHLIGHTS_TITLE = `Only the first ${FIND_MATCHES_LIMIT} results are highlighted. Every result is counted, and Find Next, Replace All and Select All Matches cover the entire text.`\n"],"mappings":";;;;;AAUA,IAAM,yBAAyB;CAC7B;CACA;CACA;AACF;AAmBA,IAAa,mBAAb,MAA8B;CAgBT;CACA;CAhBnB,UAA+C,CAAC;CAChD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YACE,WACA,aACA,SACA;EAFiB,KAAA,cAAA;EACA,KAAA,UAAA;EAEjB,MAAM,WAAW,UAAU;EAC3B,MAAM,WAAW,UAAU,cAAc,aAAa,iBAAiB,SAAS,CAAC,CAAC;EAClF,IAAI,CAAC,YAAY,aAAa,UAAU,UAAU,MAAM,WAAW;EACnE,KAAK,OAAO,SAAS,cAAc,KAAK;EACxC,KAAK,YAAY,SAAS,cAAc,OAAO;EAC/C,KAAK,eAAe,SAAS,cAAc,OAAO;EAClD,KAAK,aAAa,SAAS,cAAc,KAAK;EAC9C,KAAK,QAAQ,SAAS,cAAc,MAAM;EAC1C,KAAK,sBAAsB,iBACzB,UACA,WAAW,eACX,gBACF;EACA,KAAK,oBAAoB,UAAU,IAAI,4BAA4B;EACnE,KAAK,aAAa,iBAAiB,UAAU,WAAW,eAAe,YAAY;EACnF,KAAK,aAAa,iBAAiB,UAAU,WAAW,WAAW,YAAY;EAC/E,KAAK,cAAc,iBAAiB,UAAU,WAAW,OAAO,wBAAwB;EACxF,KAAK,cAAc,iBAAiB,UAAU,WAAW,OAAO,mBAAmB;EACnF,KAAK,iBAAiB,iBAAiB,UAAU,WAAW,cAAc,eAAe;EACzF,KAAK,MAAM,QAAQ;EACnB,UAAU,YAAY,KAAK,IAAI;CACjC;CAEA,KAAY,gBAA+B;EACzC,yBAAyB,KAAK,MAAM,KAAK,WAAW;E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,yBAAyB,QAAqB,QAA2B;CAChF,MAAM,QAAQ,OAAO,cAAc,aAAa,iBAAiB,MAAM;CACvE,IAAI,CAAC,OAAO;CAEZ,KAAK,MAAM,YAAY,wBAAwB;EAC7C,MAAM,QACJ,OAAO,MAAM,iBAAiB,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM,iBAAiB,QAAQ,CAAC,CAAC,KAAK;EAC1F,IAAI,OAAO,OAAO,MAAM,YAAY,UAAU,KAAK;CACrD;AACF;AAEA,SAAS,iBAAiB,QAA2B,SAAkB,OAAqB;CAC1F,OAAO,UAAU,OAAO,UAAU,OAAO;CACzC,OAAO,aAAa,gBAAgB,UAAU,SAAS,OAAO;CAC9D,iBAAiB,QAAQ,cAAc,OAAO,OAAO,CAAC;AACxD;AAEA,SAAS,kBAAkB,QAA2B,UAAmB,OAAqB;CAC5F,OAAO,UAAU,OAAO,UAAU,QAAQ;CAC1C,OAAO,aAAa,iBAAiB,WAAW,SAAS,OAAO;CAChE,iBAAiB,QAAQ,WAAW,QAAQ,UAAU,QAAQ,OAAO;AACvE;AAEA,SAAS,iBAAiB,SAAsB,OAAqB;CACnE,QAAQ,QAAQ;CAChB,QAAQ,aAAa,cAAc,KAAK;AAC1C;AAEA,SAAS,cAAc,OAAe,QAAyB;CAC7D,OAAO,SAAS,GAAG,MAAM,SAAS,GAAG,MAAM;AAC7C;AAEA,SAAS,gBAAgB,UAAkB,OAAuB;CAChE,IAAI,UAAU,GAAG,OAAO;CACxB,OAAO,GAAG,YAAY,IAAI,MAAM;AAClC;AAIA,IAAM,6BAA6B,kBAAkB,mBAAmB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import './style.css';
|
|
2
1
|
export { createEditorFindContributionProviders, createEditorFindPlugin, EDITOR_FIND_FEATURE, EDITOR_FIND_FEATURE_ID, type EditorFindContributionProviders, type EditorFindFeature, } from './plugin';
|
|
3
2
|
export { FIND_HIGHLIGHT_Z_INDEX } from './findController';
|
|
4
3
|
export type { EditorFindOptions } from './types';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qCAAqC,EACrC,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,+BAA+B,EACpC,KAAK,iBAAiB,GACvB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AACzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { FIND_HIGHLIGHT_Z_INDEX } from "./findController.js";
|
|
2
2
|
import { EDITOR_FIND_FEATURE, EDITOR_FIND_FEATURE_ID, createEditorFindContributionProviders, createEditorFindPlugin } from "./plugin.js";
|
|
3
|
-
import "./style.css";
|
|
4
3
|
export { EDITOR_FIND_FEATURE, EDITOR_FIND_FEATURE_ID, FIND_HIGHLIGHT_Z_INDEX, createEditorFindContributionProviders, createEditorFindPlugin };
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,oCAAoC,EAGpC,iCAAiC,EAIjC,8BAA8B,EAC9B,iBAAiB,EAGjB,YAAY,EAIZ,8BAA8B,EAG/B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EAEvB,MAAM,mCAAmC,CAAA;AAW1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,OAAO,EAAE,mBAAmB,EAAE,sBA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
@@ -2,7 +2,7 @@ import { EditorFindController } from "./findController.js";
|
|
|
2
2
|
import { EditorFindWidget } from "./findWidget.js";
|
|
3
3
|
import { compareTextOffsetRanges } from "@singapore-editor/core/document";
|
|
4
4
|
import { EDITOR_FIND_FEATURE, EDITOR_FIND_FEATURE_ID, EDITOR_MINIMAP_FEATURE, projectDecorationRangeThroughEdits } from "@singapore-editor/core/extensions";
|
|
5
|
-
|
|
5
|
+
// src/plugin.ts
|
|
6
6
|
function createEditorFindPlugin(options = {}) {
|
|
7
7
|
return {
|
|
8
8
|
name: "editor.find",
|
|
@@ -110,6 +110,7 @@ var EditorFindViewContribution = class {
|
|
|
110
110
|
}
|
|
111
111
|
createWidgetOptions() {
|
|
112
112
|
return {
|
|
113
|
+
registerKeymapNode: (options) => this.context.registerKeymapNode(options),
|
|
113
114
|
onSearchInput: (value) => this.controller.setSearchString(value),
|
|
114
115
|
onReplaceInput: (value) => this.controller.setReplaceString(value),
|
|
115
116
|
onToggleReplace: () => this.controller.toggleReplace(),
|
|
@@ -162,7 +163,7 @@ var EditorFindEditContribution = class {
|
|
|
162
163
|
registration;
|
|
163
164
|
constructor(context, controller) {
|
|
164
165
|
this.registration = controller.attachEditHost({
|
|
165
|
-
textSnapshot: () => context.
|
|
166
|
+
textSnapshot: () => context.getCurrentDocumentSnapshot()?.textSnapshot ?? null,
|
|
166
167
|
getSelections: () => findSelections(context.getSelections()),
|
|
167
168
|
applyEdits: (edits, timingName, selection) => context.applyEdits(edits, timingName, selection)
|
|
168
169
|
});
|
|
@@ -402,7 +403,6 @@ function findSelections(selections) {
|
|
|
402
403
|
function disposeAll(disposables) {
|
|
403
404
|
for (const disposable of disposables.toReversed()) disposable.dispose();
|
|
404
405
|
}
|
|
405
|
-
//#endregion
|
|
406
406
|
export { EDITOR_FIND_FEATURE, EDITOR_FIND_FEATURE_ID, createEditorFindContributionProviders, createEditorFindPlugin };
|
|
407
407
|
|
|
408
408
|
//# sourceMappingURL=plugin.js.map
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { compareTextOffsetRanges, type DocumentSyncPoint } from '@singapore-editor/core/document'\nimport {\n type EditorContributionChange,\n projectDecorationRangeThroughEdits,\n} from '@singapore-editor/core/extensions'\nimport type {\n EditorCapabilityContribution,\n EditorCapabilityContributionContext,\n EditorCapabilityContributionProvider,\n EditorCommandContribution,\n EditorCommandContributionContext,\n EditorCommandContributionProvider,\n EditorDisposable,\n EditorEditContribution,\n EditorEditContributionContext,\n EditorEditContributionProvider,\n EditorFindFeature,\n EditorMinimapDecoration,\n EditorMinimapFeature,\n EditorPlugin,\n EditorResolvedSelection,\n EditorViewContribution,\n EditorViewContributionContext,\n EditorViewContributionProvider,\n EditorViewContributionUpdateKind,\n EditorViewSnapshot,\n} from '@singapore-editor/core/extensions'\nimport {\n EDITOR_FIND_FEATURE,\n EDITOR_FIND_FEATURE_ID,\n EDITOR_MINIMAP_FEATURE,\n} from '@singapore-editor/core/extensions'\nimport type { VirtualizedTextHighlightStyle } from '@singapore-editor/core/rendering'\nimport {\n EditorFindController,\n type EditorFindHost,\n type EditorFindResolvedSelection,\n type EditorFindUiEvent,\n type FindTrackedRanges,\n} from './findController'\nimport { EditorFindWidget, type EditorFindWidgetOptions } from './findWidget'\nimport { type FindLineStartsView, type FindRange, type FindTextSource } from './search'\nimport type { EditorFindOptions } from './types'\n\nexport { EDITOR_FIND_FEATURE, EDITOR_FIND_FEATURE_ID }\n\nexport type EditorFindContributionProviders = {\n readonly view: EditorViewContributionProvider\n readonly command: EditorCommandContributionProvider\n readonly capability: EditorCapabilityContributionProvider\n readonly edit: EditorEditContributionProvider\n}\n\nexport function createEditorFindPlugin(options: EditorFindOptions = {}): EditorPlugin {\n return {\n name: 'editor.find',\n activate(context) {\n const providers = createEditorFindContributionProviders(options)\n return [\n context.registerViewContribution(providers.view),\n context.registerCommandContribution(providers.command),\n context.registerCapabilityContribution(providers.capability),\n context.registerEditContribution(providers.edit),\n ]\n },\n }\n}\n\nexport function createEditorFindContributionProviders(\n options: EditorFindOptions = {},\n): EditorFindContributionProviders {\n const controller = new EditorFindController(options)\n return {\n view: {\n createContribution: (context) => new EditorFindViewContribution(context, controller),\n },\n command: {\n createContribution: (context) => new EditorFindCommandContribution(context, controller),\n },\n capability: {\n createContribution: (context) => new EditorFindCapabilityContribution(context, controller),\n },\n edit: {\n createContribution: (context) => new EditorFindEditContribution(context, controller),\n },\n }\n}\n\nclass EditorFindViewContribution implements EditorViewContribution {\n private readonly hostRegistration: EditorDisposable\n private readonly subscription: EditorDisposable\n private readonly visibleKey: EditorDisposable\n private latestSnapshot: EditorViewSnapshot\n private widget: EditorFindWidget | null = null\n private reservationListener: EditorDisposable | null = null\n private paintedMatches: PaintedFindRanges | null = null\n\n public constructor(\n private readonly context: EditorViewContributionContext,\n private readonly controller: EditorFindController,\n ) {\n this.latestSnapshot = context.getSnapshot()\n this.hostRegistration = controller.attachHost(\n createFindHost(context, () => this.latestSnapshot, this.trackPaintedRanges),\n context.highlightPrefix,\n )\n this.subscription = controller.subscribe(this.handleUiEvent)\n this.visibleKey = context.registerKeymapContextKey('findVisible', () => controller.isVisible())\n }\n\n public update(\n snapshot: EditorViewSnapshot,\n kind: EditorViewContributionUpdateKind,\n change?: EditorContributionChange | null,\n ): void {\n if (\n kind === 'layout' ||\n snapshot.viewport.clientWidth !== this.latestSnapshot.viewport.clientWidth\n ) {\n this.syncTrailingInset()\n }\n this.latestSnapshot = snapshot\n // Scrolling is the one thing that moves rows under the marks without an edit\n // having happened yet, which is the only moment left to start following the\n // ones it brought in front of the reader.\n // Re-read after the line moves, not only after an edit: the set the controller is painting was\n // copied out of these ranges, so a match promoted into the mounted rows by the scroll is still\n // at the offset it was found at until the copy is taken again.\n if (kind === 'viewport' || kind === 'layout') {\n if (this.paintedMatches?.repartition(snapshot)) this.controller.refreshTrackedMatches()\n }\n this.controller.handleViewUpdate(kind, change ?? null)\n }\n\n public dispose(): void {\n this.visibleKey.dispose()\n this.subscription.dispose()\n this.reservationListener?.dispose()\n this.reservationListener = null\n this.widget?.dispose()\n this.widget = null\n this.paintedMatches = null\n this.hostRegistration.dispose()\n }\n\n private readonly trackPaintedRanges = (ranges: readonly FindRange[]): FindTrackedRanges => {\n this.paintedMatches = new PaintedFindRanges(this.context, this.latestSnapshot, ranges)\n return this.paintedMatches\n }\n\n private readonly handleUiEvent = (event: EditorFindUiEvent): void => {\n if (event.type === 'show') {\n this.ensureWidget().show(event.replaceVisible)\n return\n }\n\n if (event.type === 'hide') {\n this.widget?.hide()\n // Nothing reads the set once it is off screen, so leaving it here would\n // have every scroll from now on redraw a line across it for nobody.\n this.paintedMatches = null\n return\n }\n\n if (event.type === 'update') {\n this.widget?.update(event.state)\n return\n }\n\n this.focusWidget(event.target)\n }\n\n private focusWidget(target: 'find' | 'replace'): void {\n const widget = this.widget\n if (!widget) return\n\n if (target === 'find') widget.focusFindInput()\n if (target === 'replace') widget.focusReplaceInput()\n }\n\n private ensureWidget(): EditorFindWidget {\n if (this.widget) return this.widget\n\n this.widget = new EditorFindWidget(\n this.context.container,\n this.context.scrollElement,\n this.createWidgetOptions(),\n )\n this.observeReservedWidth()\n this.syncTrailingInset()\n return this.widget\n }\n\n private observeReservedWidth(): void {\n this.reservationListener ??= this.context.onDidChangeReservedOverlayWidth((side) => {\n if (side === 'right') this.syncTrailingInset()\n })\n }\n\n private syncTrailingInset(): void {\n if (!this.widget) return\n\n const { container, scrollElement } = this.context\n const containerRight =\n container.getBoundingClientRect().left + container.clientLeft + container.clientWidth\n const viewportRight =\n scrollElement.getBoundingClientRect().left +\n scrollElement.clientLeft +\n scrollElement.clientWidth\n const reservedWidth = this.context.getReservedOverlayWidth('right')\n this.widget.setTrailingInset(reservedWidth + Math.max(0, containerRight - viewportRight))\n }\n\n private createWidgetOptions(): EditorFindWidgetOptions {\n return {\n onSearchInput: (value) => this.controller.setSearchString(value),\n onReplaceInput: (value) => this.controller.setReplaceString(value),\n onToggleReplace: () => this.controller.toggleReplace(),\n onPrevious: () => this.controller.findPrevious(),\n onNext: () => this.controller.findNext(),\n onClose: () => this.controller.close(),\n onToggleCase: () => this.controller.toggleMatchCase(),\n onToggleWholeWord: () => this.controller.toggleWholeWord(),\n onToggleRegex: () => this.controller.toggleRegex(),\n onToggleScope: () => this.controller.toggleFindInSelection(),\n onTogglePreserveCase: () => this.controller.togglePreserveCase(),\n onReplaceOne: () => this.controller.replaceOne(),\n onReplaceAll: () => this.controller.replaceAll(),\n }\n }\n}\n\nclass EditorFindCommandContribution implements EditorCommandContribution {\n private readonly commands: readonly EditorDisposable[]\n\n public constructor(context: EditorCommandContributionContext, controller: EditorFindController) {\n this.commands = [\n context.registerCommand('find', () => controller.toggleFind()),\n context.registerCommand('findReplace', () => controller.openFindReplace()),\n context.registerCommand('findNext', () => controller.findNext()),\n context.registerCommand('findPrevious', () => controller.findPrevious()),\n context.registerCommand('closeFind', () => controller.close()),\n context.registerCommand('toggleFindCaseSensitive', () => controller.toggleMatchCase()),\n context.registerCommand('toggleFindWholeWord', () => controller.toggleWholeWord()),\n context.registerCommand('toggleFindRegex', () => controller.toggleRegex()),\n context.registerCommand('toggleFindInSelection', () => controller.toggleFindInSelection()),\n context.registerCommand('togglePreserveCase', () => controller.togglePreserveCase()),\n context.registerCommand('replaceOne', () => controller.replaceOne()),\n context.registerCommand('replaceAll', () => controller.replaceAll()),\n context.registerCommand('selectAllMatches', () => controller.selectAllMatches()),\n ]\n }\n\n public dispose(): void {\n disposeAll(this.commands)\n }\n}\n\nclass EditorFindCapabilityContribution implements EditorCapabilityContribution {\n private readonly registration: EditorDisposable\n\n public constructor(\n context: EditorCapabilityContributionContext,\n controller: EditorFindController,\n ) {\n this.registration = context.registerFeature(EDITOR_FIND_FEATURE, createFindFeature(controller))\n }\n\n public dispose(): void {\n this.registration.dispose()\n }\n}\n\nclass EditorFindEditContribution implements EditorEditContribution {\n private readonly registration: EditorDisposable\n\n public constructor(context: EditorEditContributionContext, controller: EditorFindController) {\n this.registration = controller.attachEditHost({\n textSnapshot: () => context.getTextSnapshot(),\n getSelections: () => findSelections(context.getSelections()),\n applyEdits: (edits, timingName, selection) =>\n context.applyEdits(edits, timingName, selection),\n })\n }\n\n public dispose(): void {\n this.registration.dispose()\n }\n}\n\nfunction createFindFeature(controller: EditorFindController): EditorFindFeature {\n return {\n openFind: () => controller.openFind(),\n toggleFind: () => controller.toggleFind(),\n openFindReplace: () => controller.openFindReplace(),\n closeFind: () => controller.close(),\n findNext: () => controller.findNext(),\n findPrevious: () => controller.findPrevious(),\n replaceOne: () => controller.replaceOne(),\n replaceAll: () => controller.replaceAll(),\n selectAllMatches: () => controller.selectAllMatches(),\n }\n}\n\nfunction createFindHost(\n context: EditorViewContributionContext,\n getSnapshot: () => EditorViewSnapshot,\n trackPaintedRanges: (ranges: readonly FindRange[]) => FindTrackedRanges,\n): EditorFindHost {\n const textSource = snapshotTextSource()\n return {\n hasDocument: () => context.hasDocument(),\n textSource: () => textSource(getSnapshot()),\n hasTextSnapshot: (snapshot) => getSnapshot().textSnapshot === snapshot,\n trackRanges: (ranges) => context.trackRanges(ranges),\n trackPaintedRanges,\n getSelections: () => findSelections(getSnapshot().selections),\n focusEditor: () => context.focusEditor(),\n announce: (message) => context.announce(message),\n setSelection: (anchor, head, timingName, options) =>\n context.setSelection(anchor, head, timingName, options),\n setSelections: (selections, timingName, revealOffset) =>\n context.setSelections(selections, timingName, revealOffset),\n setRangeHighlight: (name, ranges, style) => {\n context.setRangeHighlight(name, ranges, style)\n minimapFeature(context)?.setDecorations(\n name,\n minimapBands(textSource(getSnapshot()).lineStartsView, ranges, style),\n )\n },\n clearRangeHighlight: (name) => {\n context.clearRangeHighlight(name)\n minimapFeature(context)?.clearDecorations(name)\n },\n }\n}\n\nfunction minimapFeature(context: EditorViewContributionContext): EditorMinimapFeature | null {\n return context.getFeature(EDITOR_MINIMAP_FEATURE)\n}\n\n/**\n * A count says how many matches there are and nothing says where they are until\n * they reach the scroll furniture, so every group find paints in the text is\n * published under the name it is painted under.\n *\n * The band keeps its group's own colour: the minimap paints onto a canvas from a\n * worker, which has no element to resolve a registered colour against and\n * silently substitutes the selection colour for anything it cannot parse, so the\n * literal has to travel with the group rather than be looked up there.\n */\nfunction minimapBands(\n lineStartsView: FindLineStartsView,\n ranges: readonly FindRange[],\n style: VirtualizedTextHighlightStyle,\n): readonly EditorMinimapDecoration[] {\n return ranges.map((range): EditorMinimapDecoration => {\n const rows = bandRows(lineStartsView, range)\n return {\n startLineNumber: rows.start,\n startColumn: 1,\n endLineNumber: rows.end,\n endColumn: 1,\n color: style.backgroundColor,\n position: 'inline',\n zIndex: style.zIndex,\n }\n })\n}\n\n// A range ending exactly at a line start ends on the row before it: the break\n// belongs to the line it terminates, and a selection taken to the end of one row\n// should not shade the next.\nfunction bandRows(\n lineStartsView: FindLineStartsView,\n range: FindRange,\n): { readonly start: number; readonly end: number } {\n const startIndex = lineStartsView.indexForOffset(range.start)\n const endIndex = lineStartsView.indexForOffset(range.end)\n if (endIndex > startIndex && lineStartsView.at(endIndex) === range.end) {\n return { start: startIndex + 1, end: endIndex }\n }\n\n return { start: startIndex + 1, end: endIndex + 1 }\n}\n\n/**\n * Follows the ranges as far as they are painted, answering for the rest with the\n * offsets it was handed.\n *\n * A span the reader cannot see cannot be seen standing on text that moved out\n * from under it, and the re-search already on its way replaces the whole set\n * either way. Handing the document every match instead costs it an anchor pair\n * each, on every keystroke — the bill deferring that re-search was supposed to\n * take off the keystroke in the first place.\n *\n * Which of them those are is a fact about the rows mounted at the time and not\n * about the set, so it stops being true the moment the reader scrolls. Drawn once\n * and left, the line would divide the screenful they have scrolled away from,\n * and every mark now in front of them would be one nobody is following.\n */\n// A match is the text the query answered for, so typing against either edge of one is not part of\n// it — unlike a scope, which is a region the reader drew and which takes in what they add at its\n// edges. The same pair decides how an offset is carried across an edit nobody was following.\nconst MATCH_BIAS = { startBias: 'right', endBias: 'left' } as const\n\nclass PaintedFindRanges implements FindTrackedRanges {\n private span: FindRange | null = null\n private tracked: FindTrackedRanges | null = null\n private elsewhere: readonly FindRange[]\n /** Text version the offsets in `elsewhere` describe, which is not always the document's. */\n private elsewhereVersion: number\n private elsewhereSyncPoint: DocumentSyncPoint\n\n public constructor(\n private readonly context: EditorViewContributionContext,\n snapshot: EditorViewSnapshot,\n ranges: readonly FindRange[],\n ) {\n this.elsewhere = ranges\n this.elsewhereVersion = snapshot.textVersion\n this.elsewhereSyncPoint = snapshot.documentSyncPoint\n this.partition(snapshot)\n }\n\n public resolve(): readonly FindRange[] {\n if (!this.tracked) return this.elsewhere\n return mergeRanges(this.tracked.resolve(), this.elsewhere)\n }\n\n /** Answers whether the line moved, so a caller only re-reads the set when there is a reason to. */\n public repartition(snapshot: EditorViewSnapshot): boolean {\n return this.partition(snapshot)\n }\n\n private partition(snapshot: EditorViewSnapshot): boolean {\n const span = paintedSpan(snapshot)\n if (!span || sameSpan(span, this.span)) return false\n\n // Read back first: what is already followed has moved since it was handed\n // over, and re-partitioning the offsets of the search would undo that.\n this.carryElsewhereForward(snapshot)\n const ranges = this.resolve()\n const painted = ranges.filter((range) => overlapsSpan(range, span))\n const tracked = painted.length === 0 ? null : this.context.trackRanges(painted, MATCH_BIAS)\n\n this.span = span\n this.tracked = tracked\n this.elsewhere = tracked ? ranges.filter((range) => !overlapsSpan(range, span)) : ranges\n this.elsewhereVersion = snapshot.textVersion\n this.elsewhereSyncPoint = snapshot.documentSyncPoint\n return true\n }\n\n /**\n * Brings the unfollowed half up to the document before any of it is promoted.\n *\n * Nothing follows a match the reader cannot see, so an edit that lands while they are looking\n * elsewhere leaves those offsets describing text that has moved. Scrolling then hands one of them\n * to the document to be followed from where it used to be, and the mark lands beside its word —\n * the defect being followed at all was supposed to prevent, arriving one scroll later. The edits\n * are replayed where the host can name them, and where it cannot the offsets are dropped rather\n * than promoted: no mark is the honest answer for the moment before the re-search lands, and a\n * mark on the wrong word is not.\n */\n private carryElsewhereForward(snapshot: EditorViewSnapshot): void {\n if (snapshot.textVersion === this.elsewhereVersion) return\n if (this.elsewhere.length === 0) {\n this.elsewhereVersion = snapshot.textVersion\n this.elsewhereSyncPoint = snapshot.documentSyncPoint\n return\n }\n\n const edits =\n snapshot.changesSinceDocumentSyncPoint(this.elsewhereSyncPoint, null)?.edits ?? null\n this.elsewhere = edits\n ? this.elsewhere\n .map((range) => projectDecorationRangeThroughEdits({ ...range, ...MATCH_BIAS }, edits))\n .filter((range) => range !== null)\n .map((range) => ({ end: range.end, start: range.start }))\n : []\n this.elsewhereVersion = snapshot.textVersion\n this.elsewhereSyncPoint = snapshot.documentSyncPoint\n }\n}\n\n// The view adds a range highlight to the rows it has mounted and to no others.\nfunction paintedSpan(snapshot: EditorViewSnapshot): FindRange | null {\n const first = snapshot.visibleRows[0]\n const last = snapshot.visibleRows.at(-1)\n if (!first || !last) return null\n\n return { start: first.startOffset, end: last.endOffset }\n}\n\nfunction overlapsSpan(range: FindRange, span: FindRange): boolean {\n return range.end > span.start && range.start < span.end\n}\n\nfunction sameSpan(span: FindRange, other: FindRange | null): boolean {\n return other !== null && span.start === other.start && span.end === other.end\n}\n\n// Navigation steps the set rather than searching it, so an entry out of order\n// answers the next press with the wrong match.\nfunction mergeRanges(\n left: readonly FindRange[],\n right: readonly FindRange[],\n): readonly FindRange[] {\n if (right.length === 0) return left\n\n const merged: FindRange[] = []\n let leftIndex = 0\n let rightIndex = 0\n while (leftIndex < left.length && rightIndex < right.length) {\n if (compareTextOffsetRanges(left[leftIndex]!, right[rightIndex]!) <= 0) {\n merged.push(left[leftIndex]!)\n leftIndex += 1\n continue\n }\n\n merged.push(right[rightIndex]!)\n rightIndex += 1\n }\n\n for (; leftIndex < left.length; leftIndex += 1) merged.push(left[leftIndex]!)\n for (; rightIndex < right.length; rightIndex += 1) merged.push(right[rightIndex]!)\n return merged\n}\n\n/**\n * The text a search reads, kept for as long as the snapshot it was taken from.\n *\n * Either view can be absent, and standing in for a missing one materializes what\n * it exists to avoid: a copy of the document, or the whole line-start array.\n * Every press in the find box searches again, so a stand-in built per search\n * would hand a keystroke exactly the bill that ranged reads are here to spare it.\n * Held against the snapshot itself rather than its text version, because a\n * document swap can carry that version across unchanged.\n */\nfunction snapshotTextSource(): (snapshot: EditorViewSnapshot) => FindTextSource {\n let cached: { readonly snapshot: EditorViewSnapshot; readonly source: FindTextSource } | null =\n null\n return (snapshot) => {\n if (cached?.snapshot !== snapshot) cached = { snapshot, source: findTextSource(snapshot) }\n return cached.source\n }\n}\n\nfunction findTextSource(snapshot: EditorViewSnapshot): FindTextSource {\n const text = snapshot.textSnapshot\n return {\n length: text.length,\n readRange: (start, end) => text.readRange(start, end),\n lineStartsView: snapshot.lineStartsView,\n }\n}\n\nfunction findSelections(\n selections: readonly EditorResolvedSelection[],\n): readonly EditorFindResolvedSelection[] {\n return selections.map((selection) => ({\n ...selection,\n collapsed: selection.startOffset === selection.endOffset,\n }))\n}\n\nfunction disposeAll(disposables: readonly EditorDisposable[]): void {\n for (const disposable of disposables.toReversed()) disposable.dispose()\n}\n\nexport type { EditorFindFeature, EditorFindOptions }\n"],"mappings":";;;;;AAqDA,SAAgB,uBAAuB,UAA6B,CAAC,GAAiB;CACpF,OAAO;EACL,MAAM;EACN,SAAS,SAAS;GAChB,MAAM,YAAY,sCAAsC,OAAO;GAC/D,OAAO;IACL,QAAQ,yBAAyB,UAAU,IAAI;IAC/C,QAAQ,4BAA4B,UAAU,OAAO;IACrD,QAAQ,+BAA+B,UAAU,UAAU;IAC3D,QAAQ,yBAAyB,UAAU,IAAI;GACjD;EACF;CACF;AACF;AAEA,SAAgB,sCACd,UAA6B,CAAC,GACG;CACjC,MAAM,aAAa,IAAI,qBAAqB,OAAO;CACnD,OAAO;EACL,MAAM,EACJ,qBAAqB,YAAY,IAAI,2BAA2B,SAAS,UAAU,EACrF;EACA,SAAS,EACP,qBAAqB,YAAY,IAAI,8BAA8B,SAAS,UAAU,EACxF;EACA,YAAY,EACV,qB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}
|
|
1
|
+
{"version":3,"file":"plugin.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { compareTextOffsetRanges, type DocumentSyncPoint } from '@singapore-editor/core/document'\nimport {\n type EditorContributionChange,\n projectDecorationRangeThroughEdits,\n} from '@singapore-editor/core/extensions'\nimport type {\n EditorCapabilityContribution,\n EditorCapabilityContributionContext,\n EditorCapabilityContributionProvider,\n EditorCommandContribution,\n EditorCommandContributionContext,\n EditorCommandContributionProvider,\n EditorDisposable,\n EditorEditContribution,\n EditorEditContributionContext,\n EditorEditContributionProvider,\n EditorFindFeature,\n EditorMinimapDecoration,\n EditorMinimapFeature,\n EditorPlugin,\n EditorResolvedSelection,\n EditorViewContribution,\n EditorViewContributionContext,\n EditorViewContributionProvider,\n EditorViewContributionUpdateKind,\n EditorViewSnapshot,\n} from '@singapore-editor/core/extensions'\nimport {\n EDITOR_FIND_FEATURE,\n EDITOR_FIND_FEATURE_ID,\n EDITOR_MINIMAP_FEATURE,\n} from '@singapore-editor/core/extensions'\nimport type { VirtualizedTextHighlightStyle } from '@singapore-editor/core/rendering'\nimport {\n EditorFindController,\n type EditorFindHost,\n type EditorFindResolvedSelection,\n type EditorFindUiEvent,\n type FindTrackedRanges,\n} from './findController'\nimport { EditorFindWidget, type EditorFindWidgetOptions } from './findWidget'\nimport { type FindLineStartsView, type FindRange, type FindTextSource } from './search'\nimport type { EditorFindOptions } from './types'\n\nexport { EDITOR_FIND_FEATURE, EDITOR_FIND_FEATURE_ID }\n\nexport type EditorFindContributionProviders = {\n readonly view: EditorViewContributionProvider\n readonly command: EditorCommandContributionProvider\n readonly capability: EditorCapabilityContributionProvider\n readonly edit: EditorEditContributionProvider\n}\n\nexport function createEditorFindPlugin(options: EditorFindOptions = {}): EditorPlugin {\n return {\n name: 'editor.find',\n activate(context) {\n const providers = createEditorFindContributionProviders(options)\n return [\n context.registerViewContribution(providers.view),\n context.registerCommandContribution(providers.command),\n context.registerCapabilityContribution(providers.capability),\n context.registerEditContribution(providers.edit),\n ]\n },\n }\n}\n\nexport function createEditorFindContributionProviders(\n options: EditorFindOptions = {},\n): EditorFindContributionProviders {\n const controller = new EditorFindController(options)\n return {\n view: {\n createContribution: (context) => new EditorFindViewContribution(context, controller),\n },\n command: {\n createContribution: (context) => new EditorFindCommandContribution(context, controller),\n },\n capability: {\n createContribution: (context) => new EditorFindCapabilityContribution(context, controller),\n },\n edit: {\n createContribution: (context) => new EditorFindEditContribution(context, controller),\n },\n }\n}\n\nclass EditorFindViewContribution implements EditorViewContribution {\n private readonly hostRegistration: EditorDisposable\n private readonly subscription: EditorDisposable\n private readonly visibleKey: EditorDisposable\n private latestSnapshot: EditorViewSnapshot\n private widget: EditorFindWidget | null = null\n private reservationListener: EditorDisposable | null = null\n private paintedMatches: PaintedFindRanges | null = null\n\n public constructor(\n private readonly context: EditorViewContributionContext,\n private readonly controller: EditorFindController,\n ) {\n this.latestSnapshot = context.getSnapshot()\n this.hostRegistration = controller.attachHost(\n createFindHost(context, () => this.latestSnapshot, this.trackPaintedRanges),\n context.highlightPrefix,\n )\n this.subscription = controller.subscribe(this.handleUiEvent)\n this.visibleKey = context.registerKeymapContextKey('findVisible', () => controller.isVisible())\n }\n\n public update(\n snapshot: EditorViewSnapshot,\n kind: EditorViewContributionUpdateKind,\n change?: EditorContributionChange | null,\n ): void {\n if (\n kind === 'layout' ||\n snapshot.viewport.clientWidth !== this.latestSnapshot.viewport.clientWidth\n ) {\n this.syncTrailingInset()\n }\n this.latestSnapshot = snapshot\n // Scrolling is the one thing that moves rows under the marks without an edit\n // having happened yet, which is the only moment left to start following the\n // ones it brought in front of the reader.\n // Re-read after the line moves, not only after an edit: the set the controller is painting was\n // copied out of these ranges, so a match promoted into the mounted rows by the scroll is still\n // at the offset it was found at until the copy is taken again.\n if (kind === 'viewport' || kind === 'layout') {\n if (this.paintedMatches?.repartition(snapshot)) this.controller.refreshTrackedMatches()\n }\n this.controller.handleViewUpdate(kind, change ?? null)\n }\n\n public dispose(): void {\n this.visibleKey.dispose()\n this.subscription.dispose()\n this.reservationListener?.dispose()\n this.reservationListener = null\n this.widget?.dispose()\n this.widget = null\n this.paintedMatches = null\n this.hostRegistration.dispose()\n }\n\n private readonly trackPaintedRanges = (ranges: readonly FindRange[]): FindTrackedRanges => {\n this.paintedMatches = new PaintedFindRanges(this.context, this.latestSnapshot, ranges)\n return this.paintedMatches\n }\n\n private readonly handleUiEvent = (event: EditorFindUiEvent): void => {\n if (event.type === 'show') {\n this.ensureWidget().show(event.replaceVisible)\n return\n }\n\n if (event.type === 'hide') {\n this.widget?.hide()\n // Nothing reads the set once it is off screen, so leaving it here would\n // have every scroll from now on redraw a line across it for nobody.\n this.paintedMatches = null\n return\n }\n\n if (event.type === 'update') {\n this.widget?.update(event.state)\n return\n }\n\n this.focusWidget(event.target)\n }\n\n private focusWidget(target: 'find' | 'replace'): void {\n const widget = this.widget\n if (!widget) return\n\n if (target === 'find') widget.focusFindInput()\n if (target === 'replace') widget.focusReplaceInput()\n }\n\n private ensureWidget(): EditorFindWidget {\n if (this.widget) return this.widget\n\n this.widget = new EditorFindWidget(\n this.context.container,\n this.context.scrollElement,\n this.createWidgetOptions(),\n )\n this.observeReservedWidth()\n this.syncTrailingInset()\n return this.widget\n }\n\n private observeReservedWidth(): void {\n this.reservationListener ??= this.context.onDidChangeReservedOverlayWidth((side) => {\n if (side === 'right') this.syncTrailingInset()\n })\n }\n\n private syncTrailingInset(): void {\n if (!this.widget) return\n\n const { container, scrollElement } = this.context\n const containerRight =\n container.getBoundingClientRect().left + container.clientLeft + container.clientWidth\n const viewportRight =\n scrollElement.getBoundingClientRect().left +\n scrollElement.clientLeft +\n scrollElement.clientWidth\n const reservedWidth = this.context.getReservedOverlayWidth('right')\n this.widget.setTrailingInset(reservedWidth + Math.max(0, containerRight - viewportRight))\n }\n\n private createWidgetOptions(): EditorFindWidgetOptions {\n return {\n registerKeymapNode: (options) => this.context.registerKeymapNode(options),\n onSearchInput: (value) => this.controller.setSearchString(value),\n onReplaceInput: (value) => this.controller.setReplaceString(value),\n onToggleReplace: () => this.controller.toggleReplace(),\n onPrevious: () => this.controller.findPrevious(),\n onNext: () => this.controller.findNext(),\n onClose: () => this.controller.close(),\n onToggleCase: () => this.controller.toggleMatchCase(),\n onToggleWholeWord: () => this.controller.toggleWholeWord(),\n onToggleRegex: () => this.controller.toggleRegex(),\n onToggleScope: () => this.controller.toggleFindInSelection(),\n onTogglePreserveCase: () => this.controller.togglePreserveCase(),\n onReplaceOne: () => this.controller.replaceOne(),\n onReplaceAll: () => this.controller.replaceAll(),\n }\n }\n}\n\nclass EditorFindCommandContribution implements EditorCommandContribution {\n private readonly commands: readonly EditorDisposable[]\n\n public constructor(context: EditorCommandContributionContext, controller: EditorFindController) {\n this.commands = [\n context.registerCommand('find', () => controller.toggleFind()),\n context.registerCommand('findReplace', () => controller.openFindReplace()),\n context.registerCommand('findNext', () => controller.findNext()),\n context.registerCommand('findPrevious', () => controller.findPrevious()),\n context.registerCommand('closeFind', () => controller.close()),\n context.registerCommand('toggleFindCaseSensitive', () => controller.toggleMatchCase()),\n context.registerCommand('toggleFindWholeWord', () => controller.toggleWholeWord()),\n context.registerCommand('toggleFindRegex', () => controller.toggleRegex()),\n context.registerCommand('toggleFindInSelection', () => controller.toggleFindInSelection()),\n context.registerCommand('togglePreserveCase', () => controller.togglePreserveCase()),\n context.registerCommand('replaceOne', () => controller.replaceOne()),\n context.registerCommand('replaceAll', () => controller.replaceAll()),\n context.registerCommand('selectAllMatches', () => controller.selectAllMatches()),\n ]\n }\n\n public dispose(): void {\n disposeAll(this.commands)\n }\n}\n\nclass EditorFindCapabilityContribution implements EditorCapabilityContribution {\n private readonly registration: EditorDisposable\n\n public constructor(\n context: EditorCapabilityContributionContext,\n controller: EditorFindController,\n ) {\n this.registration = context.registerFeature(EDITOR_FIND_FEATURE, createFindFeature(controller))\n }\n\n public dispose(): void {\n this.registration.dispose()\n }\n}\n\nclass EditorFindEditContribution implements EditorEditContribution {\n private readonly registration: EditorDisposable\n\n public constructor(context: EditorEditContributionContext, controller: EditorFindController) {\n this.registration = controller.attachEditHost({\n textSnapshot: () => context.getCurrentDocumentSnapshot()?.textSnapshot ?? null,\n getSelections: () => findSelections(context.getSelections()),\n applyEdits: (edits, timingName, selection) =>\n context.applyEdits(edits, timingName, selection),\n })\n }\n\n public dispose(): void {\n this.registration.dispose()\n }\n}\n\nfunction createFindFeature(controller: EditorFindController): EditorFindFeature {\n return {\n openFind: () => controller.openFind(),\n toggleFind: () => controller.toggleFind(),\n openFindReplace: () => controller.openFindReplace(),\n closeFind: () => controller.close(),\n findNext: () => controller.findNext(),\n findPrevious: () => controller.findPrevious(),\n replaceOne: () => controller.replaceOne(),\n replaceAll: () => controller.replaceAll(),\n selectAllMatches: () => controller.selectAllMatches(),\n }\n}\n\nfunction createFindHost(\n context: EditorViewContributionContext,\n getSnapshot: () => EditorViewSnapshot,\n trackPaintedRanges: (ranges: readonly FindRange[]) => FindTrackedRanges,\n): EditorFindHost {\n const textSource = snapshotTextSource()\n return {\n hasDocument: () => context.hasDocument(),\n textSource: () => textSource(getSnapshot()),\n hasTextSnapshot: (snapshot) => getSnapshot().textSnapshot === snapshot,\n trackRanges: (ranges) => context.trackRanges(ranges),\n trackPaintedRanges,\n getSelections: () => findSelections(getSnapshot().selections),\n focusEditor: () => context.focusEditor(),\n announce: (message) => context.announce(message),\n setSelection: (anchor, head, timingName, options) =>\n context.setSelection(anchor, head, timingName, options),\n setSelections: (selections, timingName, revealOffset) =>\n context.setSelections(selections, timingName, revealOffset),\n setRangeHighlight: (name, ranges, style) => {\n context.setRangeHighlight(name, ranges, style)\n minimapFeature(context)?.setDecorations(\n name,\n minimapBands(textSource(getSnapshot()).lineStartsView, ranges, style),\n )\n },\n clearRangeHighlight: (name) => {\n context.clearRangeHighlight(name)\n minimapFeature(context)?.clearDecorations(name)\n },\n }\n}\n\nfunction minimapFeature(context: EditorViewContributionContext): EditorMinimapFeature | null {\n return context.getFeature(EDITOR_MINIMAP_FEATURE)\n}\n\n/**\n * A count says how many matches there are and nothing says where they are until\n * they reach the scroll furniture, so every group find paints in the text is\n * published under the name it is painted under.\n *\n * The band keeps its group's own colour: the minimap paints onto a canvas from a\n * worker, which has no element to resolve a registered colour against and\n * silently substitutes the selection colour for anything it cannot parse, so the\n * literal has to travel with the group rather than be looked up there.\n */\nfunction minimapBands(\n lineStartsView: FindLineStartsView,\n ranges: readonly FindRange[],\n style: VirtualizedTextHighlightStyle,\n): readonly EditorMinimapDecoration[] {\n return ranges.map((range): EditorMinimapDecoration => {\n const rows = bandRows(lineStartsView, range)\n return {\n startLineNumber: rows.start,\n startColumn: 1,\n endLineNumber: rows.end,\n endColumn: 1,\n color: style.backgroundColor,\n position: 'inline',\n zIndex: style.zIndex,\n }\n })\n}\n\n// A range ending exactly at a line start ends on the row before it: the break\n// belongs to the line it terminates, and a selection taken to the end of one row\n// should not shade the next.\nfunction bandRows(\n lineStartsView: FindLineStartsView,\n range: FindRange,\n): { readonly start: number; readonly end: number } {\n const startIndex = lineStartsView.indexForOffset(range.start)\n const endIndex = lineStartsView.indexForOffset(range.end)\n if (endIndex > startIndex && lineStartsView.at(endIndex) === range.end) {\n return { start: startIndex + 1, end: endIndex }\n }\n\n return { start: startIndex + 1, end: endIndex + 1 }\n}\n\n/**\n * Follows the ranges as far as they are painted, answering for the rest with the\n * offsets it was handed.\n *\n * A span the reader cannot see cannot be seen standing on text that moved out\n * from under it, and the re-search already on its way replaces the whole set\n * either way. Handing the document every match instead costs it an anchor pair\n * each, on every keystroke — the bill deferring that re-search was supposed to\n * take off the keystroke in the first place.\n *\n * Which of them those are is a fact about the rows mounted at the time and not\n * about the set, so it stops being true the moment the reader scrolls. Drawn once\n * and left, the line would divide the screenful they have scrolled away from,\n * and every mark now in front of them would be one nobody is following.\n */\n// A match is the text the query answered for, so typing against either edge of one is not part of\n// it — unlike a scope, which is a region the reader drew and which takes in what they add at its\n// edges. The same pair decides how an offset is carried across an edit nobody was following.\nconst MATCH_BIAS = { startBias: 'right', endBias: 'left' } as const\n\nclass PaintedFindRanges implements FindTrackedRanges {\n private span: FindRange | null = null\n private tracked: FindTrackedRanges | null = null\n private elsewhere: readonly FindRange[]\n /** Text version the offsets in `elsewhere` describe, which is not always the document's. */\n private elsewhereVersion: number\n private elsewhereSyncPoint: DocumentSyncPoint\n\n public constructor(\n private readonly context: EditorViewContributionContext,\n snapshot: EditorViewSnapshot,\n ranges: readonly FindRange[],\n ) {\n this.elsewhere = ranges\n this.elsewhereVersion = snapshot.textVersion\n this.elsewhereSyncPoint = snapshot.documentSyncPoint\n this.partition(snapshot)\n }\n\n public resolve(): readonly FindRange[] {\n if (!this.tracked) return this.elsewhere\n return mergeRanges(this.tracked.resolve(), this.elsewhere)\n }\n\n /** Answers whether the line moved, so a caller only re-reads the set when there is a reason to. */\n public repartition(snapshot: EditorViewSnapshot): boolean {\n return this.partition(snapshot)\n }\n\n private partition(snapshot: EditorViewSnapshot): boolean {\n const span = paintedSpan(snapshot)\n if (!span || sameSpan(span, this.span)) return false\n\n // Read back first: what is already followed has moved since it was handed\n // over, and re-partitioning the offsets of the search would undo that.\n this.carryElsewhereForward(snapshot)\n const ranges = this.resolve()\n const painted = ranges.filter((range) => overlapsSpan(range, span))\n const tracked = painted.length === 0 ? null : this.context.trackRanges(painted, MATCH_BIAS)\n\n this.span = span\n this.tracked = tracked\n this.elsewhere = tracked ? ranges.filter((range) => !overlapsSpan(range, span)) : ranges\n this.elsewhereVersion = snapshot.textVersion\n this.elsewhereSyncPoint = snapshot.documentSyncPoint\n return true\n }\n\n /**\n * Brings the unfollowed half up to the document before any of it is promoted.\n *\n * Nothing follows a match the reader cannot see, so an edit that lands while they are looking\n * elsewhere leaves those offsets describing text that has moved. Scrolling then hands one of them\n * to the document to be followed from where it used to be, and the mark lands beside its word —\n * the defect being followed at all was supposed to prevent, arriving one scroll later. The edits\n * are replayed where the host can name them, and where it cannot the offsets are dropped rather\n * than promoted: no mark is the honest answer for the moment before the re-search lands, and a\n * mark on the wrong word is not.\n */\n private carryElsewhereForward(snapshot: EditorViewSnapshot): void {\n if (snapshot.textVersion === this.elsewhereVersion) return\n if (this.elsewhere.length === 0) {\n this.elsewhereVersion = snapshot.textVersion\n this.elsewhereSyncPoint = snapshot.documentSyncPoint\n return\n }\n\n const edits =\n snapshot.changesSinceDocumentSyncPoint(this.elsewhereSyncPoint, null)?.edits ?? null\n this.elsewhere = edits\n ? this.elsewhere\n .map((range) => projectDecorationRangeThroughEdits({ ...range, ...MATCH_BIAS }, edits))\n .filter((range) => range !== null)\n .map((range) => ({ end: range.end, start: range.start }))\n : []\n this.elsewhereVersion = snapshot.textVersion\n this.elsewhereSyncPoint = snapshot.documentSyncPoint\n }\n}\n\n// The view adds a range highlight to the rows it has mounted and to no others.\nfunction paintedSpan(snapshot: EditorViewSnapshot): FindRange | null {\n const first = snapshot.visibleRows[0]\n const last = snapshot.visibleRows.at(-1)\n if (!first || !last) return null\n\n return { start: first.startOffset, end: last.endOffset }\n}\n\nfunction overlapsSpan(range: FindRange, span: FindRange): boolean {\n return range.end > span.start && range.start < span.end\n}\n\nfunction sameSpan(span: FindRange, other: FindRange | null): boolean {\n return other !== null && span.start === other.start && span.end === other.end\n}\n\n// Navigation steps the set rather than searching it, so an entry out of order\n// answers the next press with the wrong match.\nfunction mergeRanges(\n left: readonly FindRange[],\n right: readonly FindRange[],\n): readonly FindRange[] {\n if (right.length === 0) return left\n\n const merged: FindRange[] = []\n let leftIndex = 0\n let rightIndex = 0\n while (leftIndex < left.length && rightIndex < right.length) {\n if (compareTextOffsetRanges(left[leftIndex]!, right[rightIndex]!) <= 0) {\n merged.push(left[leftIndex]!)\n leftIndex += 1\n continue\n }\n\n merged.push(right[rightIndex]!)\n rightIndex += 1\n }\n\n for (; leftIndex < left.length; leftIndex += 1) merged.push(left[leftIndex]!)\n for (; rightIndex < right.length; rightIndex += 1) merged.push(right[rightIndex]!)\n return merged\n}\n\n/**\n * The text a search reads, kept for as long as the snapshot it was taken from.\n *\n * Either view can be absent, and standing in for a missing one materializes what\n * it exists to avoid: a copy of the document, or the whole line-start array.\n * Every press in the find box searches again, so a stand-in built per search\n * would hand a keystroke exactly the bill that ranged reads are here to spare it.\n * Held against the snapshot itself rather than its text version, because a\n * document swap can carry that version across unchanged.\n */\nfunction snapshotTextSource(): (snapshot: EditorViewSnapshot) => FindTextSource {\n let cached: { readonly snapshot: EditorViewSnapshot; readonly source: FindTextSource } | null =\n null\n return (snapshot) => {\n if (cached?.snapshot !== snapshot) cached = { snapshot, source: findTextSource(snapshot) }\n return cached.source\n }\n}\n\nfunction findTextSource(snapshot: EditorViewSnapshot): FindTextSource {\n const text = snapshot.textSnapshot\n return {\n length: text.length,\n readRange: (start, end) => text.readRange(start, end),\n lineStartsView: snapshot.lineStartsView,\n }\n}\n\nfunction findSelections(\n selections: readonly EditorResolvedSelection[],\n): readonly EditorFindResolvedSelection[] {\n return selections.map((selection) => ({\n ...selection,\n collapsed: selection.startOffset === selection.endOffset,\n }))\n}\n\nfunction disposeAll(disposables: readonly EditorDisposable[]): void {\n for (const disposable of disposables.toReversed()) disposable.dispose()\n}\n\nexport type { EditorFindFeature, EditorFindOptions }\n"],"mappings":";;;;;AAqDA,SAAgB,uBAAuB,UAA6B,CAAC,GAAiB;CACpF,OAAO;EACL,MAAM;EACN,SAAS,SAAS;GAChB,MAAM,YAAY,sCAAsC,OAAO;GAC/D,OAAO;IACL,QAAQ,yBAAyB,UAAU,IAAI;IAC/C,QAAQ,4BAA4B,UAAU,OAAO;IACrD,QAAQ,+BAA+B,UAAU,UAAU;IAC3D,QAAQ,yBAAyB,UAAU,IAAI;GACjD;EACF;CACF;AACF;AAEA,SAAgB,sCACd,UAA6B,CAAC,GACG;CACjC,MAAM,aAAa,IAAI,qBAAqB,OAAO;CACnD,OAAO;EACL,MAAM,EACJ,qBAAqB,YAAY,IAAI,2BAA2B,SAAS,UAAU,EACrF;EACA,SAAS,EACP,qBAAqB,YAAY,IAAI,8BAA8B,SAAS,UAAU,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AACJ;AAEA,SAAS,WAAW,aAAgD;CAClE,KAAK,MAAM,cAAc,YAAY,WAAW,GAAG,WAAW,QAAQ;AACxE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replacePattern.d.ts","sourceRoot":"","sources":["../src/replacePattern.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAc;IAON,OAAO,CAAC,QAAQ,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"replacePattern.d.ts","sourceRoot":"","sources":["../src/replacePattern.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAc;IAON,OAAO,CAAC,QAAQ,CAAC,MAAM;IAN1C,OAAc,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAE3D;IAED,SAAgB,sBAAsB,EAAE,OAAO,CAAA;IAE/C,YAAoC,MAAM,EAAE,SAAS,YAAY,EAAE,EAElE;IAEM,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,EAAE,YAAY,UAAQ,GAAG,MAAM,CAWzF;CACF;AAED,KAAK,YAAY,GACb;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAA;AAE3F,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,cAAc,CAgBxE"}
|
package/dist/replacePattern.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/replacePattern.ts
|
|
2
2
|
var ReplacePattern = class ReplacePattern {
|
|
3
3
|
pieces;
|
|
4
4
|
static fromStaticValue(value) {
|
|
@@ -206,7 +206,6 @@ function isDigit(value) {
|
|
|
206
206
|
function isNonZeroDigit(value) {
|
|
207
207
|
return value >= "1" && value <= "9";
|
|
208
208
|
}
|
|
209
|
-
//#endregion
|
|
210
209
|
export { ReplacePattern, parseReplaceString };
|
|
211
210
|
|
|
212
211
|
//# sourceMappingURL=replacePattern.js.map
|
package/dist/search.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { codePointSizeAt, compareTextOffsetRanges, isWholeWordRange } from "@singapore-editor/core/document";
|
|
2
|
-
|
|
2
|
+
// src/search.ts
|
|
3
3
|
var FIND_MATCHES_LIMIT = 19999;
|
|
4
4
|
var FIND_REPLACE_ALL_LIMIT = 1073741824;
|
|
5
5
|
var FIND_WINDOW_UNITS = 65536;
|
|
@@ -330,7 +330,7 @@ function searchRanges(source, ranges) {
|
|
|
330
330
|
const clamped = ranges.map((range) => ({
|
|
331
331
|
start: clampSourceOffset(source, range.start),
|
|
332
332
|
end: clampSourceOffset(source, range.end)
|
|
333
|
-
})).filter((range) => range.start <= range.end).
|
|
333
|
+
})).filter((range) => range.start <= range.end).sort(compareTextOffsetRanges);
|
|
334
334
|
const merged = [];
|
|
335
335
|
for (const range of clamped) {
|
|
336
336
|
const previous = merged.at(-1);
|
|
@@ -464,7 +464,6 @@ function validWholeWordMatch(text, start, length, wholeWord) {
|
|
|
464
464
|
end: start + length
|
|
465
465
|
});
|
|
466
466
|
}
|
|
467
|
-
//#endregion
|
|
468
467
|
export { FIND_MATCHES_LIMIT, FIND_REPLACE_ALL_LIMIT, FIND_WINDOW_UNITS, countMatches, escapeRegExpCharacters, findLineRange, findMatchIndex, findMatches, findNextMatchFrom, findPreviousMatchFrom, findTextSourceFromSnapshot };
|
|
469
468
|
|
|
470
469
|
//# sourceMappingURL=search.js.map
|
package/dist/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","names":[],"sources":["../src/search.ts"],"sourcesContent":["import {\n codePointSizeAt,\n compareTextOffsetRanges,\n isWholeWordRange,\n type TextOffsetRange,\n type TextReadSnapshot,\n} from '@singapore-editor/core/document'\n\n// Bounds the match set the widget counts and paints, so a pathological query\n// on a huge file cannot stall the frame.\nexport const FIND_MATCHES_LIMIT = 19_999\n\n// Replace All must never apply to a truncated match set: stopping early would\n// silently rewrite part of the document and leave the rest, with no signal to\n// the user. Searching is linear, so the only real cost of lifting the cap here\n// is the edit batch itself.\nexport const FIND_REPLACE_ALL_LIMIT = 1_073_741_824\n\n// How much text a windowed scan reads at once, rounded up to whole lines. Large\n// enough that the tree descent per read is noise, small enough that a fragmented\n// document is never joined into one string the size of the file.\nexport const FIND_WINDOW_UNITS = 65_536\n\n// Escapes whose class cannot hold a line break, so a pattern built only from\n// these can be answered a line at a time. A carriage return is among them: it\n// sits inside a line, not between two.\nconst LINE_SAFE_ESCAPES = new Set(['d', 'w', 't', 'r', 'f', 'v', 'b', 'B', '0'])\n\nexport type FindRange = TextOffsetRange\n\n// Read-only line-start access, structurally the view a document snapshot\n// already hands out, so a search never asks for the array behind it.\nexport type FindLineStartsView = {\n readonly length: number\n at(index: number): number | undefined\n indexForOffset(offset: number): number\n}\n\n/**\n * The text a search reads, in ranges rather than as one string.\n *\n * A query that cannot match a line break is answered a line at a time, so a\n * keystroke in the find box costs the lines examined instead of a copy of the\n * whole document — and a chunked buffer gets searched where it lies.\n */\nexport type FindTextSource = {\n readonly length: number\n readRange(start: number, end: number): string\n readonly lineStartsView: FindLineStartsView\n}\n\nexport function findTextSourceFromSnapshot(snapshot: TextReadSnapshot): FindTextSource {\n return {\n length: snapshot.length,\n readRange: (start, end) => snapshot.readRange(start, end),\n lineStartsView: {\n length: snapshot.lineCount,\n at: (index) =>\n index < 0 || index >= snapshot.lineCount ? undefined : snapshot.lineStart(index),\n indexForOffset: (offset) => snapshot.lineAt(offset),\n },\n }\n}\n\nexport type FindQuery = {\n readonly searchString: string\n readonly isRegex: boolean\n readonly matchCase: boolean\n readonly wholeWord: boolean\n}\n\nexport type FindMatch = FindRange & {\n readonly matches: readonly string[] | null\n}\n\nexport type FindMatchFromOptions = {\n readonly captureMatches?: boolean\n readonly loop?: boolean\n readonly escapeEmptyMatchAtOffset?: boolean\n}\n\n/** What the two directions have in common, so one caller can hold either. */\nexport type FindMatchFromSearcher = (\n source: FindTextSource,\n query: FindQuery,\n offset: number,\n ranges: readonly FindRange[] | null,\n options: FindMatchFromOptions,\n) => FindMatch | null\n\ntype CompiledFindQuery = {\n readonly regex: RegExp\n // Non-null only when a plain indexOf over the untouched text is exactly\n // equivalent to the regex; see compileFindQuery.\n readonly simpleSearch: string | null\n readonly wholeWord: boolean\n readonly plan: FindQueryPlan\n}\n\n/**\n * How much text one match can depend on, which is what decides how it is read.\n *\n * `lines` and `anchored-lines` cannot match a break, so they are read in windows\n * of whole lines. `literal-lines` is a literal holding breaks: it spans a known\n * number of lines, so it is windowed too. `range` is every pattern nothing here\n * can bound, read as one window because that is the only reading always correct.\n */\nexport type FindQueryPlan =\n | { readonly kind: 'lines' }\n | { readonly kind: 'anchored-lines' }\n | { readonly kind: 'literal-lines'; readonly lineBreaks: number }\n | { readonly kind: 'range'; readonly reason: 'pattern-may-match-line-break' }\n\n// One stretch of the document already read: the text of\n// `[start, start + text.length)`, to be searched from `from` onward.\ntype FindWindow = {\n readonly text: string\n readonly start: number\n readonly from: number\n}\n\nexport function findMatches(\n source: FindTextSource,\n query: FindQuery,\n ranges: readonly FindRange[] | null = null,\n captureMatches = false,\n limit = FIND_MATCHES_LIMIT,\n): readonly FindMatch[] {\n const compiled = compileFindQuery(query)\n if (!compiled || limit <= 0) return []\n\n const matches: FindMatch[] = []\n const collect: FindMatchVisitor = (start, end, captures) => {\n matches.push({ start, end, matches: captures })\n return matches.length < limit\n }\n for (const range of searchRanges(source, ranges)) {\n scanRange(source, compiled, range, captureMatches, collect)\n if (matches.length >= limit) break\n }\n\n return matches\n}\n\n/**\n * Every match counted, none kept: a total costs no record per match.\n *\n * With `before`, only the matches starting in front of that offset, which is the\n * position of a match the listing stopped short of.\n */\nexport function countMatches(\n source: FindTextSource,\n query: FindQuery,\n ranges: readonly FindRange[] | null = null,\n before = Number.POSITIVE_INFINITY,\n): number {\n const compiled = compileFindQuery(query)\n if (!compiled) return 0\n\n let count = 0\n const tally: FindMatchVisitor = (start) => {\n if (start >= before) return false\n\n count += 1\n return true\n }\n for (const range of searchRanges(source, ranges)) {\n if (range.start >= before) break\n scanRange(source, compiled, range, false, tally)\n }\n\n return count\n}\n\n/** Null for a query that cannot be compiled, which is one that finds nothing. */\nexport function findQueryPlan(query: FindQuery): FindQueryPlan | null {\n return compileFindQuery(query)?.plan ?? null\n}\n\n/** The line holding `offset`, break excluded. */\nexport function findLineRange(source: FindTextSource, offset: number): FindRange {\n const index = source.lineStartsView.indexForOffset(offset)\n return { start: source.lineStartsView.at(index) ?? 0, end: lineEndAt(source, index) }\n}\n\n/**\n * One match, scanned for from an offset instead of picked out of a list.\n *\n * A listing stops at FIND_MATCHES_LIMIT, and past that every entry in it sits\n * behind the cursor: picking from it answers each press with the top of the\n * document. Scanning outward stops at the first match it reaches, so how far\n * navigation can go is not what a paint budget allowed.\n */\nexport function findNextMatchFrom(\n source: FindTextSource,\n query: FindQuery,\n offset: number,\n ranges: readonly FindRange[] | null = null,\n options: FindMatchFromOptions = {},\n): FindMatch | null {\n const compiled = compileFindQuery(query)\n if (!compiled) return null\n\n const searched = searchRanges(source, ranges)\n const from = clampSourceOffset(source, offset)\n const ahead = firstMatchAfter(source, compiled, searched, from, options)\n if (ahead) return ahead\n if (options.loop === false) return null\n\n // Wrapping is a second bounded scan rather than a listing, so a cursor past\n // the last match still costs only the text up to the first one.\n return firstMatchAtOrAfter(source, compiled, searched, searched[0]?.start ?? 0, options)\n}\n\nexport function findPreviousMatchFrom(\n source: FindTextSource,\n query: FindQuery,\n offset: number,\n ranges: readonly FindRange[] | null = null,\n options: FindMatchFromOptions = {},\n): FindMatch | null {\n const compiled = compileFindQuery(query)\n if (!compiled) return null\n\n const searched = searchRanges(source, ranges)\n const from = clampSourceOffset(source, offset)\n const behind = lastMatchBefore(source, compiled, searched, from, options)\n if (behind) return behind\n if (options.loop === false) return null\n\n return lastMatchBefore(source, compiled, searched, source.length, {\n ...options,\n escapeEmptyMatchAtOffset: false,\n })\n}\n\nexport function findMatchIndex(matches: readonly FindMatch[], range: FindRange): number {\n return matches.findIndex((match) => match.start === range.start && match.end === range.end)\n}\n\nexport function escapeRegExpCharacters(value: string): string {\n return value.replace(/[\\\\{}*+?|^$.[\\]()]/g, '\\\\$&')\n}\n\n// The break belongs to no line: a query that cannot match one would otherwise be\n// handed a haystack whose `$` sits behind it.\nfunction lineEndAt(source: FindTextSource, index: number): number {\n const nextLineStart = source.lineStartsView.at(index + 1)\n return nextLineStart === undefined ? source.length : nextLineStart - 1\n}\n\nfunction escapesEmptyMatch(match: FindMatch, offset: number, escape: boolean): boolean {\n return escape && match.start === match.end && match.start === offset\n}\n\nfunction firstMatchAfter(\n source: FindTextSource,\n query: CompiledFindQuery,\n ranges: readonly FindRange[],\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n const found = firstMatchAtOrAfter(source, query, ranges, offset, options)\n if (!found) return null\n if (!escapesEmptyMatch(found, offset, options.escapeEmptyMatchAtOffset ?? false)) return found\n\n // Resumed past the offset itself, once: whatever stands there is the entry\n // after the one being escaped, empty or not.\n return firstMatchAtOrAfter(source, query, ranges, nextCodePointOffset(source, offset), options)\n}\n\nfunction firstMatchAtOrAfter(\n source: FindTextSource,\n query: CompiledFindQuery,\n ranges: readonly FindRange[],\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n for (const range of ranges) {\n if (range.end < offset) continue\n\n const found = firstMatchInRange(source, query, range, offset, options.captureMatches ?? false)\n if (found) return found\n }\n\n return null\n}\n\n// The range is never cut at the offset: a pattern resumed there simply begins a\n// fresh match at the cursor — 'pha' inside 'alpha' for `\\w+` — and a range no\n// listing of the document holds is one the reader was never shown and Replace\n// must never rewrite. What the offset decides is which matches are kept, not\n// where the scan starts. Uncapped, because what stands at the cursor is being\n// asked for regardless of where the paint budget ran out.\nfunction firstMatchInRange(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n offset: number,\n captureMatches: boolean,\n): FindMatch | null {\n let found: FindMatch | null = null\n const scanned = { start: forwardScanStart(source, query, range, offset), end: range.end }\n scanRange(source, query, scanned, captureMatches, (start, end, captures) => {\n if (start < offset) return true\n\n found = { start, end, matches: captures }\n return false\n })\n\n return found\n}\n\n// Lines in front of the cursor are skipped rather than searched: a match that\n// cannot hold a break cannot reach out of the line it starts on, so none of them\n// could answer at or after the offset anyway.\nfunction forwardScanStart(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n offset: number,\n): number {\n if (!isLineLocalPlan(query.plan)) return range.start\n\n const lineStartsView = source.lineStartsView\n const line = lineStartsView.indexForOffset(Math.max(range.start, offset))\n return Math.max(range.start, lineStartsView.at(line) ?? 0)\n}\n\nfunction isLineLocalPlan(plan: FindQueryPlan): boolean {\n return plan.kind === 'lines' || plan.kind === 'anchored-lines'\n}\n\nfunction lastMatchBefore(\n source: FindTextSource,\n query: CompiledFindQuery,\n ranges: readonly FindRange[],\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n for (const range of ranges.toReversed()) {\n if (range.start > offset) continue\n\n const found = lastMatchInRange(source, query, range, offset, options)\n if (found) return found\n }\n\n return null\n}\n\n// Walked back a window at a time, because the match before the cursor is the one\n// being asked for and listing everything behind it to reach the last entry is\n// the whole document on a search that started near its end.\nfunction lastMatchInRange(\n source: FindTextSource,\n query: CompiledFindQuery,\n searched: FindRange,\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n // A pattern that can run past a break is shown the text behind the cursor too:\n // cut at the cursor's line, `[^a]+$` would end there on a match no listing of\n // the document holds. The scan still stops at the first match past the cursor.\n if (!isLineLocalPlan(query.plan))\n return lastMatchInWindow(source, query, searched, offset, options)\n\n const range = { start: searched.start, end: Math.min(searched.end, offset) }\n const lineStartsView = source.lineStartsView\n let last = lineStartsView.indexForOffset(range.end)\n while (last >= 0) {\n const reach = Math.max(range.start, (lineStartsView.at(last) ?? 0) - FIND_WINDOW_UNITS)\n const first = lineStartsView.indexForOffset(reach)\n const firstStart = lineStartsView.at(first) ?? 0\n const window = {\n start: Math.max(range.start, firstStart),\n end: Math.min(range.end, lineEndAt(source, last)),\n }\n const found =\n window.end < window.start ? null : lastMatchInWindow(source, query, window, offset, options)\n if (found) return found\n if (firstStart <= range.start) return null\n\n last = first - 1\n }\n\n return null\n}\n\n// The last match in one window, escaping the same way stepping an ordered list\n// does: what stands before a zero-width match parked on the cursor is the entry\n// the search is being asked for, and it may be in an earlier window. Uncapped,\n// and only the last two are kept: a listing that stopped at the paint cap would\n// answer every press behind the cursor with the 19,999th match.\nfunction lastMatchInWindow(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n let last: FindMatch | null = null\n let beforeLast: FindMatch | null = null\n scanRange(source, query, range, options.captureMatches ?? false, (start, end, captures) => {\n if (end > offset) return false\n\n beforeLast = last\n last = { start, end, matches: captures }\n return true\n })\n if (!last) return null\n if (!escapesEmptyMatch(last, offset, options.escapeEmptyMatchAtOffset ?? false)) return last\n\n return beforeLast\n}\n\n// A pattern compiled with the unicode flag may not be resumed inside a surrogate\n// pair, so stepping off an empty match steps a code point rather than a unit.\nfunction nextCodePointOffset(source: FindTextSource, offset: number): number {\n const text = source.readRange(offset, Math.min(source.length, offset + 2))\n return offset + Math.max(1, codePointSizeAt(text, 0))\n}\n\n// True when the query contains at least one character whose case can differ,\n// which is the only situation where matchCase changes what a plain search\n// finds. Digits, punctuation and CJK are caseless, so an untouched indexOf is\n// still exact for them even with matchCase off.\nfunction queryIsCaseSensitiveByContent(searchString: string): boolean {\n return searchString.toLowerCase() !== searchString.toUpperCase()\n}\n\n/**\n * Whether every part of a pattern is provably unable to match a line break.\n *\n * Asked the safe way round. Listing the constructs that CAN hold a break means\n * one nobody thought of routes a query to the windowed path, where it answers\n * \"no results\" for text that is plainly there — the one wrong answer a search\n * must never give. So a query is windowed only when every part of it is provably\n * break-free, and anything unrecognized takes the slower path that is always\n * correct.\n */\nfunction isLineSafePattern(pattern: string): boolean {\n for (let index = 0; index < pattern.length; index += 1) {\n const char = pattern[index]\n if (char === '\\n') return false\n if (char === '[') {\n const end = characterClassEnd(pattern, index)\n if (end === null || !isLineSafeCharacterClass(pattern.slice(index + 1, end))) return false\n\n index = end\n continue\n }\n\n if (char === '(' && !isLineSafeGroupOpener(pattern, index)) return false\n if (char !== '\\\\') continue\n\n index += 1\n const escaped = pattern[index]\n if (escaped === undefined) return false\n // A hex or unicode escape can spell the break itself, and reading which one\n // it spells is more machinery than routing it to the correct path costs.\n if (!LINE_SAFE_ESCAPES.has(escaped) && /[\\p{L}\\p{N}]/u.test(escaped)) return false\n }\n\n return true\n}\n\n/**\n * Only a group that bundles what is written inside it, leaving its meaning alone.\n *\n * A capture, a non-capture and either lookaround are all of those. A modifier\n * group is not: it can switch on the flag under which a dot spans a break, so the\n * characters inside it stop saying what they say anywhere else — and reading back\n * which flags one names is more machinery than routing it to the correct path\n * costs. Every other spelling is one nobody here recognized, which is the same\n * answer.\n */\nfunction isLineSafeGroupOpener(pattern: string, index: number): boolean {\n if (pattern[index + 1] !== '?') return true\n\n const kind = pattern[index + 2]\n // '<' opens a lookbehind or names a capture, and neither changes what matches.\n return kind === ':' || kind === '=' || kind === '!' || kind === '<'\n}\n\n// Only a positive class naming its members outright: a negated one holds a break\n// unless it names it, and an escape inside one can bring a whole class with it.\nfunction isLineSafeCharacterClass(body: string): boolean {\n if (body.startsWith('^')) return false\n return !body.includes('\\\\') && !body.includes('\\n')\n}\n\nfunction characterClassEnd(pattern: string, from: number): number | null {\n for (let index = from + 1; index < pattern.length; index += 1) {\n if (pattern[index] === '\\\\') index += 1\n else if (pattern[index] === ']') return index\n }\n\n return null\n}\n\nfunction compileFindQuery(query: FindQuery): CompiledFindQuery | null {\n if (query.searchString.length === 0) return null\n\n const source = query.isRegex ? query.searchString : escapeRegExpCharacters(query.searchString)\n const plan = planFindQuery(query)\n const lineCrossing = plan.kind === 'range' || plan.kind === 'literal-lines'\n // Flags describe the haystack, and only a line-crossing search is ever handed\n // one holding a break: a per-line slice bounds `^` and `$` by itself, so `m`\n // there would only claim breaks the slice does not contain.\n const flags = `g${query.matchCase ? '' : 'i'}${lineCrossing ? 'm' : ''}`\n\n // The fast path may never case-fold the haystack: folding is not\n // length-preserving (U+0130 'İ' lowercases to two code units), so an index\n // into folded text does not address the original text, and a match reported\n // from it slices the wrong characters — Replace would then overwrite them.\n // Fall back to the case-insensitive regex, which reports original indices.\n const canUseSimpleSearch =\n !query.isRegex && (query.matchCase || !queryIsCaseSensitiveByContent(query.searchString))\n\n const regex = compileRegex(source, flags)\n if (!regex) return null\n\n return {\n regex,\n simpleSearch: canUseSimpleSearch ? query.searchString : null,\n wholeWord: query.wholeWord,\n plan,\n }\n}\n\nfunction planFindQuery(query: FindQuery): FindQueryPlan {\n if (!query.isRegex) {\n const lineBreaks = query.searchString.split('\\n').length - 1\n return lineBreaks === 0 ? { kind: 'lines' } : { kind: 'literal-lines', lineBreaks }\n }\n\n if (!isLineSafePattern(query.searchString))\n return { kind: 'range', reason: 'pattern-may-match-line-break' }\n return hasLineAnchor(query.searchString) ? { kind: 'anchored-lines' } : { kind: 'lines' }\n}\n\n// Asked of a pattern already known to be line-safe, so a class cannot be negated\n// and a `^` inside one is a member rather than an anchor.\nfunction hasLineAnchor(pattern: string): boolean {\n for (let index = 0; index < pattern.length; index += 1) {\n const char = pattern[index]\n if (char === '\\\\') index += 1\n else if (char === '[') index = characterClassEnd(pattern, index) ?? pattern.length\n else if (char === '^' || char === '$') return true\n }\n\n return false\n}\n\n/**\n * The pattern under the unicode flag where it takes it, and without it where it\n * does not.\n *\n * Wanted, because `u` is what makes a surrogate pair one character to a dot and\n * `\\p{...}` mean anything at all. Not required, because its grammar rejects\n * spellings the flagless one accepts — an identity escape of a character that\n * needs none (`\\-`, `\\ `), a brace or bracket standing for itself, a legacy\n * back-reference — and every one of those is what escaping a search by hand\n * produces. A rejected pattern is not reported anywhere the user can see it: it\n * reaches them as \"No results\", indistinguishable from text that is not there.\n */\nfunction compileRegex(source: string, flags: string): RegExp | null {\n try {\n return new RegExp(source, `${flags}u`)\n } catch {\n // Ignored: whether the pattern is invalid outright or only invalid under the\n // stricter grammar is what the second construction answers.\n }\n\n try {\n return new RegExp(source, flags)\n } catch {\n return null\n }\n}\n\nfunction searchRanges(\n source: FindTextSource,\n ranges: readonly FindRange[] | null,\n): readonly FindRange[] {\n if (!ranges || ranges.length === 0) return [{ start: 0, end: source.length }]\n\n const clamped = ranges\n .map((range) => ({\n start: clampSourceOffset(source, range.start),\n end: clampSourceOffset(source, range.end),\n }))\n .filter((range) => range.start <= range.end)\n .toSorted(compareTextOffsetRanges)\n\n // Scopes are followed through edits, and an edit spanning the seam between two\n // of them leaves them overlapping. Searching both would report the text they\n // share twice, which a Replace All then tries to rewrite twice.\n const merged: FindRange[] = []\n for (const range of clamped) {\n const previous = merged.at(-1)\n if (previous && range.start <= previous.end) {\n merged[merged.length - 1] = { start: previous.start, end: Math.max(previous.end, range.end) }\n continue\n }\n\n merged.push(range)\n }\n\n return merged\n}\n\nfunction clampSourceOffset(source: FindTextSource, offset: number): number {\n return Math.min(Math.max(0, offset), source.length)\n}\n\n// Visited in document order; false stops the scan where it stands.\ntype FindMatchVisitor = (start: number, end: number, captures: RegExpExecArray | null) => boolean\n\n/** False once the range is spent or the visitor stopped: nothing later in it is read. */\nfunction scanRange(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n): boolean {\n if (query.plan.kind === 'range')\n return scanWholeRange(source, query, range, captureMatches, visit)\n if (query.plan.kind === 'literal-lines')\n return scanSpanningLiteral(source, query, range, query.plan.lineBreaks, visit)\n\n return scanLines(source, query, range, captureMatches, visit)\n}\n\n// Whole lines, even where the range was cut inside one: the anchors and the word\n// boundaries have to answer for the line the reader sees rather than for where\n// the range happens to end, so the range only decides which matches are kept.\n//\n// Read many lines to a window. A match that cannot hold a break cannot leave its\n// line, and a break is no word character, so a pattern with no `^` or `$` finds in\n// the window exactly what it finds line by line, without a tree descent per line.\nfunction scanLines(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n): boolean {\n const lineStartsView = source.lineStartsView\n let index = lineStartsView.indexForOffset(range.start)\n while (index < lineStartsView.length) {\n const start = lineStartsView.at(index)\n if (start === undefined || start > range.end) return true\n\n const last = lastWindowLine(source, index, start, range.end)\n const window = readWindow(source, start, lineEndAt(source, last), range)\n if (!scanLineWindow(window, query, range, captureMatches, visit)) return false\n index = last + 1\n }\n\n return true\n}\n\nfunction lastWindowLine(\n source: FindTextSource,\n first: number,\n start: number,\n rangeEnd: number,\n): number {\n const reach = Math.min(rangeEnd, start + FIND_WINDOW_UNITS)\n return Math.max(first, source.lineStartsView.indexForOffset(reach))\n}\n\nfunction scanLineWindow(\n window: FindWindow,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n): boolean {\n if (query.plan.kind !== 'anchored-lines')\n return scanWindow(window, query, range, captureMatches, visit)\n\n // `^` and `$` answer for the ends of the haystack, so each line is its own.\n let lineStart = 0\n while (lineStart <= window.text.length) {\n const found = window.text.indexOf('\\n', lineStart)\n const lineEnd = found === -1 ? window.text.length : found\n const line = {\n text: window.text.slice(lineStart, lineEnd),\n start: window.start + lineStart,\n from: Math.max(0, window.from - lineStart),\n }\n if (lineEnd >= window.from && !scanWindow(line, query, range, captureMatches, visit))\n return false\n\n lineStart = lineEnd + 1\n }\n\n return true\n}\n\n// A literal holding breaks spans exactly that many lines past the one it starts\n// on, so windows overlapping by that many lines show every match whole to at\n// least one of them. The cursor is carried across: restarting the greedy scan at\n// an overlap's first character would change which of two overlapping candidates\n// wins, and with it every match after them.\nfunction scanSpanningLiteral(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n lineBreaks: number,\n visit: FindMatchVisitor,\n): boolean {\n const lineStartsView = source.lineStartsView\n const finalLine = lineStartsView.indexForOffset(range.end)\n let first = lineStartsView.indexForOffset(range.start)\n const cursor = { offset: range.start }\n while (first <= finalLine) {\n const start = lineStartsView.at(first) ?? 0\n const last = Math.min(\n finalLine,\n Math.max(first + lineBreaks, lastWindowLine(source, first, start, range.end)),\n )\n const text = source.readRange(start, Math.max(start, lineEndAt(source, last)))\n const window = { text, start, from: Math.max(0, cursor.offset - start) }\n if (!scanWindow(window, query, range, false, visit, cursor)) return false\n if (last === finalLine) return true\n\n first = last + 1 - lineBreaks\n }\n\n return true\n}\n\n// Listing every match of a pattern that can span the range's ends has to look at\n// every character between them, so the range is read as one window: a window\n// grown in steps would only re-run the pattern over text it already scanned. The\n// window still stops on line boundaries, or `^` and `$` would answer for its cut\n// ends instead of for real ones.\nfunction scanWholeRange(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n): boolean {\n const lineStartsView = source.lineStartsView\n const start = lineStartsView.at(lineStartsView.indexForOffset(range.start)) ?? 0\n const end = lineEndAt(source, lineStartsView.indexForOffset(range.end))\n const window = readWindow(source, start, Math.max(start, end), range)\n return scanWindow(window, query, range, captureMatches, visit)\n}\n\nfunction readWindow(\n source: FindTextSource,\n start: number,\n end: number,\n range: FindRange,\n): FindWindow {\n return { text: source.readRange(start, end), start, from: Math.max(0, range.start - start) }\n}\n\n// Where the next raw match may begin. It moves past every raw match, including\n// one the whole-word filter rejects, so the scan keeps one non-overlap phase.\ntype FindCursor = { offset: number }\n\n/** False once the range is spent or the visitor stopped, so no later window can add anything. */\nfunction scanWindow(\n window: FindWindow,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n cursor?: FindCursor,\n): boolean {\n if (query.simpleSearch && !captureMatches)\n return scanSimpleMatches(window, query.simpleSearch, query.wholeWord, range, visit, cursor)\n\n return scanRegexMatches(window, query, range, captureMatches, visit, cursor)\n}\n\nfunction scanSimpleMatches(\n window: FindWindow,\n searchString: string,\n wholeWord: boolean,\n range: FindRange,\n visit: FindMatchVisitor,\n cursor?: FindCursor,\n): boolean {\n // Searched as-is: no folded copy of the text is allocated, and every index\n // returned addresses the window it came from.\n let index = window.text.indexOf(searchString, window.from)\n while (index !== -1) {\n const start = window.start + index\n const end = start + searchString.length\n if (end > range.end) return false\n if (cursor) cursor.offset = end\n if (validWholeWordMatch(window.text, index, searchString.length, wholeWord)) {\n if (!visit(start, end, null)) return false\n }\n\n index = window.text.indexOf(searchString, index + searchString.length)\n }\n\n return true\n}\n\nfunction scanRegexMatches(\n window: FindWindow,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n cursor?: FindCursor,\n): boolean {\n query.regex.lastIndex = window.from\n while (true) {\n const match = query.regex.exec(window.text)\n if (!match) return true\n\n const start = window.start + match.index\n const end = start + match[0].length\n if (start > range.end || end > range.end) return false\n if (cursor) cursor.offset = end\n if (validWholeWordMatch(window.text, match.index, match[0].length, query.wholeWord)) {\n if (!visit(start, end, captureMatches ? match : null)) return false\n }\n\n if (match[0].length === 0) advancePastEmptyMatch(query.regex, window.text)\n }\n}\n\nfunction advancePastEmptyMatch(regex: RegExp, text: string): void {\n const current = regex.lastIndex\n if (current > text.length) return\n\n const size = codePointSizeAt(text, current)\n regex.lastIndex = current + Math.max(1, size)\n}\n\nfunction validWholeWordMatch(\n text: string,\n start: number,\n length: number,\n wholeWord: boolean,\n): boolean {\n if (!wholeWord) return true\n return isWholeWordRange(text, { start, end: start + length })\n}\n"],"mappings":";;AAUA,IAAa,qBAAqB;AAMlC,IAAa,yBAAyB;AAKtC,IAAa,oBAAoB;AAKjC,IAAM,oCAAoB,IAAI,IAAI;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAG,C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KAAK,iBAAiB,QAAQ,IAAI,GAAG,OAAO;EAAA;EAGhE,IAAI,MAAM,EAAE,CAAC,WAAW,GAAG,sBAAsB,MAAM,OAAO,OAAO,IAAI;CAC3E;AACF;AAEA,SAAS,sBAAsB,OAAe,MAAoB;CAChE,MAAM,UAAU,MAAM;CACtB,IAAI,UAAU,KAAK,QAAQ;CAE3B,MAAM,OAAO,gBAAgB,MAAM,OAAO;CAC1C,MAAM,YAAY,UAAU,KAAK,IAAI,GAAG,IAAI;AAC9C;AAEA,SAAS,oBACP,MACA,OACA,QACA,WACS;CACT,IAAI,CAAC,WAAW,OAAO;CACvB,OAAO,iBAAiB,MAAM;EAAE;EAAO,KAAK,QAAQ;CAAO,CAAC;AAC9D"}
|
|
1
|
+
{"version":3,"file":"search.js","names":[],"sources":["../src/search.ts"],"sourcesContent":["import {\n codePointSizeAt,\n compareTextOffsetRanges,\n isWholeWordRange,\n type TextOffsetRange,\n type TextReadSnapshot,\n} from '@singapore-editor/core/document'\n\n// Bounds the match set the widget counts and paints, so a pathological query\n// on a huge file cannot stall the frame.\nexport const FIND_MATCHES_LIMIT = 19_999\n\n// Replace All must never apply to a truncated match set: stopping early would\n// silently rewrite part of the document and leave the rest, with no signal to\n// the user. Searching is linear, so the only real cost of lifting the cap here\n// is the edit batch itself.\nexport const FIND_REPLACE_ALL_LIMIT = 1_073_741_824\n\n// How much text a windowed scan reads at once, rounded up to whole lines. Large\n// enough that the tree descent per read is noise, small enough that a fragmented\n// document is never joined into one string the size of the file.\nexport const FIND_WINDOW_UNITS = 65_536\n\n// Escapes whose class cannot hold a line break, so a pattern built only from\n// these can be answered a line at a time. A carriage return is among them: it\n// sits inside a line, not between two.\nconst LINE_SAFE_ESCAPES = new Set(['d', 'w', 't', 'r', 'f', 'v', 'b', 'B', '0'])\n\nexport type FindRange = TextOffsetRange\n\n// Read-only line-start access, structurally the view a document snapshot\n// already hands out, so a search never asks for the array behind it.\nexport type FindLineStartsView = {\n readonly length: number\n at(index: number): number | undefined\n indexForOffset(offset: number): number\n}\n\n/**\n * The text a search reads, in ranges rather than as one string.\n *\n * A query that cannot match a line break is answered a line at a time, so a\n * keystroke in the find box costs the lines examined instead of a copy of the\n * whole document — and a chunked buffer gets searched where it lies.\n */\nexport type FindTextSource = {\n readonly length: number\n readRange(start: number, end: number): string\n readonly lineStartsView: FindLineStartsView\n}\n\nexport function findTextSourceFromSnapshot(snapshot: TextReadSnapshot): FindTextSource {\n return {\n length: snapshot.length,\n readRange: (start, end) => snapshot.readRange(start, end),\n lineStartsView: {\n length: snapshot.lineCount,\n at: (index) =>\n index < 0 || index >= snapshot.lineCount ? undefined : snapshot.lineStart(index),\n indexForOffset: (offset) => snapshot.lineAt(offset),\n },\n }\n}\n\nexport type FindQuery = {\n readonly searchString: string\n readonly isRegex: boolean\n readonly matchCase: boolean\n readonly wholeWord: boolean\n}\n\nexport type FindMatch = FindRange & {\n readonly matches: readonly string[] | null\n}\n\nexport type FindMatchFromOptions = {\n readonly captureMatches?: boolean\n readonly loop?: boolean\n readonly escapeEmptyMatchAtOffset?: boolean\n}\n\n/** What the two directions have in common, so one caller can hold either. */\nexport type FindMatchFromSearcher = (\n source: FindTextSource,\n query: FindQuery,\n offset: number,\n ranges: readonly FindRange[] | null,\n options: FindMatchFromOptions,\n) => FindMatch | null\n\ntype CompiledFindQuery = {\n readonly regex: RegExp\n // Non-null only when a plain indexOf over the untouched text is exactly\n // equivalent to the regex; see compileFindQuery.\n readonly simpleSearch: string | null\n readonly wholeWord: boolean\n readonly plan: FindQueryPlan\n}\n\n/**\n * How much text one match can depend on, which is what decides how it is read.\n *\n * `lines` and `anchored-lines` cannot match a break, so they are read in windows\n * of whole lines. `literal-lines` is a literal holding breaks: it spans a known\n * number of lines, so it is windowed too. `range` is every pattern nothing here\n * can bound, read as one window because that is the only reading always correct.\n */\nexport type FindQueryPlan =\n | { readonly kind: 'lines' }\n | { readonly kind: 'anchored-lines' }\n | { readonly kind: 'literal-lines'; readonly lineBreaks: number }\n | { readonly kind: 'range'; readonly reason: 'pattern-may-match-line-break' }\n\n// One stretch of the document already read: the text of\n// `[start, start + text.length)`, to be searched from `from` onward.\ntype FindWindow = {\n readonly text: string\n readonly start: number\n readonly from: number\n}\n\nexport function findMatches(\n source: FindTextSource,\n query: FindQuery,\n ranges: readonly FindRange[] | null = null,\n captureMatches = false,\n limit = FIND_MATCHES_LIMIT,\n): readonly FindMatch[] {\n const compiled = compileFindQuery(query)\n if (!compiled || limit <= 0) return []\n\n const matches: FindMatch[] = []\n const collect: FindMatchVisitor = (start, end, captures) => {\n matches.push({ start, end, matches: captures })\n return matches.length < limit\n }\n for (const range of searchRanges(source, ranges)) {\n scanRange(source, compiled, range, captureMatches, collect)\n if (matches.length >= limit) break\n }\n\n return matches\n}\n\n/**\n * Every match counted, none kept: a total costs no record per match.\n *\n * With `before`, only the matches starting in front of that offset, which is the\n * position of a match the listing stopped short of.\n */\nexport function countMatches(\n source: FindTextSource,\n query: FindQuery,\n ranges: readonly FindRange[] | null = null,\n before = Number.POSITIVE_INFINITY,\n): number {\n const compiled = compileFindQuery(query)\n if (!compiled) return 0\n\n let count = 0\n const tally: FindMatchVisitor = (start) => {\n if (start >= before) return false\n\n count += 1\n return true\n }\n for (const range of searchRanges(source, ranges)) {\n if (range.start >= before) break\n scanRange(source, compiled, range, false, tally)\n }\n\n return count\n}\n\n/** Null for a query that cannot be compiled, which is one that finds nothing. */\nexport function findQueryPlan(query: FindQuery): FindQueryPlan | null {\n return compileFindQuery(query)?.plan ?? null\n}\n\n/** The line holding `offset`, break excluded. */\nexport function findLineRange(source: FindTextSource, offset: number): FindRange {\n const index = source.lineStartsView.indexForOffset(offset)\n return { start: source.lineStartsView.at(index) ?? 0, end: lineEndAt(source, index) }\n}\n\n/**\n * One match, scanned for from an offset instead of picked out of a list.\n *\n * A listing stops at FIND_MATCHES_LIMIT, and past that every entry in it sits\n * behind the cursor: picking from it answers each press with the top of the\n * document. Scanning outward stops at the first match it reaches, so how far\n * navigation can go is not what a paint budget allowed.\n */\nexport function findNextMatchFrom(\n source: FindTextSource,\n query: FindQuery,\n offset: number,\n ranges: readonly FindRange[] | null = null,\n options: FindMatchFromOptions = {},\n): FindMatch | null {\n const compiled = compileFindQuery(query)\n if (!compiled) return null\n\n const searched = searchRanges(source, ranges)\n const from = clampSourceOffset(source, offset)\n const ahead = firstMatchAfter(source, compiled, searched, from, options)\n if (ahead) return ahead\n if (options.loop === false) return null\n\n // Wrapping is a second bounded scan rather than a listing, so a cursor past\n // the last match still costs only the text up to the first one.\n return firstMatchAtOrAfter(source, compiled, searched, searched[0]?.start ?? 0, options)\n}\n\nexport function findPreviousMatchFrom(\n source: FindTextSource,\n query: FindQuery,\n offset: number,\n ranges: readonly FindRange[] | null = null,\n options: FindMatchFromOptions = {},\n): FindMatch | null {\n const compiled = compileFindQuery(query)\n if (!compiled) return null\n\n const searched = searchRanges(source, ranges)\n const from = clampSourceOffset(source, offset)\n const behind = lastMatchBefore(source, compiled, searched, from, options)\n if (behind) return behind\n if (options.loop === false) return null\n\n return lastMatchBefore(source, compiled, searched, source.length, {\n ...options,\n escapeEmptyMatchAtOffset: false,\n })\n}\n\nexport function findMatchIndex(matches: readonly FindMatch[], range: FindRange): number {\n return matches.findIndex((match) => match.start === range.start && match.end === range.end)\n}\n\nexport function escapeRegExpCharacters(value: string): string {\n return value.replace(/[\\\\{}*+?|^$.[\\]()]/g, '\\\\$&')\n}\n\n// The break belongs to no line: a query that cannot match one would otherwise be\n// handed a haystack whose `$` sits behind it.\nfunction lineEndAt(source: FindTextSource, index: number): number {\n const nextLineStart = source.lineStartsView.at(index + 1)\n return nextLineStart === undefined ? source.length : nextLineStart - 1\n}\n\nfunction escapesEmptyMatch(match: FindMatch, offset: number, escape: boolean): boolean {\n return escape && match.start === match.end && match.start === offset\n}\n\nfunction firstMatchAfter(\n source: FindTextSource,\n query: CompiledFindQuery,\n ranges: readonly FindRange[],\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n const found = firstMatchAtOrAfter(source, query, ranges, offset, options)\n if (!found) return null\n if (!escapesEmptyMatch(found, offset, options.escapeEmptyMatchAtOffset ?? false)) return found\n\n // Resumed past the offset itself, once: whatever stands there is the entry\n // after the one being escaped, empty or not.\n return firstMatchAtOrAfter(source, query, ranges, nextCodePointOffset(source, offset), options)\n}\n\nfunction firstMatchAtOrAfter(\n source: FindTextSource,\n query: CompiledFindQuery,\n ranges: readonly FindRange[],\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n for (const range of ranges) {\n if (range.end < offset) continue\n\n const found = firstMatchInRange(source, query, range, offset, options.captureMatches ?? false)\n if (found) return found\n }\n\n return null\n}\n\n// The range is never cut at the offset: a pattern resumed there simply begins a\n// fresh match at the cursor — 'pha' inside 'alpha' for `\\w+` — and a range no\n// listing of the document holds is one the reader was never shown and Replace\n// must never rewrite. What the offset decides is which matches are kept, not\n// where the scan starts. Uncapped, because what stands at the cursor is being\n// asked for regardless of where the paint budget ran out.\nfunction firstMatchInRange(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n offset: number,\n captureMatches: boolean,\n): FindMatch | null {\n let found: FindMatch | null = null\n const scanned = { start: forwardScanStart(source, query, range, offset), end: range.end }\n scanRange(source, query, scanned, captureMatches, (start, end, captures) => {\n if (start < offset) return true\n\n found = { start, end, matches: captures }\n return false\n })\n\n return found\n}\n\n// Lines in front of the cursor are skipped rather than searched: a match that\n// cannot hold a break cannot reach out of the line it starts on, so none of them\n// could answer at or after the offset anyway.\nfunction forwardScanStart(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n offset: number,\n): number {\n if (!isLineLocalPlan(query.plan)) return range.start\n\n const lineStartsView = source.lineStartsView\n const line = lineStartsView.indexForOffset(Math.max(range.start, offset))\n return Math.max(range.start, lineStartsView.at(line) ?? 0)\n}\n\nfunction isLineLocalPlan(plan: FindQueryPlan): boolean {\n return plan.kind === 'lines' || plan.kind === 'anchored-lines'\n}\n\nfunction lastMatchBefore(\n source: FindTextSource,\n query: CompiledFindQuery,\n ranges: readonly FindRange[],\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n for (const range of ranges.toReversed()) {\n if (range.start > offset) continue\n\n const found = lastMatchInRange(source, query, range, offset, options)\n if (found) return found\n }\n\n return null\n}\n\n// Walked back a window at a time, because the match before the cursor is the one\n// being asked for and listing everything behind it to reach the last entry is\n// the whole document on a search that started near its end.\nfunction lastMatchInRange(\n source: FindTextSource,\n query: CompiledFindQuery,\n searched: FindRange,\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n // A pattern that can run past a break is shown the text behind the cursor too:\n // cut at the cursor's line, `[^a]+$` would end there on a match no listing of\n // the document holds. The scan still stops at the first match past the cursor.\n if (!isLineLocalPlan(query.plan))\n return lastMatchInWindow(source, query, searched, offset, options)\n\n const range = { start: searched.start, end: Math.min(searched.end, offset) }\n const lineStartsView = source.lineStartsView\n let last = lineStartsView.indexForOffset(range.end)\n while (last >= 0) {\n const reach = Math.max(range.start, (lineStartsView.at(last) ?? 0) - FIND_WINDOW_UNITS)\n const first = lineStartsView.indexForOffset(reach)\n const firstStart = lineStartsView.at(first) ?? 0\n const window = {\n start: Math.max(range.start, firstStart),\n end: Math.min(range.end, lineEndAt(source, last)),\n }\n const found =\n window.end < window.start ? null : lastMatchInWindow(source, query, window, offset, options)\n if (found) return found\n if (firstStart <= range.start) return null\n\n last = first - 1\n }\n\n return null\n}\n\n// The last match in one window, escaping the same way stepping an ordered list\n// does: what stands before a zero-width match parked on the cursor is the entry\n// the search is being asked for, and it may be in an earlier window. Uncapped,\n// and only the last two are kept: a listing that stopped at the paint cap would\n// answer every press behind the cursor with the 19,999th match.\nfunction lastMatchInWindow(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n offset: number,\n options: FindMatchFromOptions,\n): FindMatch | null {\n let last: FindMatch | null = null\n let beforeLast: FindMatch | null = null\n scanRange(source, query, range, options.captureMatches ?? false, (start, end, captures) => {\n if (end > offset) return false\n\n beforeLast = last\n last = { start, end, matches: captures }\n return true\n })\n if (!last) return null\n if (!escapesEmptyMatch(last, offset, options.escapeEmptyMatchAtOffset ?? false)) return last\n\n return beforeLast\n}\n\n// A pattern compiled with the unicode flag may not be resumed inside a surrogate\n// pair, so stepping off an empty match steps a code point rather than a unit.\nfunction nextCodePointOffset(source: FindTextSource, offset: number): number {\n const text = source.readRange(offset, Math.min(source.length, offset + 2))\n return offset + Math.max(1, codePointSizeAt(text, 0))\n}\n\n// True when the query contains at least one character whose case can differ,\n// which is the only situation where matchCase changes what a plain search\n// finds. Digits, punctuation and CJK are caseless, so an untouched indexOf is\n// still exact for them even with matchCase off.\nfunction queryIsCaseSensitiveByContent(searchString: string): boolean {\n return searchString.toLowerCase() !== searchString.toUpperCase()\n}\n\n/**\n * Whether every part of a pattern is provably unable to match a line break.\n *\n * Asked the safe way round. Listing the constructs that CAN hold a break means\n * one nobody thought of routes a query to the windowed path, where it answers\n * \"no results\" for text that is plainly there — the one wrong answer a search\n * must never give. So a query is windowed only when every part of it is provably\n * break-free, and anything unrecognized takes the slower path that is always\n * correct.\n */\nfunction isLineSafePattern(pattern: string): boolean {\n for (let index = 0; index < pattern.length; index += 1) {\n const char = pattern[index]\n if (char === '\\n') return false\n if (char === '[') {\n const end = characterClassEnd(pattern, index)\n if (end === null || !isLineSafeCharacterClass(pattern.slice(index + 1, end))) return false\n\n index = end\n continue\n }\n\n if (char === '(' && !isLineSafeGroupOpener(pattern, index)) return false\n if (char !== '\\\\') continue\n\n index += 1\n const escaped = pattern[index]\n if (escaped === undefined) return false\n // A hex or unicode escape can spell the break itself, and reading which one\n // it spells is more machinery than routing it to the correct path costs.\n if (!LINE_SAFE_ESCAPES.has(escaped) && /[\\p{L}\\p{N}]/u.test(escaped)) return false\n }\n\n return true\n}\n\n/**\n * Only a group that bundles what is written inside it, leaving its meaning alone.\n *\n * A capture, a non-capture and either lookaround are all of those. A modifier\n * group is not: it can switch on the flag under which a dot spans a break, so the\n * characters inside it stop saying what they say anywhere else — and reading back\n * which flags one names is more machinery than routing it to the correct path\n * costs. Every other spelling is one nobody here recognized, which is the same\n * answer.\n */\nfunction isLineSafeGroupOpener(pattern: string, index: number): boolean {\n if (pattern[index + 1] !== '?') return true\n\n const kind = pattern[index + 2]\n // '<' opens a lookbehind or names a capture, and neither changes what matches.\n return kind === ':' || kind === '=' || kind === '!' || kind === '<'\n}\n\n// Only a positive class naming its members outright: a negated one holds a break\n// unless it names it, and an escape inside one can bring a whole class with it.\nfunction isLineSafeCharacterClass(body: string): boolean {\n if (body.startsWith('^')) return false\n return !body.includes('\\\\') && !body.includes('\\n')\n}\n\nfunction characterClassEnd(pattern: string, from: number): number | null {\n for (let index = from + 1; index < pattern.length; index += 1) {\n if (pattern[index] === '\\\\') index += 1\n else if (pattern[index] === ']') return index\n }\n\n return null\n}\n\nfunction compileFindQuery(query: FindQuery): CompiledFindQuery | null {\n if (query.searchString.length === 0) return null\n\n const source = query.isRegex ? query.searchString : escapeRegExpCharacters(query.searchString)\n const plan = planFindQuery(query)\n const lineCrossing = plan.kind === 'range' || plan.kind === 'literal-lines'\n // Flags describe the haystack, and only a line-crossing search is ever handed\n // one holding a break: a per-line slice bounds `^` and `$` by itself, so `m`\n // there would only claim breaks the slice does not contain.\n const flags = `g${query.matchCase ? '' : 'i'}${lineCrossing ? 'm' : ''}`\n\n // The fast path may never case-fold the haystack: folding is not\n // length-preserving (U+0130 'İ' lowercases to two code units), so an index\n // into folded text does not address the original text, and a match reported\n // from it slices the wrong characters — Replace would then overwrite them.\n // Fall back to the case-insensitive regex, which reports original indices.\n const canUseSimpleSearch =\n !query.isRegex && (query.matchCase || !queryIsCaseSensitiveByContent(query.searchString))\n\n const regex = compileRegex(source, flags)\n if (!regex) return null\n\n return {\n regex,\n simpleSearch: canUseSimpleSearch ? query.searchString : null,\n wholeWord: query.wholeWord,\n plan,\n }\n}\n\nfunction planFindQuery(query: FindQuery): FindQueryPlan {\n if (!query.isRegex) {\n const lineBreaks = query.searchString.split('\\n').length - 1\n return lineBreaks === 0 ? { kind: 'lines' } : { kind: 'literal-lines', lineBreaks }\n }\n\n if (!isLineSafePattern(query.searchString))\n return { kind: 'range', reason: 'pattern-may-match-line-break' }\n return hasLineAnchor(query.searchString) ? { kind: 'anchored-lines' } : { kind: 'lines' }\n}\n\n// Asked of a pattern already known to be line-safe, so a class cannot be negated\n// and a `^` inside one is a member rather than an anchor.\nfunction hasLineAnchor(pattern: string): boolean {\n for (let index = 0; index < pattern.length; index += 1) {\n const char = pattern[index]\n if (char === '\\\\') index += 1\n else if (char === '[') index = characterClassEnd(pattern, index) ?? pattern.length\n else if (char === '^' || char === '$') return true\n }\n\n return false\n}\n\n/**\n * The pattern under the unicode flag where it takes it, and without it where it\n * does not.\n *\n * Wanted, because `u` is what makes a surrogate pair one character to a dot and\n * `\\p{...}` mean anything at all. Not required, because its grammar rejects\n * spellings the flagless one accepts — an identity escape of a character that\n * needs none (`\\-`, `\\ `), a brace or bracket standing for itself, a legacy\n * back-reference — and every one of those is what escaping a search by hand\n * produces. A rejected pattern is not reported anywhere the user can see it: it\n * reaches them as \"No results\", indistinguishable from text that is not there.\n */\nfunction compileRegex(source: string, flags: string): RegExp | null {\n try {\n return new RegExp(source, `${flags}u`)\n } catch {\n // Ignored: whether the pattern is invalid outright or only invalid under the\n // stricter grammar is what the second construction answers.\n }\n\n try {\n return new RegExp(source, flags)\n } catch {\n return null\n }\n}\n\nfunction searchRanges(\n source: FindTextSource,\n ranges: readonly FindRange[] | null,\n): readonly FindRange[] {\n if (!ranges || ranges.length === 0) return [{ start: 0, end: source.length }]\n\n const clamped = ranges\n .map((range) => ({\n start: clampSourceOffset(source, range.start),\n end: clampSourceOffset(source, range.end),\n }))\n .filter((range) => range.start <= range.end)\n .sort(compareTextOffsetRanges)\n\n // Scopes are followed through edits, and an edit spanning the seam between two\n // of them leaves them overlapping. Searching both would report the text they\n // share twice, which a Replace All then tries to rewrite twice.\n const merged: FindRange[] = []\n for (const range of clamped) {\n const previous = merged.at(-1)\n if (previous && range.start <= previous.end) {\n merged[merged.length - 1] = { start: previous.start, end: Math.max(previous.end, range.end) }\n continue\n }\n\n merged.push(range)\n }\n\n return merged\n}\n\nfunction clampSourceOffset(source: FindTextSource, offset: number): number {\n return Math.min(Math.max(0, offset), source.length)\n}\n\n// Visited in document order; false stops the scan where it stands.\ntype FindMatchVisitor = (start: number, end: number, captures: RegExpExecArray | null) => boolean\n\n/** False once the range is spent or the visitor stopped: nothing later in it is read. */\nfunction scanRange(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n): boolean {\n if (query.plan.kind === 'range')\n return scanWholeRange(source, query, range, captureMatches, visit)\n if (query.plan.kind === 'literal-lines')\n return scanSpanningLiteral(source, query, range, query.plan.lineBreaks, visit)\n\n return scanLines(source, query, range, captureMatches, visit)\n}\n\n// Whole lines, even where the range was cut inside one: the anchors and the word\n// boundaries have to answer for the line the reader sees rather than for where\n// the range happens to end, so the range only decides which matches are kept.\n//\n// Read many lines to a window. A match that cannot hold a break cannot leave its\n// line, and a break is no word character, so a pattern with no `^` or `$` finds in\n// the window exactly what it finds line by line, without a tree descent per line.\nfunction scanLines(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n): boolean {\n const lineStartsView = source.lineStartsView\n let index = lineStartsView.indexForOffset(range.start)\n while (index < lineStartsView.length) {\n const start = lineStartsView.at(index)\n if (start === undefined || start > range.end) return true\n\n const last = lastWindowLine(source, index, start, range.end)\n const window = readWindow(source, start, lineEndAt(source, last), range)\n if (!scanLineWindow(window, query, range, captureMatches, visit)) return false\n index = last + 1\n }\n\n return true\n}\n\nfunction lastWindowLine(\n source: FindTextSource,\n first: number,\n start: number,\n rangeEnd: number,\n): number {\n const reach = Math.min(rangeEnd, start + FIND_WINDOW_UNITS)\n return Math.max(first, source.lineStartsView.indexForOffset(reach))\n}\n\nfunction scanLineWindow(\n window: FindWindow,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n): boolean {\n if (query.plan.kind !== 'anchored-lines')\n return scanWindow(window, query, range, captureMatches, visit)\n\n // `^` and `$` answer for the ends of the haystack, so each line is its own.\n let lineStart = 0\n while (lineStart <= window.text.length) {\n const found = window.text.indexOf('\\n', lineStart)\n const lineEnd = found === -1 ? window.text.length : found\n const line = {\n text: window.text.slice(lineStart, lineEnd),\n start: window.start + lineStart,\n from: Math.max(0, window.from - lineStart),\n }\n if (lineEnd >= window.from && !scanWindow(line, query, range, captureMatches, visit))\n return false\n\n lineStart = lineEnd + 1\n }\n\n return true\n}\n\n// A literal holding breaks spans exactly that many lines past the one it starts\n// on, so windows overlapping by that many lines show every match whole to at\n// least one of them. The cursor is carried across: restarting the greedy scan at\n// an overlap's first character would change which of two overlapping candidates\n// wins, and with it every match after them.\nfunction scanSpanningLiteral(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n lineBreaks: number,\n visit: FindMatchVisitor,\n): boolean {\n const lineStartsView = source.lineStartsView\n const finalLine = lineStartsView.indexForOffset(range.end)\n let first = lineStartsView.indexForOffset(range.start)\n const cursor = { offset: range.start }\n while (first <= finalLine) {\n const start = lineStartsView.at(first) ?? 0\n const last = Math.min(\n finalLine,\n Math.max(first + lineBreaks, lastWindowLine(source, first, start, range.end)),\n )\n const text = source.readRange(start, Math.max(start, lineEndAt(source, last)))\n const window = { text, start, from: Math.max(0, cursor.offset - start) }\n if (!scanWindow(window, query, range, false, visit, cursor)) return false\n if (last === finalLine) return true\n\n first = last + 1 - lineBreaks\n }\n\n return true\n}\n\n// Listing every match of a pattern that can span the range's ends has to look at\n// every character between them, so the range is read as one window: a window\n// grown in steps would only re-run the pattern over text it already scanned. The\n// window still stops on line boundaries, or `^` and `$` would answer for its cut\n// ends instead of for real ones.\nfunction scanWholeRange(\n source: FindTextSource,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n): boolean {\n const lineStartsView = source.lineStartsView\n const start = lineStartsView.at(lineStartsView.indexForOffset(range.start)) ?? 0\n const end = lineEndAt(source, lineStartsView.indexForOffset(range.end))\n const window = readWindow(source, start, Math.max(start, end), range)\n return scanWindow(window, query, range, captureMatches, visit)\n}\n\nfunction readWindow(\n source: FindTextSource,\n start: number,\n end: number,\n range: FindRange,\n): FindWindow {\n return { text: source.readRange(start, end), start, from: Math.max(0, range.start - start) }\n}\n\n// Where the next raw match may begin. It moves past every raw match, including\n// one the whole-word filter rejects, so the scan keeps one non-overlap phase.\ntype FindCursor = { offset: number }\n\n/** False once the range is spent or the visitor stopped, so no later window can add anything. */\nfunction scanWindow(\n window: FindWindow,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n cursor?: FindCursor,\n): boolean {\n if (query.simpleSearch && !captureMatches)\n return scanSimpleMatches(window, query.simpleSearch, query.wholeWord, range, visit, cursor)\n\n return scanRegexMatches(window, query, range, captureMatches, visit, cursor)\n}\n\nfunction scanSimpleMatches(\n window: FindWindow,\n searchString: string,\n wholeWord: boolean,\n range: FindRange,\n visit: FindMatchVisitor,\n cursor?: FindCursor,\n): boolean {\n // Searched as-is: no folded copy of the text is allocated, and every index\n // returned addresses the window it came from.\n let index = window.text.indexOf(searchString, window.from)\n while (index !== -1) {\n const start = window.start + index\n const end = start + searchString.length\n if (end > range.end) return false\n if (cursor) cursor.offset = end\n if (validWholeWordMatch(window.text, index, searchString.length, wholeWord)) {\n if (!visit(start, end, null)) return false\n }\n\n index = window.text.indexOf(searchString, index + searchString.length)\n }\n\n return true\n}\n\nfunction scanRegexMatches(\n window: FindWindow,\n query: CompiledFindQuery,\n range: FindRange,\n captureMatches: boolean,\n visit: FindMatchVisitor,\n cursor?: FindCursor,\n): boolean {\n query.regex.lastIndex = window.from\n while (true) {\n const match = query.regex.exec(window.text)\n if (!match) return true\n\n const start = window.start + match.index\n const end = start + match[0].length\n if (start > range.end || end > range.end) return false\n if (cursor) cursor.offset = end\n if (validWholeWordMatch(window.text, match.index, match[0].length, query.wholeWord)) {\n if (!visit(start, end, captureMatches ? match : null)) return false\n }\n\n if (match[0].length === 0) advancePastEmptyMatch(query.regex, window.text)\n }\n}\n\nfunction advancePastEmptyMatch(regex: RegExp, text: string): void {\n const current = regex.lastIndex\n if (current > text.length) return\n\n const size = codePointSizeAt(text, current)\n regex.lastIndex = current + Math.max(1, size)\n}\n\nfunction validWholeWordMatch(\n text: string,\n start: number,\n length: number,\n wholeWord: boolean,\n): boolean {\n if (!wholeWord) return true\n return isWholeWordRange(text, { start, end: start + length })\n}\n"],"mappings":";;AAUA,IAAa,qBAAqB;AAMlC,IAAa,yBAAyB;AAKtC,IAAa,oBAAoB;AAKjC,IAAM,oCAAoB,IAAI,IAAI;CAAC;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAG,CAAC;AAyB/E,SAAgB,2BAA2B,UAA4C;CACrF,OAAO;EACL,QAAQ,SAAS;EACjB,YAAY,OAAO,QAAQ,SAAS,UAAU,OAAO,GAAG;EACxD,gBAAgB;GACd,QAAQ,SAAS;GACjB,KAAK,UACH,QAAQ,KAAK,SAAS,SAAS,YAAY,KAAA,IAAY,SAAS,UAAU,KAAK;GACjF,iBAAiB,WAAW,SAAS,OAAO,MAAM;EACpD;CACF;AACF;AA2DA,SAAgB,YACd,QACA,OACA,SAAsC,MACtC,iBAAiB,OACjB,QAAQ,oBACc;CACtB,MAAM,WAAW,iBAAiB,KAAK;CACvC,IAAI,CAAC,YAAY,SAAS,GAAG,OAAO,CAAC;CAErC,MAAM,UAAuB,CAAC;CAC9B,MAAM,WAA6B,OAAO,KAAK,aAAa;EAC1D,QAAQ,KAAK;GAAE;GAAO;GAAK,SAAS;EAAS,CAAC;EAC9C,OAAO,QAAQ,SAAS;CAC1B;CACA,KAAK,MAAM,SAAS,aAAa,QAAQ,MAAM,GAAG;EAChD,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A,CAAC,MAAM,OAAO,KAAK,IAAI,GAAG,OAAO;EAAA;EAGvC,QAAQ,OAAO,KAAK,QAAQ,cAAc,QAAQ,aAAa,MAAM;CACvE;CAEA,OAAO;AACT;AAEA,SAAS,iBACP,QACA,OACA,OACA,gBACA,OACA,QACS;CACT,MAAM,MAAM,YAAY,OAAO;CAC/B,OAAO,MAAM;EACX,MAAM,QAAQ,MAAM,MAAM,KAAK,OAAO,IAAI;EAC1C,IAAI,CAAC,OAAO,OAAO;EAEnB,MAAM,QAAQ,OAAO,QAAQ,MAAM;EACnC,MAAM,MAAM,QAAQ,MAAM,EAAE,CAAC;EAC7B,IAAI,QAAQ,MAAM,OAAO,MAAM,MAAM,KAAK,OAAO;EACjD,IAAI,QAAQ,OAAO,SAAS;EAC5B,IAAI,oBAAoB,OAAO,MAAM,MAAM,OAAO,MAAM,EAAE,CAAC,QAAQ,MAAM,SAAS,GAC5E;OAAA,CAAC,MAAM,OAAO,KAAK,iBAAiB,QAAQ,IAAI,GAAG,OAAO;EAAA;EAGhE,IAAI,MAAM,EAAE,CAAC,WAAW,GAAG,sBAAsB,MAAM,OAAO,OAAO,IAAI;CAC3E;AACF;AAEA,SAAS,sBAAsB,OAAe,MAAoB;CAChE,MAAM,UAAU,MAAM;CACtB,IAAI,UAAU,KAAK,QAAQ;CAE3B,MAAM,OAAO,gBAAgB,MAAM,OAAO;CAC1C,MAAM,YAAY,UAAU,KAAK,IAAI,GAAG,IAAI;AAC9C;AAEA,SAAS,oBACP,MACA,OACA,QACA,WACS;CACT,IAAI,CAAC,WAAW,OAAO;CACvB,OAAO,iBAAiB,MAAM;EAAE;EAAO,KAAK,QAAQ;CAAO,CAAC;AAC9D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@singapore-editor/find",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.11",
|
|
4
|
+
"description": "Find and replace with regular expressions and case-preserving replacements for the Singapore editor.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"browser",
|
|
7
|
+
"editor",
|
|
8
|
+
"replace",
|
|
9
|
+
"search",
|
|
10
|
+
"singapore",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://singapore.shaulavo.dev/docs/reference/api/find/overview/",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/ShaulLavo/singapore/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/ShaulLavo/singapore.git"
|
|
21
|
+
},
|
|
4
22
|
"files": [
|
|
5
23
|
"README.md",
|
|
6
24
|
"dist"
|
|
@@ -19,6 +37,7 @@
|
|
|
19
37
|
},
|
|
20
38
|
"publishConfig": {
|
|
21
39
|
"access": "public",
|
|
40
|
+
"provenance": true,
|
|
22
41
|
"registry": "https://registry.npmjs.org/"
|
|
23
42
|
},
|
|
24
43
|
"scripts": {
|
|
@@ -26,23 +45,22 @@
|
|
|
26
45
|
"test": "vitest run",
|
|
27
46
|
"bench:search": "bun bench/search.ts",
|
|
28
47
|
"bench:matchers": "bun bench/matchers.ts",
|
|
29
|
-
"typecheck": "
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
30
49
|
"lint": "oxlint .",
|
|
31
50
|
"format": "oxfmt --write .",
|
|
32
51
|
"format:check": "oxfmt --check ."
|
|
33
52
|
},
|
|
34
53
|
"devDependencies": {
|
|
35
54
|
"@playwright/test": "^1.63.0",
|
|
36
|
-
"@singapore-editor/core": "0.
|
|
37
|
-
"@
|
|
38
|
-
"@vitest/browser-playwright": "^5.0.2",
|
|
55
|
+
"@singapore-editor/core": "0.2.11",
|
|
56
|
+
"@vitest/browser-playwright": "5.0.2",
|
|
39
57
|
"happy-dom": "^20.14.5",
|
|
40
58
|
"oxfmt": "0.70.0",
|
|
41
59
|
"oxlint": "1.85.0",
|
|
42
|
-
"typescript": "
|
|
43
|
-
"vitest": "
|
|
60
|
+
"typescript": "7.0.2",
|
|
61
|
+
"vitest": "5.0.2"
|
|
44
62
|
},
|
|
45
63
|
"peerDependencies": {
|
|
46
|
-
"@singapore-editor/core": "0.
|
|
64
|
+
"@singapore-editor/core": "0.2.11"
|
|
47
65
|
}
|
|
48
66
|
}
|