RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { SearchQuery } from "@codemirror/search";
|
||||
|
||||
/** Commands for the shared document search controls. */
|
||||
export interface FindTarget {
|
||||
query: SearchQuery;
|
||||
readOnly: boolean;
|
||||
canSelectAll?: boolean;
|
||||
setQuery(query: SearchQuery): void;
|
||||
next(backward?: boolean): void;
|
||||
selectAll(): void;
|
||||
replace(all?: boolean): void;
|
||||
close(): void;
|
||||
keydown?(event: KeyboardEvent): boolean;
|
||||
}
|
||||
|
||||
export function documentMatches(source: string, query: SearchQuery) {
|
||||
const state = EditorState.create({ doc: source });
|
||||
const matches: { from: number; to: number }[] = [];
|
||||
if (query.valid) {
|
||||
const cursor = query.getCursor(state);
|
||||
for (let match = cursor.next(); !match.done; match = cursor.next()) matches.push(match.value);
|
||||
}
|
||||
return { state, matches };
|
||||
}
|
||||
Reference in New Issue
Block a user