quick and dirty search and replace

This commit is contained in:
Chris Kruining 2025-02-25 17:02:11 +11:00
parent fc22ce6027
commit 5f6138d30b
No known key found for this signature in database
GPG key ID: EB894A3560CCCAD2
6 changed files with 36 additions and 83 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

View file

@ -7,11 +7,14 @@ import { createMap } from './map';
import { splice } from "~/utilities";
import rehypeParse from "rehype-parse";
type Editor = [Accessor<string>];
type Editor = [Accessor<string>, { select(range: Range): void, mutate(setter: (text: string) => string): void }];
export function createEditor(ref: Accessor<Element | undefined>, value: Accessor<string>): Editor {
if (isServer) {
return [value];
return [value, {
select(range) { },
mutate() { },
}];
}
if (!("EditContext" in window)) {
@ -187,7 +190,17 @@ export function createEditor(ref: Accessor<Element | undefined>, value: Accessor
}
});
return [createMemo(() => store.text)];
return [
createMemo(() => store.text),
{
select(range: Range) {
updateSelection(range);
},
mutate(setter) {
setStore('text', setter);
},
}];
}
const equals = (a: Range, b: Range): boolean => {