Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client: fix an issue
Adorian Dorand844861e4a4f
diff --git a/apps/client/src/widgets/find_in_code.ts b/apps/client/src/widgets/find_in_code.tsindex cac9bd53b2..d36ed7c107 100644--- a/apps/client/src/widgets/find_in_code.ts+++ b/apps/client/src/widgets/find_in_code.ts@@ -130,12 +130,13 @@ export class CodeMirrorFindTarget implements FindTarget {return index >= 0 ? index : null;}+ // `readOnly` blocks typing only, not the changes that `replace()` dispatches.canReplace() {- return true;+ return !this.view.state.readOnly;}async replace(index: number, text: string) {- if (this.isAlive()) {+ if (this.isAlive() && this.canReplace()) {await this.view.findNext(0, 0, index);await this.view.replace(text);}@@ -143,7 +144,7 @@ export class CodeMirrorFindTarget implements FindTarget {}async replaceAll(text: string) {- if (this.isAlive()) {+ if (this.isAlive() && this.canReplace()) {await this.view.replaceAll(text);}return this.searchAgain();diff --git a/apps/client/src/widgets/type_widgets/code/CodeEmbed.spec.tsx b/apps/client/src/widgets/type_widgets/code/CodeEmbed.spec.tsxindex cc8a5bac9c..f2da170327 100644--- a/apps/client/src/widgets/type_widgets/code/CodeEmbed.spec.tsx+++ b/apps/client/src/widgets/type_widgets/code/CodeEmbed.spec.tsx@@ -121,7 +121,7 @@ describe("CodeEmbed", () => {await vi.waitFor(() => expect(view.state.doc.toString()).toBe("print('hi')"));});- it("lets the find search the editor, the read-only one too", async () => {+ it("lets the find search both editors and replace only in the editable one", async () => {const { figure } = await mount(buildCodeNote("print(1)\nprint(2)"), buildEditor(), {isEditable: true});@@ -154,7 +154,7 @@ describe("CodeEmbed", () => {delete figure.dataset.editable;await Promise.resolve();});- await findView(figure, true);+ const readOnlyView = await findView(figure, true);const readOnlyTarget = getEmbedFindTarget(figure);if (!(readOnlyTarget instanceof CodeMirrorFindTarget)) {throw new Error("Expected a code target.");@@ -162,6 +162,10 @@ describe("CodeEmbed", () => {expect(readOnlyTarget).not.toBe(target);expect(await readOnlyTarget.find("print", { matchCase: false, wholeWord: false })).toBe(1);expect(await target.find("print", { matchCase: false, wholeWord: false })).toBe(0);+ expect(readOnlyTarget.canReplace()).toBe(false);+ expect(await readOnlyTarget.replace(0, "log")).toBe(1);+ expect(await readOnlyTarget.replaceAll("log")).toBe(1);+ expect(readOnlyView.state.doc.toString()).toBe("#print(1)\nlog(2)");});it("releases the edited content and shows it read-only once the toggle goes off", async () => {