| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- diff --git a/dist/index.cjs b/dist/index.cjs
- index 46231ae..fb0f9aa 100644
- --- a/dist/index.cjs
- +++ b/dist/index.cjs
- @@ -592,6 +592,7 @@ class SearchQuery {
- this.valid = !!this.search && (!this.regexp || validRegExp(this.search));
- this.unquoted = this.unquote(this.search);
- this.wholeWord = !!config.wholeWord;
- + this.scope = config.scope;
- }
- /**
- @internal
- @@ -606,7 +607,7 @@ class SearchQuery {
- eq(other) {
- return this.search == other.search && this.replace == other.replace &&
- this.caseSensitive == other.caseSensitive && this.regexp == other.regexp &&
- - this.wholeWord == other.wholeWord;
- + this.wholeWord == other.wholeWord && this.scope == other.scope;
- }
- /**
- @internal
- @@ -631,7 +632,12 @@ class QueryType {
- }
- }
- function stringCursor(spec, state, from, to) {
- - return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined);
- + const test = spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined;
- + const testWithinScope = (from, to, buffer, bufferPos) => {
- + return (!test || test(from, to, buffer, bufferPos))
- + && (!spec.scope || spec.scope.some(range => from >= range.from && from <= range.to && to >= range.from && to <= range.to));
- + };
- + return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), testWithinScope);
- }
- function stringWordTest(doc, categorizer) {
- return (from, to, buf, bufPos) => {
- @@ -695,9 +701,14 @@ class StringQuery extends QueryType {
- }
- }
- function regexpCursor(spec, state, from, to) {
- + const test = spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined;
- + const testWithinScope = (from, to, match) => {
- + return (!test || test(from, to, match))
- + && (!spec.scope || spec.scope.some(range => from >= range.from && from <= range.to && to >= range.from && to <= range.to));
- + };
- return new RegExpCursor(state.doc, spec.search, {
- ignoreCase: !spec.caseSensitive,
- - test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined
- + test: testWithinScope,
- }, from, to);
- }
- function charBefore(str, index) {
- @@ -737,10 +748,18 @@ class RegExpQuery extends QueryType {
- this.prevMatchInRange(state, curTo, state.doc.length);
- }
- getReplacement(result) {
- - return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$"
- - : i == "&" ? result.match[0]
- - : i != "0" && +i < result.match.length ? result.match[i]
- - : m);
- + return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g, (m, i) => {
- + if (i == "&")
- + return result.match[0];
- + if (i == "$")
- + return "$";
- + for (let l = i.length; l > 0; l--) {
- + let n = +i.slice(0, l);
- + if (n > 0 && n < result.match.length)
- + return result.match[n] + i.slice(l);
- + }
- + return m;
- + });
- }
- matchAll(state, limit) {
- let cursor = regexpCursor(this.spec, state, 0, state.doc.length), ranges = [];
- @@ -1227,7 +1246,9 @@ const searchExtensions = [
- exports.RegExpCursor = RegExpCursor;
- exports.SearchCursor = SearchCursor;
- exports.SearchQuery = SearchQuery;
- +exports.StringQuery = StringQuery;
- exports.closeSearchPanel = closeSearchPanel;
- +exports.createSearchPanel = createSearchPanel;
- exports.findNext = findNext;
- exports.findPrevious = findPrevious;
- exports.getSearchQuery = getSearchQuery;
- @@ -1242,4 +1263,6 @@ exports.searchPanelOpen = searchPanelOpen;
- exports.selectMatches = selectMatches;
- exports.selectNextOccurrence = selectNextOccurrence;
- exports.selectSelectionMatches = selectSelectionMatches;
- +exports.selectWord = selectWord;
- exports.setSearchQuery = setSearchQuery;
- +exports.togglePanel = togglePanel;
- diff --git a/dist/index.d.cts b/dist/index.d.cts
- index 08f5696..663d192 100644
- --- a/dist/index.d.cts
- +++ b/dist/index.d.cts
- @@ -1,6 +1,6 @@
- import * as _codemirror_state from '@codemirror/state';
- import { Text, Extension, StateCommand, EditorState, SelectionRange, StateEffect } from '@codemirror/state';
- -import { Command, KeyBinding, EditorView, Panel } from '@codemirror/view';
- +import { Command, EditorView, Panel, KeyBinding } from '@codemirror/view';
-
- /**
- A search cursor provides an iterator over text matches in a
- @@ -161,6 +161,7 @@ the `"cm-selectionMatch"` class for the highlighting. When
- itself will be highlighted with `"cm-selectionMatch-main"`.
- */
- declare function highlightSelectionMatches(options?: HighlightOptions): Extension;
- +declare const selectWord: StateCommand;
- /**
- Select next occurrence of the current selection. Expand selection
- to the surrounding word when the selection is empty.
- @@ -264,6 +265,13 @@ declare class SearchQuery {
- */
- readonly wholeWord: boolean;
- /**
- + When set, only include search matches within these ranges
- + */
- + readonly scope?: Readonly<{
- + from: number;
- + to: number;
- + }[]>;
- + /**
- Create a query object.
- */
- constructor(config: {
- @@ -293,6 +301,13 @@ declare class SearchQuery {
- Enable whole-word matching.
- */
- wholeWord?: boolean;
- + /**
- + The ranges to match within
- + */
- + scope?: Readonly<{
- + from: number;
- + to: number;
- + }[]>;
- });
- /**
- Compare this query to another query.
- @@ -307,6 +322,34 @@ declare class SearchQuery {
- to: number;
- }>;
- }
- +type SearchResult = typeof SearchCursor.prototype.value;
- +declare abstract class QueryType<Result extends SearchResult = SearchResult> {
- + readonly spec: SearchQuery;
- + constructor(spec: SearchQuery);
- + abstract nextMatch(state: EditorState, curFrom: number, curTo: number): Result | null;
- + abstract prevMatch(state: EditorState, curFrom: number, curTo: number): Result | null;
- + abstract getReplacement(result: Result): string;
- + abstract matchAll(state: EditorState, limit: number): readonly Result[] | null;
- + abstract highlight(state: EditorState, from: number, to: number, add: (from: number, to: number) => void): void;
- +}
- +declare class StringQuery extends QueryType<SearchResult> {
- + constructor(spec: SearchQuery);
- + nextMatch(state: EditorState, curFrom: number, curTo: number): {
- + from: number;
- + to: number;
- + } | null;
- + private prevMatchInRange;
- + prevMatch(state: EditorState, curFrom: number, curTo: number): {
- + from: number;
- + to: number;
- + } | null;
- + getReplacement(_result: SearchResult): string;
- + matchAll(state: EditorState, limit: number): {
- + from: number;
- + to: number;
- + }[] | null;
- + highlight(state: EditorState, from: number, to: number, add: (from: number, to: number) => void): void;
- +}
- /**
- A state effect that updates the current search query. Note that
- this only has an effect if the search state has been initialized
- @@ -315,6 +358,7 @@ by running [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSea
- once).
- */
- declare const setSearchQuery: _codemirror_state.StateEffectType<SearchQuery>;
- +declare const togglePanel: _codemirror_state.StateEffectType<boolean>;
- /**
- Get the current search query from an editor state.
- */
- @@ -353,6 +397,7 @@ Replace all instances of the search query with the given
- replacement.
- */
- declare const replaceAll: Command;
- +declare function createSearchPanel(view: EditorView): Panel;
- /**
- Make sure the search panel is open and focused.
- */
- @@ -372,4 +417,4 @@ Default search-related key bindings.
- */
- declare const searchKeymap: readonly KeyBinding[];
-
- -export { RegExpCursor, SearchCursor, SearchQuery, closeSearchPanel, findNext, findPrevious, getSearchQuery, gotoLine, highlightSelectionMatches, openSearchPanel, replaceAll, replaceNext, search, searchKeymap, searchPanelOpen, selectMatches, selectNextOccurrence, selectSelectionMatches, setSearchQuery };
- +export { RegExpCursor, SearchCursor, SearchQuery, StringQuery, closeSearchPanel, createSearchPanel, findNext, findPrevious, getSearchQuery, gotoLine, highlightSelectionMatches, openSearchPanel, replaceAll, replaceNext, search, searchKeymap, searchPanelOpen, selectMatches, selectNextOccurrence, selectSelectionMatches, selectWord, setSearchQuery, togglePanel };
- diff --git a/dist/index.d.ts b/dist/index.d.ts
- index 08f5696..663d192 100644
- --- a/dist/index.d.ts
- +++ b/dist/index.d.ts
- @@ -1,6 +1,6 @@
- import * as _codemirror_state from '@codemirror/state';
- import { Text, Extension, StateCommand, EditorState, SelectionRange, StateEffect } from '@codemirror/state';
- -import { Command, KeyBinding, EditorView, Panel } from '@codemirror/view';
- +import { Command, EditorView, Panel, KeyBinding } from '@codemirror/view';
-
- /**
- A search cursor provides an iterator over text matches in a
- @@ -161,6 +161,7 @@ the `"cm-selectionMatch"` class for the highlighting. When
- itself will be highlighted with `"cm-selectionMatch-main"`.
- */
- declare function highlightSelectionMatches(options?: HighlightOptions): Extension;
- +declare const selectWord: StateCommand;
- /**
- Select next occurrence of the current selection. Expand selection
- to the surrounding word when the selection is empty.
- @@ -264,6 +265,13 @@ declare class SearchQuery {
- */
- readonly wholeWord: boolean;
- /**
- + When set, only include search matches within these ranges
- + */
- + readonly scope?: Readonly<{
- + from: number;
- + to: number;
- + }[]>;
- + /**
- Create a query object.
- */
- constructor(config: {
- @@ -293,6 +301,13 @@ declare class SearchQuery {
- Enable whole-word matching.
- */
- wholeWord?: boolean;
- + /**
- + The ranges to match within
- + */
- + scope?: Readonly<{
- + from: number;
- + to: number;
- + }[]>;
- });
- /**
- Compare this query to another query.
- @@ -307,6 +322,34 @@ declare class SearchQuery {
- to: number;
- }>;
- }
- +type SearchResult = typeof SearchCursor.prototype.value;
- +declare abstract class QueryType<Result extends SearchResult = SearchResult> {
- + readonly spec: SearchQuery;
- + constructor(spec: SearchQuery);
- + abstract nextMatch(state: EditorState, curFrom: number, curTo: number): Result | null;
- + abstract prevMatch(state: EditorState, curFrom: number, curTo: number): Result | null;
- + abstract getReplacement(result: Result): string;
- + abstract matchAll(state: EditorState, limit: number): readonly Result[] | null;
- + abstract highlight(state: EditorState, from: number, to: number, add: (from: number, to: number) => void): void;
- +}
- +declare class StringQuery extends QueryType<SearchResult> {
- + constructor(spec: SearchQuery);
- + nextMatch(state: EditorState, curFrom: number, curTo: number): {
- + from: number;
- + to: number;
- + } | null;
- + private prevMatchInRange;
- + prevMatch(state: EditorState, curFrom: number, curTo: number): {
- + from: number;
- + to: number;
- + } | null;
- + getReplacement(_result: SearchResult): string;
- + matchAll(state: EditorState, limit: number): {
- + from: number;
- + to: number;
- + }[] | null;
- + highlight(state: EditorState, from: number, to: number, add: (from: number, to: number) => void): void;
- +}
- /**
- A state effect that updates the current search query. Note that
- this only has an effect if the search state has been initialized
- @@ -315,6 +358,7 @@ by running [`openSearchPanel`](https://codemirror.net/6/docs/ref/#search.openSea
- once).
- */
- declare const setSearchQuery: _codemirror_state.StateEffectType<SearchQuery>;
- +declare const togglePanel: _codemirror_state.StateEffectType<boolean>;
- /**
- Get the current search query from an editor state.
- */
- @@ -353,6 +397,7 @@ Replace all instances of the search query with the given
- replacement.
- */
- declare const replaceAll: Command;
- +declare function createSearchPanel(view: EditorView): Panel;
- /**
- Make sure the search panel is open and focused.
- */
- @@ -372,4 +417,4 @@ Default search-related key bindings.
- */
- declare const searchKeymap: readonly KeyBinding[];
-
- -export { RegExpCursor, SearchCursor, SearchQuery, closeSearchPanel, findNext, findPrevious, getSearchQuery, gotoLine, highlightSelectionMatches, openSearchPanel, replaceAll, replaceNext, search, searchKeymap, searchPanelOpen, selectMatches, selectNextOccurrence, selectSelectionMatches, setSearchQuery };
- +export { RegExpCursor, SearchCursor, SearchQuery, StringQuery, closeSearchPanel, createSearchPanel, findNext, findPrevious, getSearchQuery, gotoLine, highlightSelectionMatches, openSearchPanel, replaceAll, replaceNext, search, searchKeymap, searchPanelOpen, selectMatches, selectNextOccurrence, selectSelectionMatches, selectWord, setSearchQuery, togglePanel };
- diff --git a/dist/index.js b/dist/index.js
- index 22172ef..08a9974 100644
- --- a/dist/index.js
- +++ b/dist/index.js
- @@ -590,6 +590,7 @@ class SearchQuery {
- this.valid = !!this.search && (!this.regexp || validRegExp(this.search));
- this.unquoted = this.unquote(this.search);
- this.wholeWord = !!config.wholeWord;
- + this.scope = config.scope;
- }
- /**
- @internal
- @@ -604,7 +605,7 @@ class SearchQuery {
- eq(other) {
- return this.search == other.search && this.replace == other.replace &&
- this.caseSensitive == other.caseSensitive && this.regexp == other.regexp &&
- - this.wholeWord == other.wholeWord;
- + this.wholeWord == other.wholeWord && this.scope == other.scope;
- }
- /**
- @internal
- @@ -629,7 +630,12 @@ class QueryType {
- }
- }
- function stringCursor(spec, state, from, to) {
- - return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined);
- + const test = spec.wholeWord ? stringWordTest(state.doc, state.charCategorizer(state.selection.main.head)) : undefined;
- + const testWithinScope = (from, to, buffer, bufferPos) => {
- + return (!test || test(from, to, buffer, bufferPos))
- + && (!spec.scope || spec.scope.some(range => from >= range.from && from <= range.to && to >= range.from && to <= range.to));
- + };
- + return new SearchCursor(state.doc, spec.unquoted, from, to, spec.caseSensitive ? undefined : x => x.toLowerCase(), testWithinScope);
- }
- function stringWordTest(doc, categorizer) {
- return (from, to, buf, bufPos) => {
- @@ -693,9 +699,14 @@ class StringQuery extends QueryType {
- }
- }
- function regexpCursor(spec, state, from, to) {
- + const test = spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined;
- + const testWithinScope = (from, to, match) => {
- + return (!test || test(from, to, match))
- + && (!spec.scope || spec.scope.some(range => from >= range.from && from <= range.to && to >= range.from && to <= range.to));
- + };
- return new RegExpCursor(state.doc, spec.search, {
- ignoreCase: !spec.caseSensitive,
- - test: spec.wholeWord ? regexpWordTest(state.charCategorizer(state.selection.main.head)) : undefined
- + test: testWithinScope,
- }, from, to);
- }
- function charBefore(str, index) {
- @@ -735,10 +746,18 @@ class RegExpQuery extends QueryType {
- this.prevMatchInRange(state, curTo, state.doc.length);
- }
- getReplacement(result) {
- - return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g, (m, i) => i == "$" ? "$"
- - : i == "&" ? result.match[0]
- - : i != "0" && +i < result.match.length ? result.match[i]
- - : m);
- + return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g, (m, i) => {
- + if (i == "&")
- + return result.match[0];
- + if (i == "$")
- + return "$";
- + for (let l = i.length; l > 0; l--) {
- + let n = +i.slice(0, l);
- + if (n > 0 && n < result.match.length)
- + return result.match[n] + i.slice(l);
- + }
- + return m;
- + });
- }
- matchAll(state, limit) {
- let cursor = regexpCursor(this.spec, state, 0, state.doc.length), ranges = [];
- @@ -1222,4 +1241,4 @@ const searchExtensions = [
- baseTheme
- ];
-
- -export { RegExpCursor, SearchCursor, SearchQuery, closeSearchPanel, findNext, findPrevious, getSearchQuery, gotoLine, highlightSelectionMatches, openSearchPanel, replaceAll, replaceNext, search, searchKeymap, searchPanelOpen, selectMatches, selectNextOccurrence, selectSelectionMatches, setSearchQuery };
- +export { RegExpCursor, SearchCursor, SearchQuery, StringQuery, closeSearchPanel, createSearchPanel, findNext, findPrevious, getSearchQuery, gotoLine, highlightSelectionMatches, openSearchPanel, replaceAll, replaceNext, search, searchKeymap, searchPanelOpen, selectMatches, selectNextOccurrence, selectSelectionMatches, selectWord, setSearchQuery, togglePanel };
|