@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/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shaul Lavo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @singapore-editor/find
|
|
2
2
|
|
|
3
|
-
Find and replace
|
|
3
|
+
Find and replace with regular expressions and case-preserving replacements for the Singapore editor.
|
|
4
|
+
|
|
5
|
+
Part of [Singapore](https://singapore.shaulavo.dev/). A code editor for the browser that keeps every version.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
@@ -13,16 +15,31 @@ npm install @singapore-editor/core @singapore-editor/find
|
|
|
13
15
|
```ts
|
|
14
16
|
import { Editor } from '@singapore-editor/core/editor'
|
|
15
17
|
import { createEditorFindPlugin } from '@singapore-editor/find'
|
|
16
|
-
import '@singapore-editor/core/style.css'
|
|
17
|
-
import '@singapore-editor/find/style.css'
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const host = document.createElement('div')
|
|
20
|
+
host.style.height = '400px'
|
|
21
|
+
document.body.append(host)
|
|
22
|
+
|
|
23
|
+
const editor = new Editor(host, {
|
|
20
24
|
plugins: [createEditorFindPlugin()],
|
|
21
25
|
})
|
|
26
|
+
editor.setText('const value = 1\n')
|
|
22
27
|
```
|
|
23
28
|
|
|
24
|
-
##
|
|
29
|
+
## API highlights
|
|
30
|
+
|
|
31
|
+
- `createEditorFindPlugin()` adds the search widget.
|
|
32
|
+
- `editor.openFind()` opens search from code.
|
|
33
|
+
- `editor.replaceAll()` applies the current replacement.
|
|
34
|
+
|
|
35
|
+
[Generated API reference](https://singapore.shaulavo.dev/docs/reference/api/find/overview/)
|
|
36
|
+
|
|
37
|
+
## In the Singapore family
|
|
38
|
+
|
|
39
|
+
`@singapore-editor/core` owns the editor view. Add this plugin for find and replace.
|
|
40
|
+
|
|
41
|
+
[Singapore README](https://github.com/ShaulLavo/singapore/blob/main/README.md) · [Documentation](https://singapore.shaulavo.dev/docs/start-here/introduction/)
|
|
42
|
+
|
|
43
|
+
## License
|
|
25
44
|
|
|
26
|
-
|
|
27
|
-
- `createEditorFindContributionProviders` exposes the find widget and capability providers.
|
|
28
|
-
- `EDITOR_FIND_FEATURE` and `EDITOR_FIND_FEATURE_ID` expose the find feature capability token.
|
|
45
|
+
MIT. [License](https://github.com/ShaulLavo/singapore/blob/main/LICENSE)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findController.d.ts","sourceRoot":"","sources":["../src/findController.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACtB,MAAM,iCAAiC,CAAA;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAA;AAC9E,OAAO,KAAK,EACV,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,gCAAgC,EACjC,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAA;AAErF,OAAO,EAcL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,UAAU,CAAA;AAEjB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAgBhD,eAAO,MAAM,sBAAsB
|
|
1
|
+
{"version":3,"file":"findController.d.ts","sourceRoot":"","sources":["../src/findController.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACtB,MAAM,iCAAiC,CAAA;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,+B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B;IAMzB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,mBAAmB;IAK3B,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,UAAU;IAclB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,6BAA6B;IAQrC,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,wBAAwB;IAiBhC,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,IAAI;CAGb"}
|
package/dist/findController.js
CHANGED
|
@@ -2,7 +2,7 @@ import { FIND_MATCHES_LIMIT, FIND_REPLACE_ALL_LIMIT, countMatches, escapeRegExpC
|
|
|
2
2
|
import { ReplacePattern, parseReplaceString } from "./replacePattern.js";
|
|
3
3
|
import { wordRangeAtOffset } from "@singapore-editor/core/document";
|
|
4
4
|
import { EditorSecondaryViewScheduler } from "@singapore-editor/core/secondary-views";
|
|
5
|
-
|
|
5
|
+
// src/findController.ts
|
|
6
6
|
var FIND_HIGHLIGHT_Z_INDEX = {
|
|
7
7
|
scope: 4,
|
|
8
8
|
match: 5,
|
|
@@ -643,12 +643,8 @@ function orderedMatchSelections(matches, currentSelection) {
|
|
|
643
643
|
head: currentSelection.headOffset,
|
|
644
644
|
affinity: currentSelection.affinity
|
|
645
645
|
};
|
|
646
|
-
if (currentIndex === 0) return [current
|
|
647
|
-
return [
|
|
648
|
-
current,
|
|
649
|
-
...selections.slice(0, currentIndex),
|
|
650
|
-
...selections.slice(currentIndex + 1)
|
|
651
|
-
];
|
|
646
|
+
if (currentIndex === 0) return [current].concat(selections.slice(1));
|
|
647
|
+
return [current].concat(selections.slice(0, currentIndex), selections.slice(currentIndex + 1));
|
|
652
648
|
}
|
|
653
649
|
function selectionForMatch(match) {
|
|
654
650
|
return {
|
|
@@ -658,7 +654,7 @@ function selectionForMatch(match) {
|
|
|
658
654
|
};
|
|
659
655
|
}
|
|
660
656
|
function mergeAdjacentReplaceEdits(edits) {
|
|
661
|
-
const sorted = edits.
|
|
657
|
+
const sorted = edits.sort((left, right) => left.from - right.from || left.to - right.to);
|
|
662
658
|
const merged = [];
|
|
663
659
|
for (const edit of sorted) mergeReplaceEdit(merged, edit);
|
|
664
660
|
return merged;
|
|
@@ -675,7 +671,6 @@ function mergeReplaceEdit(merged, edit) {
|
|
|
675
671
|
text: previous.text + edit.text
|
|
676
672
|
};
|
|
677
673
|
}
|
|
678
|
-
//#endregion
|
|
679
674
|
export { EditorFindController, FIND_HIGHLIGHT_Z_INDEX };
|
|
680
675
|
|
|
681
676
|
//# sourceMappingURL=findController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findController.js","names":[],"sources":["../src/findController.ts"],"sourcesContent":["import {\n wordRangeAtOffset,\n type TextEdit,\n type TextReadSnapshot,\n} from '@singapore-editor/core/document'\nimport type { EditorSetSelectionOptions } from '@singapore-editor/core/editor'\nimport type {\n EditorContributionChange,\n EditorDisposable,\n EditorResolvedSelection,\n EditorSelectionRange,\n EditorViewContributionUpdateKind,\n} from '@singapore-editor/core/extensions'\nimport type { VirtualizedTextHighlightStyle } from '@singapore-editor/core/rendering'\nimport { EditorSecondaryViewScheduler } from '@singapore-editor/core/secondary-views'\nimport {\n countMatches,\n escapeRegExpCharacters,\n FIND_MATCHES_LIMIT,\n FIND_REPLACE_ALL_LIMIT,\n findLineRange,\n findMatchIndex,\n findMatches,\n findNextMatchFrom,\n findPreviousMatchFrom,\n findTextSourceFromSnapshot,\n type FindMatch,\n type FindMatchFromOptions,\n type FindMatchFromSearcher,\n type FindQuery,\n type FindRange,\n type FindTextSource,\n} from './search'\nimport { parseReplaceString, ReplacePattern } from './replacePattern'\nimport type { EditorFindOptions } from './types'\n\n// These three overlap by construction — the current match is always also a\n// match, and both sit inside the scope — so their stacking is declared rather\n// than left to the order the groups happen to reach the highlight registry in.\n//\n// The numbers are exported because they are half of a cross-package agreement: the highlight\n// priority space is one namespace that several subsystems write into, and priority is what settles\n// a contest between two of them that declare the same property. A regression test elsewhere asserts\n// the resulting order, and it can only do that by reading these rather than by restating them.\n//\n// They sit above the error diagnostic, which declares a background of its own at 2. `current` is the\n// only find style that declares a `color`, so it is the only one contending on that axis — but all\n// three declare a background, and so does the error, which is why none of them may share its number.\n// A tie there would put the background contest back where the numbers exist to take it out of:\n// registration order in the document's shared registry.\nexport const FIND_HIGHLIGHT_Z_INDEX = {\n scope: 4,\n match: 5,\n current: 6,\n} as const\n\nconst FIND_MATCH_STYLE = {\n dimmable: false,\n backgroundColor: 'rgba(234, 179, 8, 0.34)',\n zIndex: FIND_HIGHLIGHT_Z_INDEX.match,\n}\nconst FIND_CURRENT_STYLE = {\n dimmable: false,\n backgroundColor: 'rgba(245, 158, 11, 0.72)',\n color: '#111827',\n zIndex: FIND_HIGHLIGHT_Z_INDEX.current,\n}\nconst FIND_SCOPE_STYLE = {\n dimmable: false,\n backgroundColor: 'rgba(59, 130, 246, 0.22)',\n zIndex: FIND_HIGHLIGHT_Z_INDEX.scope,\n}\n\n// A match on screen stays where the reader is looking at it; one that is not lands\n// in the middle, with context on both sides rather than on the viewport's edge.\nfunction findReveal(match: FindRange, committed = true): EditorSetSelectionOptions {\n return {\n ...(committed ? { jumpCause: 'find' as const } : {}),\n revealOffset: match.end,\n revealBlock: 'center-if-outside',\n }\n}\n\n// Seeding stops here rather than pushing a multi-megabyte selection through the\n// find input and searching for it.\nconst SEARCH_STRING_MAX_LENGTH = 524_288\n\n// A re-search reads the whole document, which is not a bill a keystroke can be\n// handed. The ceiling is the load-bearing half: a sustained typing run never\n// leaves the quiet gap, so waiting only for quiet would mean never re-searching\n// at all for as long as the user keeps going.\nconst FIND_RESEARCH_KEY = 'find.research'\nconst FIND_RESEARCH_DELAY_MS = 100\nconst FIND_RESEARCH_MAX_DELAY_MS = 400\n\ntype EditorFindSelectionRange = EditorSelectionRange\n\nexport type EditorFindResolvedSelection = EditorResolvedSelection & {\n readonly collapsed: boolean\n}\n\n/**\n * Ranges the host follows through edits on find's behalf.\n *\n * A scope outlives the selection it was taken from: the first replace inside it moves the caret off\n * that selection, so a scope re-derived from what is selected now would be re-derived from\n * something else — or from nothing, and a scope of nothing is indistinguishable from no scope at\n * all. Handed over once, it answers from wherever its text went, however many edits later.\n */\nexport type FindTrackedRanges = {\n resolve(): readonly FindRange[]\n}\n\nexport type EditorFindHost = {\n hasDocument(): boolean\n // Ranges rather than a string, so nothing find does can cost a copy of the\n // document — the reason there is no full-text accessor here to reach for.\n textSource(): FindTextSource\n hasTextSnapshot(snapshot: TextReadSnapshot): boolean\n // Followed wherever they end up, however far off screen: a scope decides where\n // Replace All rewrites, and one that stopped being followed would rewrite text\n // the user never marked.\n trackRanges(ranges: readonly FindRange[]): FindTrackedRanges\n // Followed only as far as the host paints them, the rest answered with the\n // offsets they were handed; see adoptMatches.\n trackPaintedRanges(ranges: readonly FindRange[]): FindTrackedRanges\n getSelections(): readonly EditorFindResolvedSelection[]\n focusEditor(): void\n announce(message: string): void\n setSelection(\n anchor: number,\n head: number,\n timingName: string,\n options?: EditorSetSelectionOptions,\n ): void\n setSelections(\n selections: readonly EditorFindSelectionRange[],\n timingName: string,\n revealOffset?: number,\n ): void\n setRangeHighlight(\n name: string,\n ranges: readonly FindRange[],\n style: VirtualizedTextHighlightStyle,\n ): void\n clearRangeHighlight(name: string): void\n}\n\nexport type EditorFindEditHost = {\n textSnapshot(): TextReadSnapshot | null\n getSelections(): readonly EditorFindResolvedSelection[]\n applyEdits(\n edits: readonly TextEdit[],\n timingName: string,\n selection?: EditorFindSelectionRange,\n ): void\n}\n\nexport type EditorFindStartOptions = {\n readonly replace: boolean\n readonly focus: 'find' | 'replace' | 'none'\n}\n\nexport type EditorFindState = FindQuery & {\n readonly replaceString: string\n readonly preserveCase: boolean\n readonly revealed: boolean\n readonly replaceRevealed: boolean\n readonly inSelection: boolean\n}\n\nexport type EditorFindWidgetState = EditorFindState & {\n // Every match in the searched text, however many of them are painted.\n readonly matchesCount: number\n readonly matchesPosition: number\n // Painting stopped at FIND_MATCHES_LIMIT. The count and navigation did not.\n readonly highlightsTruncated: boolean\n}\n\nexport type EditorFindUiEvent =\n | { readonly type: 'show'; readonly replaceVisible: boolean }\n | { readonly type: 'hide' }\n | { readonly type: 'focus'; readonly target: 'find' | 'replace' }\n | { readonly type: 'update'; readonly state: EditorFindWidgetState }\n\ntype ResolvedFindOptions = Required<EditorFindOptions>\ntype EditorFindUiListener = (event: EditorFindUiEvent) => void\n\n// What every search resolves to before it runs: the text, and the ranges of it\n// the query is allowed to answer from. Null scopes are the whole document; an\n// empty scope refuses the search outright, so it is never one of these.\ntype FindSearchTarget = {\n readonly source: FindTextSource\n readonly scopes: readonly FindRange[] | null\n}\n\nexport class EditorFindController {\n private readonly options: ResolvedFindOptions\n private readonly listeners = new Set<EditorFindUiListener>()\n private host: EditorFindHost | null = null\n private editHost: EditorFindEditHost | null = null\n private matchHighlightName = ''\n private currentHighlightName = ''\n private scopeHighlightName = ''\n private state: EditorFindState = {\n searchString: '',\n replaceString: '',\n isRegex: false,\n matchCase: false,\n wholeWord: false,\n preserveCase: false,\n revealed: false,\n replaceRevealed: false,\n inSelection: false,\n }\n private readonly scheduler = new EditorSecondaryViewScheduler()\n private matches: readonly FindMatch[] = []\n private highlightsTruncated = false\n // Counted rather than listed, so it is exact past the paint cap.\n private totalMatches = 0\n private scope: FindTrackedRanges | null = null\n // What the host follows the painted matches by, so a deferred re-search cannot\n // leave a highlight standing on text that moved out from under it.\n private trackedMatches: FindTrackedRanges | null = null\n private currentMatch: FindMatch | null = null\n private replacing = false\n private pendingResearch = false\n\n public constructor(options: EditorFindOptions = {}) {\n this.options = resolveFindOptions(options)\n }\n\n public attachHost(host: EditorFindHost, highlightPrefix: string): EditorDisposable {\n if (this.host && this.host !== host) this.clearHighlights()\n\n this.host = host\n this.matchHighlightName = `${highlightPrefix}-find-match`\n this.currentHighlightName = `${highlightPrefix}-find-current`\n this.scopeHighlightName = `${highlightPrefix}-find-scope`\n return { dispose: () => this.detachHost(host) }\n }\n\n public attachEditHost(host: EditorFindEditHost): EditorDisposable {\n this.editHost = host\n return { dispose: () => this.detachEditHost(host) }\n }\n\n public subscribe(listener: EditorFindUiListener): EditorDisposable {\n this.listeners.add(listener)\n return { dispose: () => this.listeners.delete(listener) }\n }\n\n public dispose(): void {\n this.pendingResearch = false\n this.scheduler.dispose()\n this.clearHighlights()\n this.listeners.clear()\n this.host = null\n this.editHost = null\n }\n\n public isVisible(): boolean {\n return this.state.revealed\n }\n\n public openFind(): boolean {\n return this.open({ replace: false, focus: 'find' })\n }\n\n public toggleFind(): boolean {\n if (this.state.revealed) return this.close()\n return this.openFind()\n }\n\n public openFindReplace(): boolean {\n return this.open({ replace: true, focus: 'replace' })\n }\n\n public close(): boolean {\n const host = this.host\n if (!this.state.revealed || !host) return false\n\n this.pendingResearch = false\n this.state = { ...this.state, revealed: false, inSelection: false }\n this.scope = null\n this.trackedMatches = null\n this.currentMatch = null\n this.scheduler.cancel(FIND_RESEARCH_KEY)\n this.clearHighlights()\n this.emit({ type: 'hide' })\n host.focusEditor()\n return true\n }\n\n public findNext(): boolean {\n if (!this.ensureFindReady('none')) return false\n\n const startOffset = this.primarySelection()?.endOffset ?? 0\n const match = this.nextMatchAt(startOffset, true)\n // Landing behind where the search started is the search having run out and begun again. Nothing\n // on screen says so to a reader who cannot see the caret jump back up the file.\n if (match && match.start < startOffset) this.host?.announce('Wrapped to the first match')\n\n return this.selectMatch(match)\n }\n\n public findPrevious(): boolean {\n if (!this.ensureFindReady('none')) return false\n\n const startOffset = this.primarySelection()?.startOffset ?? 0\n const match = this.searchFrom(findPreviousMatchFrom, startOffset, {\n escapeEmptyMatchAtOffset: true,\n })\n if (match && match.start > startOffset) this.host?.announce('Wrapped to the last match')\n\n return this.selectMatch(match)\n }\n\n public replaceOne(): boolean {\n if (!this.ensureFindReady('replace')) return false\n const editHost = this.editHost\n if (!editHost) return false\n\n const selection = this.primarySelection()\n if (!selection) return false\n const search = this.commandSearchTarget()\n if (!search) return false\n\n // One scan, from the cursor, with the capture groups of the one match that\n // may be about to be rewritten: enumerating the document for them allocates\n // a capture array per match in it to use exactly one.\n const match = findNextMatchFrom(\n search.source,\n this.state,\n selection.startOffset,\n search.scopes,\n { captureMatches: true, loop: this.options.loop },\n )\n if (!match) return false\n // Not on it yet, so this press is the one that selects it and the next one\n // replaces it.\n if (match.start !== selection.startOffset || match.end !== selection.endOffset)\n return this.selectMatch(match)\n\n const replaceText = this.replacePattern().buildReplaceString(\n match.matches,\n this.state.preserveCase,\n )\n this.applyReplacement(\n [{ from: match.start, to: match.end, text: replaceText }],\n 'input.findReplaceOne',\n { anchor: match.start + replaceText.length, head: match.start + replaceText.length },\n )\n this.selectNextReplacementMatch()\n this.research(false)\n return true\n }\n\n public replaceAll(): boolean {\n if (!this.ensureFindReady('replace')) return false\n const editHost = this.editHost\n if (!editHost) return false\n const search = this.commandSearchTarget()\n if (!search) return false\n\n const pattern = this.replacePattern()\n // Deliberately not FIND_MATCHES_LIMIT: that cap exists to bound painting,\n // and applying it here would rewrite the first 19,999 matches and leave the\n // rest, silently.\n const matches = findMatches(\n search.source,\n this.state,\n search.scopes,\n pattern.hasReplacementPatterns || this.state.preserveCase,\n FIND_REPLACE_ALL_LIMIT,\n )\n if (matches.length === 0) return false\n\n const edits = mergeAdjacentReplaceEdits(\n matches.map((match) => ({\n from: match.start,\n to: match.end,\n text: pattern.buildReplaceString(match.matches, this.state.preserveCase),\n })),\n )\n this.applyReplacement(edits, 'input.findReplaceAll')\n this.research(false)\n return true\n }\n\n public selectAllMatches(): boolean {\n const host = this.host\n if (!host) return false\n if (!this.ensureFindReady('none')) return false\n\n // Re-queried uncapped for the same reason Replace All is: FIND_MATCHES_LIMIT\n // bounds painting, and a cursor set that silently stopped at the paint cap\n // would let the next keystroke edit only part of what the user selected.\n const search = this.commandSearchTarget()\n if (!search) return false\n const matches = findMatches(\n search.source,\n this.state,\n search.scopes,\n false,\n FIND_REPLACE_ALL_LIMIT,\n )\n if (matches.length === 0) return false\n\n const selections = orderedMatchSelections(matches, this.primarySelection())\n host.setSelections(selections, 'input.findSelectAll', selections[0]?.head)\n return true\n }\n\n public toggleMatchCase(): boolean {\n this.state = { ...this.state, matchCase: !this.state.matchCase }\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n public toggleWholeWord(): boolean {\n this.state = { ...this.state, wholeWord: !this.state.wholeWord }\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n public toggleRegex(): boolean {\n this.state = { ...this.state, isRegex: !this.state.isRegex }\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n public togglePreserveCase(): boolean {\n this.state = { ...this.state, preserveCase: !this.state.preserveCase }\n this.updateWidget()\n return true\n }\n\n public toggleReplace(): boolean {\n this.state = { ...this.state, replaceRevealed: !this.state.replaceRevealed }\n this.updateWidget()\n return true\n }\n\n public toggleFindInSelection(): boolean {\n if (this.state.inSelection) {\n this.state = { ...this.state, inSelection: false }\n this.scope = null\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n const host = this.host\n if (!host) return false\n\n const scopes = nonEmptySelectionRanges(this.commandSelections())\n if (scopes.length === 0) return false\n\n this.state = { ...this.state, inSelection: true }\n this.scope = host.trackRanges(scopes)\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n public setSearchString(value: string): void {\n this.state = { ...this.state, searchString: value }\n if (this.options.findOnType) this.research(this.options.cursorMoveOnType)\n }\n\n public setReplaceString(value: string): void {\n this.state = { ...this.state, replaceString: value }\n this.updateWidget()\n }\n\n public handleViewUpdate(\n kind: EditorViewContributionUpdateKind,\n change: EditorContributionChange | null,\n ): void {\n if (!this.state.revealed) return\n if (!isFindDocumentUpdate(kind)) return\n if (change?.kind === 'selection' || change?.kind === 'none') return\n\n if (kind === 'clear') {\n this.close()\n return\n }\n\n // Find's own replace re-searches once the edit it is applying has landed,\n // rather than from inside it, so the matches it is about to discard are not\n // followed through the edit first.\n if (this.replacing) return\n // Nothing to follow across a document swap: the ranges being tracked belong\n // to the buffer that was just replaced. A scope among them is the one that\n // cannot simply be dropped on the floor — resolved against the new buffer it\n // answers with offsets of text the user never marked, and a search confined\n // to those is a Replace All rewriting inside a region nobody drew.\n if (kind === 'document') {\n this.pendingResearch = false\n this.scope = null\n this.state = { ...this.state, inSelection: false }\n this.research(false)\n return\n }\n\n if (this.pendingResearch) {\n this.research(false)\n return\n }\n this.scheduleResearch()\n }\n\n private detachHost(host: EditorFindHost): void {\n if (this.host !== host) return\n\n this.pendingResearch = false\n this.clearHighlights()\n this.host = null\n this.matchHighlightName = ''\n this.currentHighlightName = ''\n this.scopeHighlightName = ''\n this.state = { ...this.state, revealed: false, inSelection: false }\n this.matches = []\n this.highlightsTruncated = false\n this.totalMatches = 0\n this.scope = null\n this.trackedMatches = null\n this.currentMatch = null\n this.scheduler.cancel(FIND_RESEARCH_KEY)\n }\n\n private detachEditHost(host: EditorFindEditHost): void {\n if (this.editHost !== host) return\n\n this.pendingResearch = false\n this.editHost = null\n }\n\n private open(options: EditorFindStartOptions): boolean {\n const host = this.host\n if (!host || !host.hasDocument()) return false\n\n const searchString = this.seedSearchString()\n this.state = {\n ...this.state,\n searchString: searchString || this.state.searchString,\n revealed: true,\n replaceRevealed: options.replace || this.state.replaceRevealed,\n }\n this.applyAutoFindInSelection(host)\n this.emit({ type: 'show', replaceVisible: this.state.replaceRevealed })\n this.research(false)\n this.focusWidget(options.focus)\n return true\n }\n\n private ensureFindReady(focus: 'find' | 'replace' | 'none'): boolean {\n if (!this.state.revealed) return this.open({ replace: focus === 'replace', focus })\n if (this.matches.length === 0) this.research(false)\n return this.state.searchString.length > 0\n }\n\n private research(moveCursor: boolean): void {\n if (!this.host) return\n if (!this.canPaintCurrentDocument()) {\n this.pendingResearch = true\n if (moveCursor) this.selectFirstMatchFromSelection()\n return\n }\n this.pendingResearch = false\n\n // Whatever a deferred run was going to answer, this run answers now.\n this.scheduler.cancel(FIND_RESEARCH_KEY)\n // One past the cap, so a document holding exactly FIND_MATCHES_LIMIT\n // matches is reported as a complete count rather than an overflow.\n const found = this.findAll(false, FIND_MATCHES_LIMIT + 1)\n this.highlightsTruncated = found.length > FIND_MATCHES_LIMIT\n this.totalMatches = this.highlightsTruncated ? this.countAll() : found.length\n this.adoptMatches(this.highlightsTruncated ? found.slice(0, FIND_MATCHES_LIMIT) : found)\n this.currentMatch = matchAtSelection(this.matches, this.primarySelection())\n this.updateHighlights()\n this.updateWidget()\n // Nothing listed is nothing to land on, and asking anyway is two more passes\n // over the document for every keystroke of a query that matches nothing.\n if (moveCursor && found.length > 0) this.selectFirstMatchFromSelection()\n }\n\n private scheduleResearch(): void {\n this.followPendingMatches()\n this.scheduler.schedule({\n key: FIND_RESEARCH_KEY,\n taskClass: 'background-derived',\n delayMs: FIND_RESEARCH_DELAY_MS,\n maxDelayMs: FIND_RESEARCH_MAX_DELAY_MS,\n run: () => this.research(false),\n })\n }\n\n /**\n * Adopts a match set and hands it to the host to follow as far as it is painted.\n *\n * Handed over now rather than when an edit arrives: find is told about an edit\n * once the text has already moved, and a range recorded against the document\n * as it is by then is a range that will never shift.\n *\n * What the reader can see is the bound. A set stopping at the paint cap holds\n * twenty thousand matches, and asking the host to carry all of them costs more\n * per keystroke than the search this deferral exists to keep off it.\n */\n private adoptMatches(matches: readonly FindMatch[]): void {\n this.matches = matches\n this.trackedMatches = this.host?.trackPaintedRanges(matches) ?? null\n }\n\n /**\n * Carries the painted matches through the edit that deferred their re-search.\n *\n * Until it lands they are what the reader sees, and the offsets they were found\n * at address text that has since moved — so they are read back from where that\n * text went. A match whose text is gone resolves to nothing and stops being\n * painted.\n */\n /** Takes the offsets again from what the host is following, after the line it follows to moved. */\n public refreshTrackedMatches(): void {\n this.followPendingMatches()\n }\n\n private followPendingMatches(): void {\n if (!this.canPaintCurrentDocument()) return\n const tracked = this.trackedMatches\n if (!tracked || this.matches.length === 0) return\n\n // The capture groups belonged to the text that was there; only the ranges\n // survive the edit, and the re-search is what recovers the rest.\n this.matches = tracked.resolve().map((range) => ({ ...range, matches: null }))\n this.currentMatch = matchAtSelection(this.matches, this.primarySelection())\n this.updateHighlights()\n this.updateWidget()\n }\n\n private applyReplacement(\n edits: readonly TextEdit[],\n timingName: string,\n selection?: EditorFindSelectionRange,\n ): void {\n const editHost = this.editHost\n if (!editHost) return\n\n this.replacing = true\n try {\n editHost.applyEdits(edits, timingName, selection)\n } finally {\n this.replacing = false\n }\n }\n\n private selectNextReplacementMatch(): void {\n const offset = this.primarySelection()?.endOffset ?? 0\n const match = this.searchFrom(findNextMatchFrom, offset, {})\n if (!match) return\n this.host?.setSelection(match.start, match.end, 'input.findNavigate', findReveal(match))\n }\n\n private canPaintCurrentDocument(): boolean {\n if (!this.editHost) return true\n const snapshot = this.editHost.textSnapshot()\n return snapshot !== null && this.host?.hasTextSnapshot(snapshot) === true\n }\n\n private commandTextSource(): FindTextSource | undefined {\n if (!this.editHost) return this.host?.textSource()\n const snapshot = this.editHost.textSnapshot()\n return snapshot ? findTextSourceFromSnapshot(snapshot) : undefined\n }\n\n private commandSelections(): readonly EditorFindResolvedSelection[] {\n return this.editHost?.getSelections() ?? this.host?.getSelections() ?? []\n }\n\n private commandSearchTarget(): FindSearchTarget | null {\n const source = this.commandTextSource()\n return source ? this.searchTarget(source) : null\n }\n\n private findAll(captureMatches: boolean, limit = FIND_MATCHES_LIMIT): readonly FindMatch[] {\n const search = this.searchTarget()\n if (!search) return []\n\n return findMatches(search.source, this.state, search.scopes, captureMatches, limit)\n }\n\n private countAll(before?: number): number {\n const search = this.searchTarget()\n return search ? countMatches(search.source, this.state, search.scopes, before) : 0\n }\n\n private searchFrom(\n find: FindMatchFromSearcher,\n offset: number,\n options: FindMatchFromOptions,\n ): FindMatch | null {\n const search = this.commandSearchTarget()\n if (!search) return null\n\n return find(search.source, this.state, offset, search.scopes, {\n loop: this.options.loop,\n ...options,\n })\n }\n\n private searchTarget(source = this.host?.textSource()): FindSearchTarget | null {\n if (!source) return null\n\n const scopes = this.scopeRanges()\n // A scope that has run out of ranges is not the absence of a scope: every\n // range the user marked was edited away, and widening the search to the\n // document would let the next Replace All rewrite text they never marked.\n if (scopes && scopes.length === 0) return null\n\n return { source, scopes }\n }\n\n private scopeRanges(): readonly FindRange[] | null {\n return this.scope?.resolve() ?? null\n }\n\n private selectFirstMatchFromSelection(): void {\n const offset = this.primarySelection()?.endOffset ?? 0\n // Deliberately not escaping an empty match here: re-searching should land\n // on the match at the cursor, empty or not. Only an explicit Find\n // Next/Previous is asking to move off it.\n this.selectMatch(this.nextMatchAt(offset, false), false)\n }\n\n private nextMatchAt(offset: number, escapeEmptyMatchAtOffset: boolean): FindMatch | null {\n return this.searchFrom(findNextMatchFrom, offset, { escapeEmptyMatchAtOffset })\n }\n\n private selectMatch(match: FindMatch | null, committed = true): boolean {\n const host = this.host\n if (!match || !host) return false\n\n if (this.canPaintCurrentDocument()) this.currentMatch = match\n host.setSelection(match.start, match.end, 'input.findNavigate', findReveal(match, committed))\n if (!this.canPaintCurrentDocument()) return true\n this.updateHighlights()\n this.updateWidget()\n return true\n }\n\n private updateHighlights(): void {\n if (!this.canPaintCurrentDocument()) return\n const host = this.host\n if (!host) return\n\n host.setRangeHighlight(this.matchHighlightName, this.matches, FIND_MATCH_STYLE)\n host.setRangeHighlight(this.currentHighlightName, this.currentMatchRanges(), FIND_CURRENT_STYLE)\n const scopes = this.scopeRanges()\n if (scopes) {\n host.setRangeHighlight(this.scopeHighlightName, scopes, FIND_SCOPE_STYLE)\n return\n }\n\n host.clearRangeHighlight(this.scopeHighlightName)\n }\n\n private currentMatchRanges(): readonly FindRange[] {\n return this.currentMatch ? [this.currentMatch] : []\n }\n\n private clearHighlights(): void {\n const host = this.host\n if (!host || !this.matchHighlightName) return\n\n host.clearRangeHighlight(this.matchHighlightName)\n host.clearRangeHighlight(this.currentHighlightName)\n host.clearRangeHighlight(this.scopeHighlightName)\n }\n\n private updateWidget(): void {\n this.emit({ type: 'update', state: this.widgetState() })\n }\n\n private widgetState(): EditorFindWidgetState {\n return {\n ...this.state,\n // Between an edit and its re-search the painted matches are what is known.\n matchesCount: this.highlightsTruncated ? this.totalMatches : this.matches.length,\n matchesPosition: this.currentMatchPosition(),\n highlightsTruncated: this.highlightsTruncated,\n }\n }\n\n // Past the paint cap the match is in no list to look it up in, so its place is\n // the number of matches in front of it.\n private currentMatchPosition(): number {\n if (!this.currentMatch) return 0\n\n const painted = findMatchIndex(this.matches, this.currentMatch)\n if (painted >= 0 || !this.highlightsTruncated) return painted + 1\n return this.countAll(this.currentMatch.start) + 1\n }\n\n private focusWidget(focus: 'find' | 'replace' | 'none'): void {\n if (focus === 'find') this.emit({ type: 'focus', target: 'find' })\n if (focus === 'replace') this.emit({ type: 'focus', target: 'replace' })\n }\n\n private seedSearchString(): string {\n if (this.options.seedSearchStringFromSelection === 'never') return ''\n\n const selection = this.primarySelection()\n if (!selection) return ''\n\n const source = this.commandTextSource()\n if (!source) return ''\n if (!selection.collapsed)\n return this.seedFromLiteralText(selectedSingleLineText(source, selection))\n if (this.options.seedSearchStringFromSelection === 'selection') return ''\n\n return this.seedFromLiteralText(wordTextAtOffset(source, selection.headOffset))\n }\n\n // The seed is document text, never a pattern: unescaped, `foo(bar)` seeded\n // into a regex search becomes a capture group and finds nothing, with no hint\n // to the user why.\n private seedFromLiteralText(value: string): string {\n return this.state.isRegex ? escapeRegExpCharacters(value) : value\n }\n\n private applyAutoFindInSelection(host: EditorFindHost): void {\n const scopes = nonEmptySelectionRanges(this.commandSelections())\n if (scopes.length === 0) return\n if (this.options.autoFindInSelection === 'never') return\n if (this.options.autoFindInSelection === 'always') {\n this.state = { ...this.state, inSelection: true }\n this.scope = host.trackRanges(scopes)\n return\n }\n\n const source = this.commandTextSource()\n if (!source || !hasMultilineScope(source, scopes)) return\n\n this.state = { ...this.state, inSelection: true }\n this.scope = host.trackRanges(scopes)\n }\n\n private replacePattern(): ReplacePattern {\n if (this.state.isRegex) return parseReplaceString(this.state.replaceString)\n return ReplacePattern.fromStaticValue(this.state.replaceString)\n }\n\n private primarySelection(): EditorFindResolvedSelection | null {\n return this.commandSelections()[0] ?? null\n }\n\n private emit(event: EditorFindUiEvent): void {\n for (const listener of this.listeners) listener(event)\n }\n}\n\nfunction resolveFindOptions(options: EditorFindOptions): ResolvedFindOptions {\n return {\n loop: options.loop ?? true,\n seedSearchStringFromSelection: options.seedSearchStringFromSelection ?? 'always',\n findOnType: options.findOnType ?? true,\n cursorMoveOnType: options.cursorMoveOnType ?? true,\n autoFindInSelection: options.autoFindInSelection ?? 'never',\n }\n}\n\nfunction isFindDocumentUpdate(kind: EditorViewContributionUpdateKind): boolean {\n return kind === 'document' || kind === 'content' || kind === 'clear'\n}\n\nfunction selectedSingleLineText(\n source: FindTextSource,\n selection: EditorFindResolvedSelection,\n): string {\n // Both bounds are checked before the read, so an oversized or multi-line\n // selection is never copied at all.\n if (selection.endOffset - selection.startOffset >= SEARCH_STRING_MAX_LENGTH) return ''\n if (spansLines(source, selection.startOffset, selection.endOffset)) return ''\n\n return source.readRange(selection.startOffset, selection.endOffset)\n}\n\n// A word ends at a line break, so the line holding the caret is the whole\n// haystack the scan can need.\nfunction wordTextAtOffset(source: FindTextSource, offset: number): string {\n const line = findLineRange(source, offset)\n const text = source.readRange(line.start, line.end)\n const word = wordRangeAtOffset(text, offset - line.start)\n return text.slice(word.start, word.end)\n}\n\nfunction nonEmptySelectionRanges(\n selections: readonly EditorFindResolvedSelection[],\n): readonly FindRange[] {\n return selections\n .filter((selection) => !selection.collapsed)\n .map((selection) => ({ start: selection.startOffset, end: selection.endOffset }))\n}\n\nfunction hasMultilineScope(source: FindTextSource, scopes: readonly FindRange[]): boolean {\n return scopes.some((scope) => spansLines(source, scope.start, scope.end))\n}\n\n// Asked of the line index instead of the text: whether two offsets sit on one\n// line is already known there, and reading the span out to look for a break\n// would copy a selection that can be the whole document.\nfunction spansLines(source: FindTextSource, start: number, end: number): boolean {\n const lineStartsView = source.lineStartsView\n return lineStartsView.indexForOffset(start) !== lineStartsView.indexForOffset(end)\n}\n\nfunction matchAtSelection(\n matches: readonly FindMatch[],\n selection: EditorFindResolvedSelection | null,\n): FindMatch | null {\n if (!selection) return null\n return (\n matches.find(\n (match) => match.start === selection.startOffset && match.end === selection.endOffset,\n ) ?? null\n )\n}\n\nfunction orderedMatchSelections(\n matches: readonly FindMatch[],\n currentSelection: EditorFindResolvedSelection | null,\n): readonly EditorFindSelectionRange[] {\n const selections = matches.map(selectionForMatch)\n const currentMatch = matchAtSelection(matches, currentSelection)\n const currentIndex = currentMatch ? findMatchIndex(matches, currentMatch) : -1\n if (!currentSelection || currentIndex < 0) return selections\n\n const current = {\n anchor: currentSelection.anchorOffset,\n head: currentSelection.headOffset,\n affinity: currentSelection.affinity,\n }\n if (currentIndex === 0) return [current, ...selections.slice(1)]\n return [current, ...selections.slice(0, currentIndex), ...selections.slice(currentIndex + 1)]\n}\n\nfunction selectionForMatch(match: FindMatch): EditorFindSelectionRange {\n return { anchor: match.start, head: match.end, affinity: 'after' }\n}\n\nfunction mergeAdjacentReplaceEdits(edits: readonly TextEdit[]): readonly TextEdit[] {\n const sorted = edits.toSorted((left, right) => left.from - right.from || left.to - right.to)\n const merged: TextEdit[] = []\n for (const edit of sorted) mergeReplaceEdit(merged, edit)\n return merged\n}\n\nfunction mergeReplaceEdit(merged: TextEdit[], edit: TextEdit): void {\n const previous = merged.at(-1)\n if (!previous || previous.to !== edit.from) {\n merged.push({ ...edit })\n return\n }\n\n merged[merged.length - 1] = {\n from: previous.from,\n to: edit.to,\n text: previous.text + edit.text,\n }\n}\n"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EA,SAAS,uBACP,SACA,kBACqC;CACrC,MAAM,aAAa,QAAQ,IAAI,iBAAiB;CAChD,MAAM,eAAe,iBAAiB,SAAS,gBAAgB;CAC/D,MAAM,eAAe,eAAe,eAAe,SAAS,YAAY,IAAI;CAC5E,IAAI,CAAC,oBAAoB,eAAe,GAAG,OAAO;CAElD,MAAM,UAAU;EACd,QAAQ,iBAAiB;EACzB,MAAM,iBAAiB;EACvB,UAAU,iBAAiB;CAC7B;CACA,IAAI,iBAAiB,GAAG,OAAO,CAAC,SAAS,GAAG,WAAW,MAAM,CAAC,CAAC;CAC/D,OAAO;EAAC;EAAS,GAAG,WAAW,MAAM,GAAG,YAAY;EAAG,GAAG,WAAW,MAAM,eAAe,CAAC;CAAC;AAC9F;AAEA,SAAS,kBAAkB,OAA4C;CACrE,OAAO;EAAE,QAAQ,MAAM;EAAO,MAAM,MAAM;EAAK,UAAU;CAAQ;AACnE;AAEA,SAAS,0BAA0B,OAAiD;CAClF,MAAM,SAAS,MAAM,UAAU,MAAM,UAAU,KAAK,OAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,EAAE;CAC3F,MAAM,SAAqB,CAAC;CAC5B,KAAK,MAAM,QAAQ,QAAQ,iBAAiB,QAAQ,IAAI;CACxD,OAAO;AACT;AAEA,SAAS,iBAAiB,QAAoB,MAAsB;CAClE,MAAM,WAAW,OAAO,GAAG,EAAE;CAC7B,IAAI,CAAC,YAAY,SAAS,OAAO,KAAK,MAAM;EAC1C,OAAO,KAAK,EAAE,GAAG,KAAK,CAAC;EACvB;CACF;CAEA,OAAO,OAAO,SAAS,KAAK;EAC1B,MAAM,SAAS;EACf,IAAI,KAAK;EACT,MAAM,SAAS,OAAO,KAAK;CAC7B;AACF"}
|
|
1
|
+
{"version":3,"file":"findController.js","names":[],"sources":["../src/findController.ts"],"sourcesContent":["import {\n wordRangeAtOffset,\n type TextEdit,\n type TextReadSnapshot,\n} from '@singapore-editor/core/document'\nimport type { EditorSetSelectionOptions } from '@singapore-editor/core/editor'\nimport type {\n EditorContributionChange,\n EditorDisposable,\n EditorResolvedSelection,\n EditorSelectionRange,\n EditorViewContributionUpdateKind,\n} from '@singapore-editor/core/extensions'\nimport type { VirtualizedTextHighlightStyle } from '@singapore-editor/core/rendering'\nimport { EditorSecondaryViewScheduler } from '@singapore-editor/core/secondary-views'\nimport {\n countMatches,\n escapeRegExpCharacters,\n FIND_MATCHES_LIMIT,\n FIND_REPLACE_ALL_LIMIT,\n findLineRange,\n findMatchIndex,\n findMatches,\n findNextMatchFrom,\n findPreviousMatchFrom,\n findTextSourceFromSnapshot,\n type FindMatch,\n type FindMatchFromOptions,\n type FindMatchFromSearcher,\n type FindQuery,\n type FindRange,\n type FindTextSource,\n} from './search'\nimport { parseReplaceString, ReplacePattern } from './replacePattern'\nimport type { EditorFindOptions } from './types'\n\n// These three overlap by construction — the current match is always also a\n// match, and both sit inside the scope — so their stacking is declared rather\n// than left to the order the groups happen to reach the highlight registry in.\n//\n// The numbers are exported because they are half of a cross-package agreement: the highlight\n// priority space is one namespace that several subsystems write into, and priority is what settles\n// a contest between two of them that declare the same property. A regression test elsewhere asserts\n// the resulting order, and it can only do that by reading these rather than by restating them.\n//\n// They sit above the error diagnostic, which declares a background of its own at 2. `current` is the\n// only find style that declares a `color`, so it is the only one contending on that axis — but all\n// three declare a background, and so does the error, which is why none of them may share its number.\n// A tie there would put the background contest back where the numbers exist to take it out of:\n// registration order in the document's shared registry.\nexport const FIND_HIGHLIGHT_Z_INDEX = {\n scope: 4,\n match: 5,\n current: 6,\n} as const\n\nconst FIND_MATCH_STYLE = {\n dimmable: false,\n backgroundColor: 'rgba(234, 179, 8, 0.34)',\n zIndex: FIND_HIGHLIGHT_Z_INDEX.match,\n}\nconst FIND_CURRENT_STYLE = {\n dimmable: false,\n backgroundColor: 'rgba(245, 158, 11, 0.72)',\n color: '#111827',\n zIndex: FIND_HIGHLIGHT_Z_INDEX.current,\n}\nconst FIND_SCOPE_STYLE = {\n dimmable: false,\n backgroundColor: 'rgba(59, 130, 246, 0.22)',\n zIndex: FIND_HIGHLIGHT_Z_INDEX.scope,\n}\n\n// A match on screen stays where the reader is looking at it; one that is not lands\n// in the middle, with context on both sides rather than on the viewport's edge.\nfunction findReveal(match: FindRange, committed = true): EditorSetSelectionOptions {\n return {\n ...(committed ? { jumpCause: 'find' as const } : {}),\n revealOffset: match.end,\n revealBlock: 'center-if-outside',\n }\n}\n\n// Seeding stops here rather than pushing a multi-megabyte selection through the\n// find input and searching for it.\nconst SEARCH_STRING_MAX_LENGTH = 524_288\n\n// A re-search reads the whole document, which is not a bill a keystroke can be\n// handed. The ceiling is the load-bearing half: a sustained typing run never\n// leaves the quiet gap, so waiting only for quiet would mean never re-searching\n// at all for as long as the user keeps going.\nconst FIND_RESEARCH_KEY = 'find.research'\nconst FIND_RESEARCH_DELAY_MS = 100\nconst FIND_RESEARCH_MAX_DELAY_MS = 400\n\ntype EditorFindSelectionRange = EditorSelectionRange\n\nexport type EditorFindResolvedSelection = EditorResolvedSelection & {\n readonly collapsed: boolean\n}\n\n/**\n * Ranges the host follows through edits on find's behalf.\n *\n * A scope outlives the selection it was taken from: the first replace inside it moves the caret off\n * that selection, so a scope re-derived from what is selected now would be re-derived from\n * something else — or from nothing, and a scope of nothing is indistinguishable from no scope at\n * all. Handed over once, it answers from wherever its text went, however many edits later.\n */\nexport type FindTrackedRanges = {\n resolve(): readonly FindRange[]\n}\n\nexport type EditorFindHost = {\n hasDocument(): boolean\n // Ranges rather than a string, so nothing find does can cost a copy of the\n // document — the reason there is no full-text accessor here to reach for.\n textSource(): FindTextSource\n hasTextSnapshot(snapshot: TextReadSnapshot): boolean\n // Followed wherever they end up, however far off screen: a scope decides where\n // Replace All rewrites, and one that stopped being followed would rewrite text\n // the user never marked.\n trackRanges(ranges: readonly FindRange[]): FindTrackedRanges\n // Followed only as far as the host paints them, the rest answered with the\n // offsets they were handed; see adoptMatches.\n trackPaintedRanges(ranges: readonly FindRange[]): FindTrackedRanges\n getSelections(): readonly EditorFindResolvedSelection[]\n focusEditor(): void\n announce(message: string): void\n setSelection(\n anchor: number,\n head: number,\n timingName: string,\n options?: EditorSetSelectionOptions,\n ): void\n setSelections(\n selections: readonly EditorFindSelectionRange[],\n timingName: string,\n revealOffset?: number,\n ): void\n setRangeHighlight(\n name: string,\n ranges: readonly FindRange[],\n style: VirtualizedTextHighlightStyle,\n ): void\n clearRangeHighlight(name: string): void\n}\n\nexport type EditorFindEditHost = {\n textSnapshot(): TextReadSnapshot | null\n getSelections(): readonly EditorFindResolvedSelection[]\n applyEdits(\n edits: readonly TextEdit[],\n timingName: string,\n selection?: EditorFindSelectionRange,\n ): void\n}\n\nexport type EditorFindStartOptions = {\n readonly replace: boolean\n readonly focus: 'find' | 'replace' | 'none'\n}\n\nexport type EditorFindState = FindQuery & {\n readonly replaceString: string\n readonly preserveCase: boolean\n readonly revealed: boolean\n readonly replaceRevealed: boolean\n readonly inSelection: boolean\n}\n\nexport type EditorFindWidgetState = EditorFindState & {\n // Every match in the searched text, however many of them are painted.\n readonly matchesCount: number\n readonly matchesPosition: number\n // Painting stopped at FIND_MATCHES_LIMIT. The count and navigation did not.\n readonly highlightsTruncated: boolean\n}\n\nexport type EditorFindUiEvent =\n | { readonly type: 'show'; readonly replaceVisible: boolean }\n | { readonly type: 'hide' }\n | { readonly type: 'focus'; readonly target: 'find' | 'replace' }\n | { readonly type: 'update'; readonly state: EditorFindWidgetState }\n\ntype ResolvedFindOptions = Required<EditorFindOptions>\ntype EditorFindUiListener = (event: EditorFindUiEvent) => void\n\n// What every search resolves to before it runs: the text, and the ranges of it\n// the query is allowed to answer from. Null scopes are the whole document; an\n// empty scope refuses the search outright, so it is never one of these.\ntype FindSearchTarget = {\n readonly source: FindTextSource\n readonly scopes: readonly FindRange[] | null\n}\n\nexport class EditorFindController {\n private readonly options: ResolvedFindOptions\n private readonly listeners = new Set<EditorFindUiListener>()\n private host: EditorFindHost | null = null\n private editHost: EditorFindEditHost | null = null\n private matchHighlightName = ''\n private currentHighlightName = ''\n private scopeHighlightName = ''\n private state: EditorFindState = {\n searchString: '',\n replaceString: '',\n isRegex: false,\n matchCase: false,\n wholeWord: false,\n preserveCase: false,\n revealed: false,\n replaceRevealed: false,\n inSelection: false,\n }\n private readonly scheduler = new EditorSecondaryViewScheduler()\n private matches: readonly FindMatch[] = []\n private highlightsTruncated = false\n // Counted rather than listed, so it is exact past the paint cap.\n private totalMatches = 0\n private scope: FindTrackedRanges | null = null\n // What the host follows the painted matches by, so a deferred re-search cannot\n // leave a highlight standing on text that moved out from under it.\n private trackedMatches: FindTrackedRanges | null = null\n private currentMatch: FindMatch | null = null\n private replacing = false\n private pendingResearch = false\n\n public constructor(options: EditorFindOptions = {}) {\n this.options = resolveFindOptions(options)\n }\n\n public attachHost(host: EditorFindHost, highlightPrefix: string): EditorDisposable {\n if (this.host && this.host !== host) this.clearHighlights()\n\n this.host = host\n this.matchHighlightName = `${highlightPrefix}-find-match`\n this.currentHighlightName = `${highlightPrefix}-find-current`\n this.scopeHighlightName = `${highlightPrefix}-find-scope`\n return { dispose: () => this.detachHost(host) }\n }\n\n public attachEditHost(host: EditorFindEditHost): EditorDisposable {\n this.editHost = host\n return { dispose: () => this.detachEditHost(host) }\n }\n\n public subscribe(listener: EditorFindUiListener): EditorDisposable {\n this.listeners.add(listener)\n return { dispose: () => this.listeners.delete(listener) }\n }\n\n public dispose(): void {\n this.pendingResearch = false\n this.scheduler.dispose()\n this.clearHighlights()\n this.listeners.clear()\n this.host = null\n this.editHost = null\n }\n\n public isVisible(): boolean {\n return this.state.revealed\n }\n\n public openFind(): boolean {\n return this.open({ replace: false, focus: 'find' })\n }\n\n public toggleFind(): boolean {\n if (this.state.revealed) return this.close()\n return this.openFind()\n }\n\n public openFindReplace(): boolean {\n return this.open({ replace: true, focus: 'replace' })\n }\n\n public close(): boolean {\n const host = this.host\n if (!this.state.revealed || !host) return false\n\n this.pendingResearch = false\n this.state = { ...this.state, revealed: false, inSelection: false }\n this.scope = null\n this.trackedMatches = null\n this.currentMatch = null\n this.scheduler.cancel(FIND_RESEARCH_KEY)\n this.clearHighlights()\n this.emit({ type: 'hide' })\n host.focusEditor()\n return true\n }\n\n public findNext(): boolean {\n if (!this.ensureFindReady('none')) return false\n\n const startOffset = this.primarySelection()?.endOffset ?? 0\n const match = this.nextMatchAt(startOffset, true)\n // Landing behind where the search started is the search having run out and begun again. Nothing\n // on screen says so to a reader who cannot see the caret jump back up the file.\n if (match && match.start < startOffset) this.host?.announce('Wrapped to the first match')\n\n return this.selectMatch(match)\n }\n\n public findPrevious(): boolean {\n if (!this.ensureFindReady('none')) return false\n\n const startOffset = this.primarySelection()?.startOffset ?? 0\n const match = this.searchFrom(findPreviousMatchFrom, startOffset, {\n escapeEmptyMatchAtOffset: true,\n })\n if (match && match.start > startOffset) this.host?.announce('Wrapped to the last match')\n\n return this.selectMatch(match)\n }\n\n public replaceOne(): boolean {\n if (!this.ensureFindReady('replace')) return false\n const editHost = this.editHost\n if (!editHost) return false\n\n const selection = this.primarySelection()\n if (!selection) return false\n const search = this.commandSearchTarget()\n if (!search) return false\n\n // One scan, from the cursor, with the capture groups of the one match that\n // may be about to be rewritten: enumerating the document for them allocates\n // a capture array per match in it to use exactly one.\n const match = findNextMatchFrom(\n search.source,\n this.state,\n selection.startOffset,\n search.scopes,\n { captureMatches: true, loop: this.options.loop },\n )\n if (!match) return false\n // Not on it yet, so this press is the one that selects it and the next one\n // replaces it.\n if (match.start !== selection.startOffset || match.end !== selection.endOffset)\n return this.selectMatch(match)\n\n const replaceText = this.replacePattern().buildReplaceString(\n match.matches,\n this.state.preserveCase,\n )\n this.applyReplacement(\n [{ from: match.start, to: match.end, text: replaceText }],\n 'input.findReplaceOne',\n { anchor: match.start + replaceText.length, head: match.start + replaceText.length },\n )\n this.selectNextReplacementMatch()\n this.research(false)\n return true\n }\n\n public replaceAll(): boolean {\n if (!this.ensureFindReady('replace')) return false\n const editHost = this.editHost\n if (!editHost) return false\n const search = this.commandSearchTarget()\n if (!search) return false\n\n const pattern = this.replacePattern()\n // Deliberately not FIND_MATCHES_LIMIT: that cap exists to bound painting,\n // and applying it here would rewrite the first 19,999 matches and leave the\n // rest, silently.\n const matches = findMatches(\n search.source,\n this.state,\n search.scopes,\n pattern.hasReplacementPatterns || this.state.preserveCase,\n FIND_REPLACE_ALL_LIMIT,\n )\n if (matches.length === 0) return false\n\n const edits = mergeAdjacentReplaceEdits(\n matches.map((match) => ({\n from: match.start,\n to: match.end,\n text: pattern.buildReplaceString(match.matches, this.state.preserveCase),\n })),\n )\n this.applyReplacement(edits, 'input.findReplaceAll')\n this.research(false)\n return true\n }\n\n public selectAllMatches(): boolean {\n const host = this.host\n if (!host) return false\n if (!this.ensureFindReady('none')) return false\n\n // Re-queried uncapped for the same reason Replace All is: FIND_MATCHES_LIMIT\n // bounds painting, and a cursor set that silently stopped at the paint cap\n // would let the next keystroke edit only part of what the user selected.\n const search = this.commandSearchTarget()\n if (!search) return false\n const matches = findMatches(\n search.source,\n this.state,\n search.scopes,\n false,\n FIND_REPLACE_ALL_LIMIT,\n )\n if (matches.length === 0) return false\n\n const selections = orderedMatchSelections(matches, this.primarySelection())\n host.setSelections(selections, 'input.findSelectAll', selections[0]?.head)\n return true\n }\n\n public toggleMatchCase(): boolean {\n this.state = { ...this.state, matchCase: !this.state.matchCase }\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n public toggleWholeWord(): boolean {\n this.state = { ...this.state, wholeWord: !this.state.wholeWord }\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n public toggleRegex(): boolean {\n this.state = { ...this.state, isRegex: !this.state.isRegex }\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n public togglePreserveCase(): boolean {\n this.state = { ...this.state, preserveCase: !this.state.preserveCase }\n this.updateWidget()\n return true\n }\n\n public toggleReplace(): boolean {\n this.state = { ...this.state, replaceRevealed: !this.state.replaceRevealed }\n this.updateWidget()\n return true\n }\n\n public toggleFindInSelection(): boolean {\n if (this.state.inSelection) {\n this.state = { ...this.state, inSelection: false }\n this.scope = null\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n const host = this.host\n if (!host) return false\n\n const scopes = nonEmptySelectionRanges(this.commandSelections())\n if (scopes.length === 0) return false\n\n this.state = { ...this.state, inSelection: true }\n this.scope = host.trackRanges(scopes)\n this.research(this.options.cursorMoveOnType)\n return true\n }\n\n public setSearchString(value: string): void {\n this.state = { ...this.state, searchString: value }\n if (this.options.findOnType) this.research(this.options.cursorMoveOnType)\n }\n\n public setReplaceString(value: string): void {\n this.state = { ...this.state, replaceString: value }\n this.updateWidget()\n }\n\n public handleViewUpdate(\n kind: EditorViewContributionUpdateKind,\n change: EditorContributionChange | null,\n ): void {\n if (!this.state.revealed) return\n if (!isFindDocumentUpdate(kind)) return\n if (change?.kind === 'selection' || change?.kind === 'none') return\n\n if (kind === 'clear') {\n this.close()\n return\n }\n\n // Find's own replace re-searches once the edit it is applying has landed,\n // rather than from inside it, so the matches it is about to discard are not\n // followed through the edit first.\n if (this.replacing) return\n // Nothing to follow across a document swap: the ranges being tracked belong\n // to the buffer that was just replaced. A scope among them is the one that\n // cannot simply be dropped on the floor — resolved against the new buffer it\n // answers with offsets of text the user never marked, and a search confined\n // to those is a Replace All rewriting inside a region nobody drew.\n if (kind === 'document') {\n this.pendingResearch = false\n this.scope = null\n this.state = { ...this.state, inSelection: false }\n this.research(false)\n return\n }\n\n if (this.pendingResearch) {\n this.research(false)\n return\n }\n this.scheduleResearch()\n }\n\n private detachHost(host: EditorFindHost): void {\n if (this.host !== host) return\n\n this.pendingResearch = false\n this.clearHighlights()\n this.host = null\n this.matchHighlightName = ''\n this.currentHighlightName = ''\n this.scopeHighlightName = ''\n this.state = { ...this.state, revealed: false, inSelection: false }\n this.matches = []\n this.highlightsTruncated = false\n this.totalMatches = 0\n this.scope = null\n this.trackedMatches = null\n this.currentMatch = null\n this.scheduler.cancel(FIND_RESEARCH_KEY)\n }\n\n private detachEditHost(host: EditorFindEditHost): void {\n if (this.editHost !== host) return\n\n this.pendingResearch = false\n this.editHost = null\n }\n\n private open(options: EditorFindStartOptions): boolean {\n const host = this.host\n if (!host || !host.hasDocument()) return false\n\n const searchString = this.seedSearchString()\n this.state = {\n ...this.state,\n searchString: searchString || this.state.searchString,\n revealed: true,\n replaceRevealed: options.replace || this.state.replaceRevealed,\n }\n this.applyAutoFindInSelection(host)\n this.emit({ type: 'show', replaceVisible: this.state.replaceRevealed })\n this.research(false)\n this.focusWidget(options.focus)\n return true\n }\n\n private ensureFindReady(focus: 'find' | 'replace' | 'none'): boolean {\n if (!this.state.revealed) return this.open({ replace: focus === 'replace', focus })\n if (this.matches.length === 0) this.research(false)\n return this.state.searchString.length > 0\n }\n\n private research(moveCursor: boolean): void {\n if (!this.host) return\n if (!this.canPaintCurrentDocument()) {\n this.pendingResearch = true\n if (moveCursor) this.selectFirstMatchFromSelection()\n return\n }\n this.pendingResearch = false\n\n // Whatever a deferred run was going to answer, this run answers now.\n this.scheduler.cancel(FIND_RESEARCH_KEY)\n // One past the cap, so a document holding exactly FIND_MATCHES_LIMIT\n // matches is reported as a complete count rather than an overflow.\n const found = this.findAll(false, FIND_MATCHES_LIMIT + 1)\n this.highlightsTruncated = found.length > FIND_MATCHES_LIMIT\n this.totalMatches = this.highlightsTruncated ? this.countAll() : found.length\n this.adoptMatches(this.highlightsTruncated ? found.slice(0, FIND_MATCHES_LIMIT) : found)\n this.currentMatch = matchAtSelection(this.matches, this.primarySelection())\n this.updateHighlights()\n this.updateWidget()\n // Nothing listed is nothing to land on, and asking anyway is two more passes\n // over the document for every keystroke of a query that matches nothing.\n if (moveCursor && found.length > 0) this.selectFirstMatchFromSelection()\n }\n\n private scheduleResearch(): void {\n this.followPendingMatches()\n this.scheduler.schedule({\n key: FIND_RESEARCH_KEY,\n taskClass: 'background-derived',\n delayMs: FIND_RESEARCH_DELAY_MS,\n maxDelayMs: FIND_RESEARCH_MAX_DELAY_MS,\n run: () => this.research(false),\n })\n }\n\n /**\n * Adopts a match set and hands it to the host to follow as far as it is painted.\n *\n * Handed over now rather than when an edit arrives: find is told about an edit\n * once the text has already moved, and a range recorded against the document\n * as it is by then is a range that will never shift.\n *\n * What the reader can see is the bound. A set stopping at the paint cap holds\n * twenty thousand matches, and asking the host to carry all of them costs more\n * per keystroke than the search this deferral exists to keep off it.\n */\n private adoptMatches(matches: readonly FindMatch[]): void {\n this.matches = matches\n this.trackedMatches = this.host?.trackPaintedRanges(matches) ?? null\n }\n\n /**\n * Carries the painted matches through the edit that deferred their re-search.\n *\n * Until it lands they are what the reader sees, and the offsets they were found\n * at address text that has since moved — so they are read back from where that\n * text went. A match whose text is gone resolves to nothing and stops being\n * painted.\n */\n /** Takes the offsets again from what the host is following, after the line it follows to moved. */\n public refreshTrackedMatches(): void {\n this.followPendingMatches()\n }\n\n private followPendingMatches(): void {\n if (!this.canPaintCurrentDocument()) return\n const tracked = this.trackedMatches\n if (!tracked || this.matches.length === 0) return\n\n // The capture groups belonged to the text that was there; only the ranges\n // survive the edit, and the re-search is what recovers the rest.\n this.matches = tracked.resolve().map((range) => ({ ...range, matches: null }))\n this.currentMatch = matchAtSelection(this.matches, this.primarySelection())\n this.updateHighlights()\n this.updateWidget()\n }\n\n private applyReplacement(\n edits: readonly TextEdit[],\n timingName: string,\n selection?: EditorFindSelectionRange,\n ): void {\n const editHost = this.editHost\n if (!editHost) return\n\n this.replacing = true\n try {\n editHost.applyEdits(edits, timingName, selection)\n } finally {\n this.replacing = false\n }\n }\n\n private selectNextReplacementMatch(): void {\n const offset = this.primarySelection()?.endOffset ?? 0\n const match = this.searchFrom(findNextMatchFrom, offset, {})\n if (!match) return\n this.host?.setSelection(match.start, match.end, 'input.findNavigate', findReveal(match))\n }\n\n private canPaintCurrentDocument(): boolean {\n if (!this.editHost) return true\n const snapshot = this.editHost.textSnapshot()\n return snapshot !== null && this.host?.hasTextSnapshot(snapshot) === true\n }\n\n private commandTextSource(): FindTextSource | undefined {\n if (!this.editHost) return this.host?.textSource()\n const snapshot = this.editHost.textSnapshot()\n return snapshot ? findTextSourceFromSnapshot(snapshot) : undefined\n }\n\n private commandSelections(): readonly EditorFindResolvedSelection[] {\n return this.editHost?.getSelections() ?? this.host?.getSelections() ?? []\n }\n\n private commandSearchTarget(): FindSearchTarget | null {\n const source = this.commandTextSource()\n return source ? this.searchTarget(source) : null\n }\n\n private findAll(captureMatches: boolean, limit = FIND_MATCHES_LIMIT): readonly FindMatch[] {\n const search = this.searchTarget()\n if (!search) return []\n\n return findMatches(search.source, this.state, search.scopes, captureMatches, limit)\n }\n\n private countAll(before?: number): number {\n const search = this.searchTarget()\n return search ? countMatches(search.source, this.state, search.scopes, before) : 0\n }\n\n private searchFrom(\n find: FindMatchFromSearcher,\n offset: number,\n options: FindMatchFromOptions,\n ): FindMatch | null {\n const search = this.commandSearchTarget()\n if (!search) return null\n\n return find(search.source, this.state, offset, search.scopes, {\n loop: this.options.loop,\n ...options,\n })\n }\n\n private searchTarget(source = this.host?.textSource()): FindSearchTarget | null {\n if (!source) return null\n\n const scopes = this.scopeRanges()\n // A scope that has run out of ranges is not the absence of a scope: every\n // range the user marked was edited away, and widening the search to the\n // document would let the next Replace All rewrite text they never marked.\n if (scopes && scopes.length === 0) return null\n\n return { source, scopes }\n }\n\n private scopeRanges(): readonly FindRange[] | null {\n return this.scope?.resolve() ?? null\n }\n\n private selectFirstMatchFromSelection(): void {\n const offset = this.primarySelection()?.endOffset ?? 0\n // Deliberately not escaping an empty match here: re-searching should land\n // on the match at the cursor, empty or not. Only an explicit Find\n // Next/Previous is asking to move off it.\n this.selectMatch(this.nextMatchAt(offset, false), false)\n }\n\n private nextMatchAt(offset: number, escapeEmptyMatchAtOffset: boolean): FindMatch | null {\n return this.searchFrom(findNextMatchFrom, offset, { escapeEmptyMatchAtOffset })\n }\n\n private selectMatch(match: FindMatch | null, committed = true): boolean {\n const host = this.host\n if (!match || !host) return false\n\n if (this.canPaintCurrentDocument()) this.currentMatch = match\n host.setSelection(match.start, match.end, 'input.findNavigate', findReveal(match, committed))\n if (!this.canPaintCurrentDocument()) return true\n this.updateHighlights()\n this.updateWidget()\n return true\n }\n\n private updateHighlights(): void {\n if (!this.canPaintCurrentDocument()) return\n const host = this.host\n if (!host) return\n\n host.setRangeHighlight(this.matchHighlightName, this.matches, FIND_MATCH_STYLE)\n host.setRangeHighlight(this.currentHighlightName, this.currentMatchRanges(), FIND_CURRENT_STYLE)\n const scopes = this.scopeRanges()\n if (scopes) {\n host.setRangeHighlight(this.scopeHighlightName, scopes, FIND_SCOPE_STYLE)\n return\n }\n\n host.clearRangeHighlight(this.scopeHighlightName)\n }\n\n private currentMatchRanges(): readonly FindRange[] {\n return this.currentMatch ? [this.currentMatch] : []\n }\n\n private clearHighlights(): void {\n const host = this.host\n if (!host || !this.matchHighlightName) return\n\n host.clearRangeHighlight(this.matchHighlightName)\n host.clearRangeHighlight(this.currentHighlightName)\n host.clearRangeHighlight(this.scopeHighlightName)\n }\n\n private updateWidget(): void {\n this.emit({ type: 'update', state: this.widgetState() })\n }\n\n private widgetState(): EditorFindWidgetState {\n return {\n ...this.state,\n // Between an edit and its re-search the painted matches are what is known.\n matchesCount: this.highlightsTruncated ? this.totalMatches : this.matches.length,\n matchesPosition: this.currentMatchPosition(),\n highlightsTruncated: this.highlightsTruncated,\n }\n }\n\n // Past the paint cap the match is in no list to look it up in, so its place is\n // the number of matches in front of it.\n private currentMatchPosition(): number {\n if (!this.currentMatch) return 0\n\n const painted = findMatchIndex(this.matches, this.currentMatch)\n if (painted >= 0 || !this.highlightsTruncated) return painted + 1\n return this.countAll(this.currentMatch.start) + 1\n }\n\n private focusWidget(focus: 'find' | 'replace' | 'none'): void {\n if (focus === 'find') this.emit({ type: 'focus', target: 'find' })\n if (focus === 'replace') this.emit({ type: 'focus', target: 'replace' })\n }\n\n private seedSearchString(): string {\n if (this.options.seedSearchStringFromSelection === 'never') return ''\n\n const selection = this.primarySelection()\n if (!selection) return ''\n\n const source = this.commandTextSource()\n if (!source) return ''\n if (!selection.collapsed)\n return this.seedFromLiteralText(selectedSingleLineText(source, selection))\n if (this.options.seedSearchStringFromSelection === 'selection') return ''\n\n return this.seedFromLiteralText(wordTextAtOffset(source, selection.headOffset))\n }\n\n // The seed is document text, never a pattern: unescaped, `foo(bar)` seeded\n // into a regex search becomes a capture group and finds nothing, with no hint\n // to the user why.\n private seedFromLiteralText(value: string): string {\n return this.state.isRegex ? escapeRegExpCharacters(value) : value\n }\n\n private applyAutoFindInSelection(host: EditorFindHost): void {\n const scopes = nonEmptySelectionRanges(this.commandSelections())\n if (scopes.length === 0) return\n if (this.options.autoFindInSelection === 'never') return\n if (this.options.autoFindInSelection === 'always') {\n this.state = { ...this.state, inSelection: true }\n this.scope = host.trackRanges(scopes)\n return\n }\n\n const source = this.commandTextSource()\n if (!source || !hasMultilineScope(source, scopes)) return\n\n this.state = { ...this.state, inSelection: true }\n this.scope = host.trackRanges(scopes)\n }\n\n private replacePattern(): ReplacePattern {\n if (this.state.isRegex) return parseReplaceString(this.state.replaceString)\n return ReplacePattern.fromStaticValue(this.state.replaceString)\n }\n\n private primarySelection(): EditorFindResolvedSelection | null {\n return this.commandSelections()[0] ?? null\n }\n\n private emit(event: EditorFindUiEvent): void {\n for (const listener of this.listeners) listener(event)\n }\n}\n\nfunction resolveFindOptions(options: EditorFindOptions): ResolvedFindOptions {\n return {\n loop: options.loop ?? true,\n seedSearchStringFromSelection: options.seedSearchStringFromSelection ?? 'always',\n findOnType: options.findOnType ?? true,\n cursorMoveOnType: options.cursorMoveOnType ?? true,\n autoFindInSelection: options.autoFindInSelection ?? 'never',\n }\n}\n\nfunction isFindDocumentUpdate(kind: EditorViewContributionUpdateKind): boolean {\n return kind === 'document' || kind === 'content' || kind === 'clear'\n}\n\nfunction selectedSingleLineText(\n source: FindTextSource,\n selection: EditorFindResolvedSelection,\n): string {\n // Both bounds are checked before the read, so an oversized or multi-line\n // selection is never copied at all.\n if (selection.endOffset - selection.startOffset >= SEARCH_STRING_MAX_LENGTH) return ''\n if (spansLines(source, selection.startOffset, selection.endOffset)) return ''\n\n return source.readRange(selection.startOffset, selection.endOffset)\n}\n\n// A word ends at a line break, so the line holding the caret is the whole\n// haystack the scan can need.\nfunction wordTextAtOffset(source: FindTextSource, offset: number): string {\n const line = findLineRange(source, offset)\n const text = source.readRange(line.start, line.end)\n const word = wordRangeAtOffset(text, offset - line.start)\n return text.slice(word.start, word.end)\n}\n\nfunction nonEmptySelectionRanges(\n selections: readonly EditorFindResolvedSelection[],\n): readonly FindRange[] {\n return selections\n .filter((selection) => !selection.collapsed)\n .map((selection) => ({ start: selection.startOffset, end: selection.endOffset }))\n}\n\nfunction hasMultilineScope(source: FindTextSource, scopes: readonly FindRange[]): boolean {\n return scopes.some((scope) => spansLines(source, scope.start, scope.end))\n}\n\n// Asked of the line index instead of the text: whether two offsets sit on one\n// line is already known there, and reading the span out to look for a break\n// would copy a selection that can be the whole document.\nfunction spansLines(source: FindTextSource, start: number, end: number): boolean {\n const lineStartsView = source.lineStartsView\n return lineStartsView.indexForOffset(start) !== lineStartsView.indexForOffset(end)\n}\n\nfunction matchAtSelection(\n matches: readonly FindMatch[],\n selection: EditorFindResolvedSelection | null,\n): FindMatch | null {\n if (!selection) return null\n return (\n matches.find(\n (match) => match.start === selection.startOffset && match.end === selection.endOffset,\n ) ?? null\n )\n}\n\nfunction orderedMatchSelections(\n matches: readonly FindMatch[],\n currentSelection: EditorFindResolvedSelection | null,\n): readonly EditorFindSelectionRange[] {\n const selections = matches.map(selectionForMatch)\n const currentMatch = matchAtSelection(matches, currentSelection)\n const currentIndex = currentMatch ? findMatchIndex(matches, currentMatch) : -1\n if (!currentSelection || currentIndex < 0) return selections\n\n const current: EditorFindSelectionRange = {\n anchor: currentSelection.anchorOffset,\n head: currentSelection.headOffset,\n affinity: currentSelection.affinity,\n }\n if (currentIndex === 0) return [current].concat(selections.slice(1))\n return [current].concat(selections.slice(0, currentIndex), selections.slice(currentIndex + 1))\n}\n\nfunction selectionForMatch(match: FindMatch): EditorFindSelectionRange {\n return { anchor: match.start, head: match.end, affinity: 'after' }\n}\n\nfunction mergeAdjacentReplaceEdits(edits: TextEdit[]): readonly TextEdit[] {\n const sorted = edits.sort((left, right) => left.from - right.from || left.to - right.to)\n const merged: TextEdit[] = []\n for (const edit of sorted) mergeReplaceEdit(merged, edit)\n return merged\n}\n\nfunction mergeReplaceEdit(merged: TextEdit[], edit: TextEdit): void {\n const previous = merged.at(-1)\n if (!previous || previous.to !== edit.from) {\n merged.push({ ...edit })\n return\n }\n\n merged[merged.length - 1] = {\n from: previous.from,\n to: edit.to,\n text: previous.text + edit.text,\n }\n}\n"],"mappings":";;;;;AAkDA,IAAa,yBAAyB;CACpC,OAAO;CACP,OAAO;CACP,SAAS;AACX;AAEA,IAAM,mBAAmB;CACvB,UAAU;CACV,iBAAiB;CACjB,QAAQ,uBAAuB;AACjC;AACA,IAAM,qBAAqB;CACzB,UAAU;CACV,iBAAiB;CACjB,OAAO;CACP,QAAQ,uBAAuB;AACjC;AACA,IAAM,mBAAmB;CACvB,UAAU;CACV,iBAAiB;CACjB,QAAQ,uBAAuB;AACjC;AAIA,SAAS,WAAW,OAAkB,YAAY,MAAiC;CACjF,OAAO;EACL,GAAI,YAAY,EAAE,WAAW,OAAgB,IAAI,CAAC;EAClD,cAAc,MAAM;EACpB,aAAa;CACf;AACF;AAIA,IAAM,2BAA2B;AAMjC,IAAM,oBAAoB;AAC1B,IAAM,yBAAyB;AAC/B,IAAM,6BAA6B;AAuGnC,IAAa,uBAAb,MAAkC;CAChC;CACA,4BAA6B,IAAI,IAA0B;CAC3D,OAAsC;CACtC,WAA8C;CAC9C,qBAA6B;CAC7B,uBAA+B;CAC/B,qBAA6B;CAC7B,QAAiC;EAC/B,cAAc;EACd,eAAe;EACf,SAAS;EACT,WAAW;EACX,WAAW;EACX,cAAc;EACd,UAAU;EACV,iBAAiB;EACjB,aAAa;CACf;CACA,YAA6B,IAAI,6BAA6B;CAC9D,UAAwC,CAAC;CACzC,sBAA8B;C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MAAM,WAAW,OAAO,GAAG,EAAE;CAC7B,IAAI,CAAC,YAAY,SAAS,OAAO,KAAK,MAAM;EAC1C,OAAO,KAAK,EAAE,GAAG,KAAK,CAAC;EACvB;CACF;CAEA,OAAO,OAAO,SAAS,KAAK;EAC1B,MAAM,SAAS;EACf,IAAI,KAAK;EACT,MAAM,SAAS,OAAO,KAAK;CAC7B;AACF"}
|
package/dist/findIcons.d.ts
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
export declare const FIND_ICONS: {
|
|
2
2
|
readonly caseSensitive: {
|
|
3
|
-
readonly name:
|
|
4
|
-
readonly path:
|
|
3
|
+
readonly name: 'text-a-underline';
|
|
4
|
+
readonly path: 'M60.59,175.24a8,8,0,0,0,10.65-3.83L87.9,136h80.2l16.66,35.41a8,8,0,1,0,14.48-6.82l-64-136a8,8,0,0,0-14.48,0l-64,136A8,8,0,0,0,60.59,175.24ZM128,50.79,160.57,120H95.43ZM224,216a8,8,0,0,1-8,8H40a8,8,0,0,1,0-16H216A8,8,0,0,1,224,216Z';
|
|
5
5
|
};
|
|
6
6
|
readonly close: {
|
|
7
|
-
readonly name:
|
|
8
|
-
readonly path:
|
|
7
|
+
readonly name: 'x';
|
|
8
|
+
readonly path: 'M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z';
|
|
9
9
|
};
|
|
10
10
|
readonly next: {
|
|
11
|
-
readonly name:
|
|
12
|
-
readonly path:
|
|
11
|
+
readonly name: 'caret-down';
|
|
12
|
+
readonly path: 'M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z';
|
|
13
13
|
};
|
|
14
14
|
readonly preserveCase: {
|
|
15
|
-
readonly name:
|
|
16
|
-
readonly path:
|
|
15
|
+
readonly name: 'text-aa';
|
|
16
|
+
readonly path: 'M87.24,52.59a8,8,0,0,0-14.48,0l-64,136a8,8,0,1,0,14.48,6.81L39.9,160h80.2l16.66,35.4a8,8,0,1,0,14.48-6.81ZM47.43,144,80,74.79,112.57,144ZM200,96c-12.76,0-22.73,3.47-29.63,10.32a8,8,0,0,0,11.26,11.36c3.8-3.77,10-5.68,18.37-5.68,13.23,0,24,9,24,20v3.22A42.76,42.76,0,0,0,200,128c-22.06,0-40,16.15-40,36s17.94,36,40,36a42.73,42.73,0,0,0,24-7.25,8,8,0,0,0,16-.75V132C240,112.15,222.06,96,200,96Zm0,88c-13.23,0-24-9-24-20s10.77-20,24-20,24,9,24,20S213.23,184,200,184Z';
|
|
17
17
|
};
|
|
18
18
|
readonly previous: {
|
|
19
|
-
readonly name:
|
|
20
|
-
readonly path:
|
|
19
|
+
readonly name: 'caret-up';
|
|
20
|
+
readonly path: 'M213.66,165.66a8,8,0,0,1-11.32,0L128,91.31,53.66,165.66a8,8,0,0,1-11.32-11.32l80-80a8,8,0,0,1,11.32,0l80,80A8,8,0,0,1,213.66,165.66Z';
|
|
21
21
|
};
|
|
22
22
|
readonly regex: {
|
|
23
|
-
readonly name:
|
|
24
|
-
readonly path:
|
|
23
|
+
readonly name: 'asterisk';
|
|
24
|
+
readonly path: 'M214.86,180.12a8,8,0,0,1-11,2.74L136,142.13V216a8,8,0,0,1-16,0V142.13L52.12,182.86a8,8,0,1,1-8.23-13.72L112.45,128,43.89,86.86a8,8,0,1,1,8.23-13.72L120,113.87V40a8,8,0,0,1,16,0v73.87l67.88-40.73a8,8,0,1,1,8.23,13.72L143.55,128l68.56,41.14A8,8,0,0,1,214.86,180.12Z';
|
|
25
25
|
};
|
|
26
26
|
readonly replace: {
|
|
27
|
-
readonly name:
|
|
28
|
-
readonly path:
|
|
27
|
+
readonly name: 'swap';
|
|
28
|
+
readonly path: 'M224,48V152a16,16,0,0,1-16,16H99.31l10.35,10.34a8,8,0,0,1-11.32,11.32l-24-24a8,8,0,0,1,0-11.32l24-24a8,8,0,0,1,11.32,11.32L99.31,152H208V48H96v8a8,8,0,0,1-16,0V48A16,16,0,0,1,96,32H208A16,16,0,0,1,224,48ZM168,192a8,8,0,0,0-8,8v8H48V104H156.69l-10.35,10.34a8,8,0,0,0,11.32,11.32l24-24a8,8,0,0,0,0-11.32l-24-24a8,8,0,0,0-11.32,11.32L156.69,88H48a16,16,0,0,0-16,16V208a16,16,0,0,0,16,16H160a16,16,0,0,0,16-16v-8A8,8,0,0,0,168,192Z';
|
|
29
29
|
};
|
|
30
30
|
readonly replaceAll: {
|
|
31
|
-
readonly name:
|
|
32
|
-
readonly path:
|
|
31
|
+
readonly name: 'arrows-clockwise';
|
|
32
|
+
readonly path: 'M224,48V96a8,8,0,0,1-8,8H168a8,8,0,0,1,0-16h28.69L182.06,73.37a79.56,79.56,0,0,0-56.13-23.43h-.45A79.52,79.52,0,0,0,69.59,72.71,8,8,0,0,1,58.41,61.27a96,96,0,0,1,135,.79L208,76.69V48a8,8,0,0,1,16,0ZM186.41,183.29a80,80,0,0,1-112.47-.66L59.31,168H88a8,8,0,0,0,0-16H40a8,8,0,0,0-8,8v48a8,8,0,0,0,16,0V179.31l14.63,14.63A95.43,95.43,0,0,0,130,222.06h.53a95.36,95.36,0,0,0,67.07-27.33,8,8,0,0,0-11.18-11.44Z';
|
|
33
33
|
};
|
|
34
34
|
readonly replaceToggle: {
|
|
35
|
-
readonly name:
|
|
36
|
-
readonly path:
|
|
35
|
+
readonly name: 'caret-right';
|
|
36
|
+
readonly path: 'M181.66,133.66l-80,80a8,8,0,0,1-11.32-11.32L164.69,128,90.34,53.66a8,8,0,0,1,11.32-11.32l80,80A8,8,0,0,1,181.66,133.66Z';
|
|
37
37
|
};
|
|
38
38
|
readonly scope: {
|
|
39
|
-
readonly name:
|
|
40
|
-
readonly path:
|
|
39
|
+
readonly name: 'selection';
|
|
40
|
+
readonly path: 'M152,40a8,8,0,0,1-8,8H112a8,8,0,0,1,0-16h32A8,8,0,0,1,152,40Zm-8,168H112a8,8,0,0,0,0,16h32a8,8,0,0,0,0-16ZM208,32H184a8,8,0,0,0,0,16h24V72a8,8,0,0,0,16,0V48A16,16,0,0,0,208,32Zm8,72a8,8,0,0,0-8,8v32a8,8,0,0,0,16,0V112A8,8,0,0,0,216,104Zm0,72a8,8,0,0,0-8,8v24H184a8,8,0,0,0,0,16h24a16,16,0,0,0,16-16V184A8,8,0,0,0,216,176ZM40,152a8,8,0,0,0,8-8V112a8,8,0,0,0-16,0v32A8,8,0,0,0,40,152Zm32,56H48V184a8,8,0,0,0-16,0v24a16,16,0,0,0,16,16H72a8,8,0,0,0,0-16ZM72,32H48A16,16,0,0,0,32,48V72a8,8,0,0,0,16,0V48H72a8,8,0,0,0,0-16Z';
|
|
41
41
|
};
|
|
42
42
|
readonly wholeWord: {
|
|
43
|
-
readonly name:
|
|
44
|
-
readonly path:
|
|
43
|
+
readonly name: 'textbox';
|
|
44
|
+
readonly path: 'M112,40a8,8,0,0,0-8,8V64H24A16,16,0,0,0,8,80v96a16,16,0,0,0,16,16h80v16a8,8,0,0,0,16,0V48A8,8,0,0,0,112,40ZM24,176V80h80v96ZM248,80v96a16,16,0,0,1-16,16H144a8,8,0,0,1,0-16h88V80H144a8,8,0,0,1,0-16h88A16,16,0,0,1,248,80ZM88,112a8,8,0,0,1-8,8H72v24a8,8,0,0,1-16,0V120H48a8,8,0,0,1,0-16H80A8,8,0,0,1,88,112Z';
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
47
|
export type FindIcon = (typeof FIND_ICONS)[keyof typeof FIND_ICONS];
|
package/dist/findIcons.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findIcons.d.ts","sourceRoot":"","sources":["../src/findIcons.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU
|
|
1
|
+
{"version":3,"file":"findIcons.d.ts","sourceRoot":"","sources":["../src/findIcons.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU;aACrB,aAAa;iBACX,IAAI,EAAE,kBAAkB;iBACxB,IAAI,EAAE,wOAAwO;;aAEhP,KAAK;iBACH,IAAI,EAAE,GAAG;iBACT,IAAI,EAAE,0LAA0L;;aAElM,IAAI;iBACF,IAAI,EAAE,YAAY;iBAClB,IAAI,EAAE,oHAAoH;;aAE5H,YAAY;iBACV,IAAI,EAAE,SAAS;iBACf,IAAI,EAAE,gdAAgd;;aAExd,QAAQ;iBACN,IAAI,EAAE,UAAU;iBAChB,IAAI,EAAE,sIAAsI;;aAE9I,KAAK;iBACH,IAAI,EAAE,UAAU;iBAChB,IAAI,EAAE,yQAAyQ;;aAEjR,OAAO;iBACL,IAAI,EAAE,MAAM;iBACZ,IAAI,EAAE,6aAA6a;;aAErb,UAAU;iBACR,IAAI,EAAE,kBAAkB;iBACxB,IAAI,EAAE,qZAAqZ;;aAE7Z,aAAa;iBACX,IAAI,EAAE,aAAa;iBACnB,IAAI,EAAE,yHAAyH;;aAEjI,KAAK;iBACH,IAAI,EAAE,WAAW;iBACjB,IAAI,EAAE,ugBAAugB;;aAE/gB,SAAS;iBACP,IAAI,EAAE,SAAS;iBACf,IAAI,EAAE,kTAAkT;;CAElT,CAAA;AAEV,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AAInE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,aAAa,CAWhF"}
|
package/dist/findIcons.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/findIcons.ts
|
|
2
2
|
var FIND_ICON_VIEW_BOX = "0 0 256 256";
|
|
3
3
|
var FIND_ICONS = {
|
|
4
4
|
caseSensitive: {
|
|
@@ -59,7 +59,6 @@ function createFindIcon(document, icon) {
|
|
|
59
59
|
svg.appendChild(path);
|
|
60
60
|
return svg;
|
|
61
61
|
}
|
|
62
|
-
//#endregion
|
|
63
62
|
export { FIND_ICONS, createFindIcon };
|
|
64
63
|
|
|
65
64
|
//# sourceMappingURL=findIcons.js.map
|
package/dist/findWidget.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import './style.css';
|
|
2
|
+
import type { EditorViewContributionContext } from '@singapore-editor/core/extensions';
|
|
1
3
|
import type { EditorFindWidgetState } from './findController';
|
|
2
4
|
export type EditorFindWidgetOptions = {
|
|
5
|
+
readonly registerKeymapNode?: EditorViewContributionContext['registerKeymapNode'];
|
|
3
6
|
readonly onSearchInput: (value: string) => void;
|
|
4
7
|
readonly onReplaceInput: (value: string) => void;
|
|
5
8
|
readonly onToggleReplace: () => void;
|
|
@@ -17,6 +20,7 @@ export type EditorFindWidgetOptions = {
|
|
|
17
20
|
export declare class EditorFindWidget {
|
|
18
21
|
private readonly themeSource;
|
|
19
22
|
private readonly options;
|
|
23
|
+
private readonly hotkeys;
|
|
20
24
|
private readonly root;
|
|
21
25
|
private readonly findInput;
|
|
22
26
|
private readonly replaceInput;
|
|
@@ -40,6 +44,5 @@ export declare class EditorFindWidget {
|
|
|
40
44
|
private findRow;
|
|
41
45
|
private findInputFrame;
|
|
42
46
|
private installHandlers;
|
|
43
|
-
private handleKeyDown;
|
|
44
47
|
}
|
|
45
48
|
//# sourceMappingURL=findWidget.d.ts.map
|
package/dist/findWidget.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findWidget.d.ts","sourceRoot":"","sources":["../src/findWidget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAU7D,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/C,QAAQ,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CA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CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE3C;IAEM,MAAM,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI,CAgBhD;IAEM,cAAc,IAAI,IAAI,CAG5B;IAEM,iBAAiB,IAAI,IAAI,CAG/B;IAEM,OAAO,IAAI,IAAI,CAGrB;IAED,OAAO,CAAC,KAAK;IA4Bb,OAAO,CAAC,OAAO;IAqBf,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,eAAe;CAiCxB"}
|
package/dist/findWidget.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FIND_MATCHES_LIMIT } from "./search.js";
|
|
2
2
|
import { FIND_ICONS, createFindIcon } from "./findIcons.js";
|
|
3
|
-
|
|
3
|
+
import { createEditorWidgetKeymap } from "@singapore-editor/core/extensions";
|
|
4
|
+
import "./style.css";
|
|
5
|
+
// src/findWidget.ts
|
|
4
6
|
var EDITOR_THEME_VARIABLES = [
|
|
5
7
|
"--editor-background",
|
|
6
8
|
"--editor-foreground",
|
|
@@ -9,6 +11,7 @@ var EDITOR_THEME_VARIABLES = [
|
|
|
9
11
|
var EditorFindWidget = class {
|
|
10
12
|
themeSource;
|
|
11
13
|
options;
|
|
14
|
+
hotkeys = [];
|
|
12
15
|
root;
|
|
13
16
|
findInput;
|
|
14
17
|
replaceInput;
|
|
@@ -75,6 +78,7 @@ var EditorFindWidget = class {
|
|
|
75
78
|
this.replaceInput.select();
|
|
76
79
|
}
|
|
77
80
|
dispose() {
|
|
81
|
+
for (const registration of this.hotkeys) registration.dispose();
|
|
78
82
|
this.root.remove();
|
|
79
83
|
}
|
|
80
84
|
build(document) {
|
|
@@ -117,7 +121,27 @@ var EditorFindWidget = class {
|
|
|
117
121
|
return frame;
|
|
118
122
|
}
|
|
119
123
|
installHandlers() {
|
|
120
|
-
this.
|
|
124
|
+
const standalone = this.options.registerKeymapNode ? null : createEditorWidgetKeymap(this.root);
|
|
125
|
+
if (standalone) this.hotkeys.push(standalone);
|
|
126
|
+
const register = this.options.registerKeymapNode ?? standalone?.registerKeymapNode;
|
|
127
|
+
if (register) {
|
|
128
|
+
const commands = {
|
|
129
|
+
closeFind: () => this.options.onClose(),
|
|
130
|
+
findNext: () => this.options.onNext(),
|
|
131
|
+
findPrevious: () => this.options.onPrevious(),
|
|
132
|
+
replaceOne: () => this.options.onReplaceOne()
|
|
133
|
+
};
|
|
134
|
+
this.hotkeys.push(register({
|
|
135
|
+
element: this.root,
|
|
136
|
+
context: "EditorWidget FindWidget",
|
|
137
|
+
commands
|
|
138
|
+
}));
|
|
139
|
+
this.hotkeys.push(register({
|
|
140
|
+
element: this.replaceInput,
|
|
141
|
+
context: "EditorWidget FindWidget ReplaceInput",
|
|
142
|
+
commands
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
121
145
|
this.findInput.addEventListener("input", () => this.options.onSearchInput(this.findInput.value));
|
|
122
146
|
this.replaceInput.addEventListener("input", () => this.options.onReplaceInput(this.replaceInput.value));
|
|
123
147
|
this.caseButton.addEventListener("click", this.options.onToggleCase);
|
|
@@ -127,22 +151,6 @@ var EditorFindWidget = class {
|
|
|
127
151
|
this.scopeButton.addEventListener("click", this.options.onToggleScope);
|
|
128
152
|
this.preserveButton.addEventListener("click", this.options.onTogglePreserveCase);
|
|
129
153
|
}
|
|
130
|
-
handleKeyDown(event) {
|
|
131
|
-
event.stopPropagation();
|
|
132
|
-
if ([isFindToggleKey(event), event.key === "Escape"].some(Boolean)) {
|
|
133
|
-
event.preventDefault();
|
|
134
|
-
this.options.onClose();
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (event.key !== "Enter") return;
|
|
138
|
-
event.preventDefault();
|
|
139
|
-
if (event.target === this.replaceInput && !event.shiftKey) {
|
|
140
|
-
this.options.onReplaceOne();
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (event.shiftKey) this.options.onPrevious();
|
|
144
|
-
else this.options.onNext();
|
|
145
|
-
}
|
|
146
154
|
};
|
|
147
155
|
function createFindButton(document, icon, title, onClick) {
|
|
148
156
|
const button = document.createElement("button");
|
|
@@ -175,11 +183,6 @@ function setNativeTooltip(element, value) {
|
|
|
175
183
|
element.title = value;
|
|
176
184
|
element.setAttribute("aria-label", value);
|
|
177
185
|
}
|
|
178
|
-
function isFindToggleKey(event) {
|
|
179
|
-
if (event.key.toLowerCase() !== "f") return false;
|
|
180
|
-
if (event.altKey || event.shiftKey) return false;
|
|
181
|
-
return event.metaKey || event.ctrlKey;
|
|
182
|
-
}
|
|
183
186
|
function toggleTooltip(label, active) {
|
|
184
187
|
return active ? `${label} (On)` : `${label} (Off)`;
|
|
185
188
|
}
|
|
@@ -188,7 +191,6 @@ function resultCountText(position, count) {
|
|
|
188
191
|
return `${position || "?"} of ${count}`;
|
|
189
192
|
}
|
|
190
193
|
var 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.`;
|
|
191
|
-
//#endregion
|
|
192
194
|
export { EditorFindWidget };
|
|
193
195
|
|
|
194
196
|
//# sourceMappingURL=findWidget.js.map
|