@xterm/addon-search 0.16.0-beta.98 → 0.16.0
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/lib/addon-search.js +1 -1
- package/lib/addon-search.js.map +1 -1
- package/lib/addon-search.mjs +13 -13
- package/lib/addon-search.mjs.map +4 -4
- package/package.json +2 -5
- package/src/DecorationManager.ts +157 -0
- package/src/SearchAddon.ts +110 -620
- package/src/SearchEngine.ts +394 -0
- package/src/SearchLineCache.ts +114 -0
- package/src/SearchResultTracker.ts +119 -0
- package/src/SearchState.ts +106 -0
- package/typings/addon-search.d.ts +16 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ISearchOptions } from '@xterm/addon-search';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Manages search state including cached search terms, options tracking, and validation.
|
|
10
|
+
* This class provides a centralized way to handle search state consistency and option changes.
|
|
11
|
+
*/
|
|
12
|
+
export class SearchState {
|
|
13
|
+
private _cachedSearchTerm: string | undefined;
|
|
14
|
+
private _lastSearchOptions: ISearchOptions | undefined;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Gets the currently cached search term.
|
|
18
|
+
*/
|
|
19
|
+
public get cachedSearchTerm(): string | undefined {
|
|
20
|
+
return this._cachedSearchTerm;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Sets the cached search term.
|
|
25
|
+
*/
|
|
26
|
+
public set cachedSearchTerm(term: string | undefined) {
|
|
27
|
+
this._cachedSearchTerm = term;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Gets the last search options used.
|
|
32
|
+
*/
|
|
33
|
+
public get lastSearchOptions(): ISearchOptions | undefined {
|
|
34
|
+
return this._lastSearchOptions;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Sets the last search options used.
|
|
39
|
+
*/
|
|
40
|
+
public set lastSearchOptions(options: ISearchOptions | undefined) {
|
|
41
|
+
this._lastSearchOptions = options;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Validates a search term to ensure it's not empty or invalid.
|
|
46
|
+
* @param term The search term to validate.
|
|
47
|
+
* @returns true if the term is valid for searching.
|
|
48
|
+
*/
|
|
49
|
+
public isValidSearchTerm(term: string): boolean {
|
|
50
|
+
return !!(term && term.length > 0);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Determines if search options have changed compared to the last search.
|
|
55
|
+
* @param newOptions The new search options to compare.
|
|
56
|
+
* @returns true if the options have changed.
|
|
57
|
+
*/
|
|
58
|
+
public didOptionsChange(newOptions?: ISearchOptions): boolean {
|
|
59
|
+
if (!this._lastSearchOptions) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (!newOptions) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (this._lastSearchOptions.caseSensitive !== newOptions.caseSensitive) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (this._lastSearchOptions.regex !== newOptions.regex) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (this._lastSearchOptions.wholeWord !== newOptions.wholeWord) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Determines if a new search should trigger highlighting updates.
|
|
79
|
+
* @param term The search term.
|
|
80
|
+
* @param options The search options.
|
|
81
|
+
* @returns true if highlighting should be updated.
|
|
82
|
+
*/
|
|
83
|
+
public shouldUpdateHighlighting(term: string, options?: ISearchOptions): boolean {
|
|
84
|
+
if (!options?.decorations) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return this._cachedSearchTerm === undefined ||
|
|
88
|
+
term !== this._cachedSearchTerm ||
|
|
89
|
+
this.didOptionsChange(options);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Clears the cached search term.
|
|
94
|
+
*/
|
|
95
|
+
public clearCachedTerm(): void {
|
|
96
|
+
this._cachedSearchTerm = undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Resets all state.
|
|
101
|
+
*/
|
|
102
|
+
public reset(): void {
|
|
103
|
+
this._cachedSearchTerm = undefined;
|
|
104
|
+
this._lastSearchOptions = undefined;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -75,6 +75,21 @@ declare module '@xterm/addon-search' {
|
|
|
75
75
|
activeMatchColorOverviewRuler: string;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Event data fired when search results change.
|
|
80
|
+
*/
|
|
81
|
+
export interface ISearchResultChangeEvent {
|
|
82
|
+
/**
|
|
83
|
+
* The index of the currently active result, -1 when the threshold of matches is exceeded.
|
|
84
|
+
*/
|
|
85
|
+
resultIndex: number;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The total number of search results found.
|
|
89
|
+
*/
|
|
90
|
+
resultCount: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
78
93
|
/**
|
|
79
94
|
* Options for the search addon.
|
|
80
95
|
*/
|
|
@@ -139,8 +154,7 @@ declare module '@xterm/addon-search' {
|
|
|
139
154
|
/**
|
|
140
155
|
* When decorations are enabled, fires when
|
|
141
156
|
* the search results change.
|
|
142
|
-
* @returns -1 for resultIndex when the threshold of matches is exceeded.
|
|
143
157
|
*/
|
|
144
|
-
readonly onDidChangeResults: IEvent<
|
|
158
|
+
readonly onDidChangeResults: IEvent<ISearchResultChangeEvent>;
|
|
145
159
|
}
|
|
146
160
|
}
|