@singapore-editor/find 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/dist/findController.d.ts +175 -0
- package/dist/findController.d.ts.map +1 -0
- package/dist/findController.js +681 -0
- package/dist/findController.js.map +1 -0
- package/dist/findIcons.d.ts +49 -0
- package/dist/findIcons.d.ts.map +1 -0
- package/dist/findIcons.js +65 -0
- package/dist/findIcons.js.map +1 -0
- package/dist/findWidget.d.ts +45 -0
- package/dist/findWidget.d.ts.map +1 -0
- package/dist/findWidget.js +194 -0
- package/dist/findWidget.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/plugin.d.ts +14 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +408 -0
- package/dist/plugin.js.map +1 -0
- package/dist/replacePattern.d.ts +18 -0
- package/dist/replacePattern.d.ts.map +1 -0
- package/dist/replacePattern.js +212 -0
- package/dist/replacePattern.js.map +1 -0
- package/dist/search.d.ts +83 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +470 -0
- package/dist/search.js.map +1 -0
- package/dist/style.css +198 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @singapore-editor/find
|
|
2
|
+
|
|
3
|
+
Find and replace plugin for `@singapore-editor/core`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @singapore-editor/core @singapore-editor/find
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Editor } from '@singapore-editor/core/editor'
|
|
15
|
+
import { createEditorFindPlugin } from '@singapore-editor/find'
|
|
16
|
+
import '@singapore-editor/core/style.css'
|
|
17
|
+
import '@singapore-editor/find/style.css'
|
|
18
|
+
|
|
19
|
+
const editor = new Editor(document.querySelector('#editor')!, {
|
|
20
|
+
plugins: [createEditorFindPlugin()],
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Exports
|
|
25
|
+
|
|
26
|
+
- `createEditorFindPlugin` registers find, replace, and match-selection commands.
|
|
27
|
+
- `createEditorFindContributionProviders` exposes the find widget and capability providers.
|
|
28
|
+
- `EDITOR_FIND_FEATURE` and `EDITOR_FIND_FEATURE_ID` expose the find feature capability token.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { type TextEdit, type TextReadSnapshot } from '@singapore-editor/core/document';
|
|
2
|
+
import type { EditorSetSelectionOptions } from '@singapore-editor/core/editor';
|
|
3
|
+
import type { EditorContributionChange, EditorDisposable, EditorResolvedSelection, EditorSelectionRange, EditorViewContributionUpdateKind } from '@singapore-editor/core/extensions';
|
|
4
|
+
import type { VirtualizedTextHighlightStyle } from '@singapore-editor/core/rendering';
|
|
5
|
+
import { type FindQuery, type FindRange, type FindTextSource } from './search';
|
|
6
|
+
import type { EditorFindOptions } from './types';
|
|
7
|
+
export declare const FIND_HIGHLIGHT_Z_INDEX: {
|
|
8
|
+
readonly scope: 4;
|
|
9
|
+
readonly match: 5;
|
|
10
|
+
readonly current: 6;
|
|
11
|
+
};
|
|
12
|
+
type EditorFindSelectionRange = EditorSelectionRange;
|
|
13
|
+
export type EditorFindResolvedSelection = EditorResolvedSelection & {
|
|
14
|
+
readonly collapsed: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Ranges the host follows through edits on find's behalf.
|
|
18
|
+
*
|
|
19
|
+
* A scope outlives the selection it was taken from: the first replace inside it moves the caret off
|
|
20
|
+
* that selection, so a scope re-derived from what is selected now would be re-derived from
|
|
21
|
+
* something else — or from nothing, and a scope of nothing is indistinguishable from no scope at
|
|
22
|
+
* all. Handed over once, it answers from wherever its text went, however many edits later.
|
|
23
|
+
*/
|
|
24
|
+
export type FindTrackedRanges = {
|
|
25
|
+
resolve(): readonly FindRange[];
|
|
26
|
+
};
|
|
27
|
+
export type EditorFindHost = {
|
|
28
|
+
hasDocument(): boolean;
|
|
29
|
+
textSource(): FindTextSource;
|
|
30
|
+
hasTextSnapshot(snapshot: TextReadSnapshot): boolean;
|
|
31
|
+
trackRanges(ranges: readonly FindRange[]): FindTrackedRanges;
|
|
32
|
+
trackPaintedRanges(ranges: readonly FindRange[]): FindTrackedRanges;
|
|
33
|
+
getSelections(): readonly EditorFindResolvedSelection[];
|
|
34
|
+
focusEditor(): void;
|
|
35
|
+
announce(message: string): void;
|
|
36
|
+
setSelection(anchor: number, head: number, timingName: string, options?: EditorSetSelectionOptions): void;
|
|
37
|
+
setSelections(selections: readonly EditorFindSelectionRange[], timingName: string, revealOffset?: number): void;
|
|
38
|
+
setRangeHighlight(name: string, ranges: readonly FindRange[], style: VirtualizedTextHighlightStyle): void;
|
|
39
|
+
clearRangeHighlight(name: string): void;
|
|
40
|
+
};
|
|
41
|
+
export type EditorFindEditHost = {
|
|
42
|
+
textSnapshot(): TextReadSnapshot | null;
|
|
43
|
+
getSelections(): readonly EditorFindResolvedSelection[];
|
|
44
|
+
applyEdits(edits: readonly TextEdit[], timingName: string, selection?: EditorFindSelectionRange): void;
|
|
45
|
+
};
|
|
46
|
+
export type EditorFindStartOptions = {
|
|
47
|
+
readonly replace: boolean;
|
|
48
|
+
readonly focus: 'find' | 'replace' | 'none';
|
|
49
|
+
};
|
|
50
|
+
export type EditorFindState = FindQuery & {
|
|
51
|
+
readonly replaceString: string;
|
|
52
|
+
readonly preserveCase: boolean;
|
|
53
|
+
readonly revealed: boolean;
|
|
54
|
+
readonly replaceRevealed: boolean;
|
|
55
|
+
readonly inSelection: boolean;
|
|
56
|
+
};
|
|
57
|
+
export type EditorFindWidgetState = EditorFindState & {
|
|
58
|
+
readonly matchesCount: number;
|
|
59
|
+
readonly matchesPosition: number;
|
|
60
|
+
readonly highlightsTruncated: boolean;
|
|
61
|
+
};
|
|
62
|
+
export type EditorFindUiEvent = {
|
|
63
|
+
readonly type: 'show';
|
|
64
|
+
readonly replaceVisible: boolean;
|
|
65
|
+
} | {
|
|
66
|
+
readonly type: 'hide';
|
|
67
|
+
} | {
|
|
68
|
+
readonly type: 'focus';
|
|
69
|
+
readonly target: 'find' | 'replace';
|
|
70
|
+
} | {
|
|
71
|
+
readonly type: 'update';
|
|
72
|
+
readonly state: EditorFindWidgetState;
|
|
73
|
+
};
|
|
74
|
+
type EditorFindUiListener = (event: EditorFindUiEvent) => void;
|
|
75
|
+
export declare class EditorFindController {
|
|
76
|
+
private readonly options;
|
|
77
|
+
private readonly listeners;
|
|
78
|
+
private host;
|
|
79
|
+
private editHost;
|
|
80
|
+
private matchHighlightName;
|
|
81
|
+
private currentHighlightName;
|
|
82
|
+
private scopeHighlightName;
|
|
83
|
+
private state;
|
|
84
|
+
private readonly scheduler;
|
|
85
|
+
private matches;
|
|
86
|
+
private highlightsTruncated;
|
|
87
|
+
private totalMatches;
|
|
88
|
+
private scope;
|
|
89
|
+
private trackedMatches;
|
|
90
|
+
private currentMatch;
|
|
91
|
+
private replacing;
|
|
92
|
+
private pendingResearch;
|
|
93
|
+
constructor(options?: EditorFindOptions);
|
|
94
|
+
attachHost(host: EditorFindHost, highlightPrefix: string): EditorDisposable;
|
|
95
|
+
attachEditHost(host: EditorFindEditHost): EditorDisposable;
|
|
96
|
+
subscribe(listener: EditorFindUiListener): EditorDisposable;
|
|
97
|
+
dispose(): void;
|
|
98
|
+
isVisible(): boolean;
|
|
99
|
+
openFind(): boolean;
|
|
100
|
+
toggleFind(): boolean;
|
|
101
|
+
openFindReplace(): boolean;
|
|
102
|
+
close(): boolean;
|
|
103
|
+
findNext(): boolean;
|
|
104
|
+
findPrevious(): boolean;
|
|
105
|
+
replaceOne(): boolean;
|
|
106
|
+
replaceAll(): boolean;
|
|
107
|
+
selectAllMatches(): boolean;
|
|
108
|
+
toggleMatchCase(): boolean;
|
|
109
|
+
toggleWholeWord(): boolean;
|
|
110
|
+
toggleRegex(): boolean;
|
|
111
|
+
togglePreserveCase(): boolean;
|
|
112
|
+
toggleReplace(): boolean;
|
|
113
|
+
toggleFindInSelection(): boolean;
|
|
114
|
+
setSearchString(value: string): void;
|
|
115
|
+
setReplaceString(value: string): void;
|
|
116
|
+
handleViewUpdate(kind: EditorViewContributionUpdateKind, change: EditorContributionChange | null): void;
|
|
117
|
+
private detachHost;
|
|
118
|
+
private detachEditHost;
|
|
119
|
+
private open;
|
|
120
|
+
private ensureFindReady;
|
|
121
|
+
private research;
|
|
122
|
+
private scheduleResearch;
|
|
123
|
+
/**
|
|
124
|
+
* Adopts a match set and hands it to the host to follow as far as it is painted.
|
|
125
|
+
*
|
|
126
|
+
* Handed over now rather than when an edit arrives: find is told about an edit
|
|
127
|
+
* once the text has already moved, and a range recorded against the document
|
|
128
|
+
* as it is by then is a range that will never shift.
|
|
129
|
+
*
|
|
130
|
+
* What the reader can see is the bound. A set stopping at the paint cap holds
|
|
131
|
+
* twenty thousand matches, and asking the host to carry all of them costs more
|
|
132
|
+
* per keystroke than the search this deferral exists to keep off it.
|
|
133
|
+
*/
|
|
134
|
+
private adoptMatches;
|
|
135
|
+
/**
|
|
136
|
+
* Carries the painted matches through the edit that deferred their re-search.
|
|
137
|
+
*
|
|
138
|
+
* Until it lands they are what the reader sees, and the offsets they were found
|
|
139
|
+
* at address text that has since moved — so they are read back from where that
|
|
140
|
+
* text went. A match whose text is gone resolves to nothing and stops being
|
|
141
|
+
* painted.
|
|
142
|
+
*/
|
|
143
|
+
/** Takes the offsets again from what the host is following, after the line it follows to moved. */
|
|
144
|
+
refreshTrackedMatches(): void;
|
|
145
|
+
private followPendingMatches;
|
|
146
|
+
private applyReplacement;
|
|
147
|
+
private selectNextReplacementMatch;
|
|
148
|
+
private canPaintCurrentDocument;
|
|
149
|
+
private commandTextSource;
|
|
150
|
+
private commandSelections;
|
|
151
|
+
private commandSearchTarget;
|
|
152
|
+
private findAll;
|
|
153
|
+
private countAll;
|
|
154
|
+
private searchFrom;
|
|
155
|
+
private searchTarget;
|
|
156
|
+
private scopeRanges;
|
|
157
|
+
private selectFirstMatchFromSelection;
|
|
158
|
+
private nextMatchAt;
|
|
159
|
+
private selectMatch;
|
|
160
|
+
private updateHighlights;
|
|
161
|
+
private currentMatchRanges;
|
|
162
|
+
private clearHighlights;
|
|
163
|
+
private updateWidget;
|
|
164
|
+
private widgetState;
|
|
165
|
+
private currentMatchPosition;
|
|
166
|
+
private focusWidget;
|
|
167
|
+
private seedSearchString;
|
|
168
|
+
private seedFromLiteralText;
|
|
169
|
+
private applyAutoFindInSelection;
|
|
170
|
+
private replacePattern;
|
|
171
|
+
private primarySelection;
|
|
172
|
+
private emit;
|
|
173
|
+
}
|
|
174
|
+
export {};
|
|
175
|
+
//# sourceMappingURL=findController.d.ts.map
|
|
@@ -0,0 +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;;;;CAIzB,CAAA;AAyCV,KAAK,wBAAwB,GAAG,oBAAoB,CAAA;AAEpD,MAAM,MAAM,2BAA2B,GAAG,uBAAu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