From 34940d1c4f64ab659c28f26fa216dad02af7704b Mon Sep 17 00:00:00 2001 From: melsonic <88551650+melsonic@users.noreply.github.com> Date: Thu, 16 Feb 2023 19:38:28 +0530 Subject: [PATCH] Desktop: Fixes #7662: Ctrl-X behaviour when no text is selected (#7778) --- .../NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx index eb8eab7b7..35c00e40e 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx @@ -276,11 +276,22 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) { const editorCutText = useCallback(() => { if (editorRef.current) { const selections = editorRef.current.getSelections(); - if (selections.length > 0) { + if (selections.length > 0 && selections[0]) { clipboard.writeText(selections[0]); // Easy way to wipe out just the first selection selections[0] = ''; editorRef.current.replaceSelections(selections); + } else { + const cursor = editorRef.current.getCursor(); + const line = editorRef.current.getLine(cursor.line); + clipboard.writeText(`${line}\n`); + const startLine = editorRef.current.getCursor('head'); + startLine.ch = 0; + const endLine = { + line: startLine.line + 1, + ch: 0, + }; + editorRef.current.replaceRange('', startLine, endLine); } } }, []);