1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-27 10:32:58 +02:00

Desktop: Fixes #7662: Ctrl-X behaviour when no text is selected (#7778)

This commit is contained in:
melsonic 2023-02-16 19:38:28 +05:30 committed by GitHub
parent 7fa1459dc3
commit 34940d1c4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -276,11 +276,22 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) {
const editorCutText = useCallback(() => { const editorCutText = useCallback(() => {
if (editorRef.current) { if (editorRef.current) {
const selections = editorRef.current.getSelections(); const selections = editorRef.current.getSelections();
if (selections.length > 0) { if (selections.length > 0 && selections[0]) {
clipboard.writeText(selections[0]); clipboard.writeText(selections[0]);
// Easy way to wipe out just the first selection // Easy way to wipe out just the first selection
selections[0] = ''; selections[0] = '';
editorRef.current.replaceSelections(selections); 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);
} }
} }
}, []); }, []);