From 3dd13ca32124527da56798d026b07bf9c84ca2d9 Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Wed, 14 May 2025 11:13:22 +0800 Subject: [PATCH] fix(find): readonly code getSelection --- apps/client/src/widgets/find.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/apps/client/src/widgets/find.ts b/apps/client/src/widgets/find.ts index 7580ba3a6..7ff87736a 100644 --- a/apps/client/src/widgets/find.ts +++ b/apps/client/src/widgets/find.ts @@ -197,14 +197,9 @@ export default class FindWidget extends NoteContextAwareWidget { const isReadOnly = await this.noteContext?.isReadOnly(); let selectedText = ""; - if (this.note?.type === "code" && this.noteContext) { - if (isReadOnly){ - const $content = await this.noteContext.getContentElement(); - selectedText = $content.find('.cm-matchhighlight').first().text(); - } else { - const codeEditor = await this.noteContext.getCodeEditor(); - selectedText = codeEditor.getSelectedText(); - } + if (this.note?.type === "code" && this.noteContext && !isReadOnly) { + const codeEditor = await this.noteContext.getCodeEditor(); + selectedText = codeEditor.getSelectedText(); } else { selectedText = window.getSelection()?.toString() || ""; }