From 1714d68bbfc178017858d05f3c3a117679f32c84 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Fri, 17 Jan 2020 14:59:55 -0700 Subject: [PATCH] Stop erasing the copy buffer if copying empty editor selections Resolves #1843 Previously it has been the case that if you attempt to copy something in the note editor but there is no selection then it will wipe out the system's copy buffer. This is because we implement our own copy handler which strips away the visual formatting of elements in the note editor. 1. Copy anything in any app, suppose you copy "test" 2. Paste that "test" anywhere, it pastes 3. Click in the note editor but don't select anything. 4. "Copy" by hitting the copy shortcut or by using a menu option 5. Paste anywhere Although we'd expect that "test" is still in our copy buffer we get the empty string pasted in and "test" is gone. While not really _wrong_ or _broken_ this is a bit jarring and it's probably better in most cases to preserve the previous copy buffer if we're not copying anything. We've turned the copy command into a "clear the copy buffer" command if there's no content. In this patch we're aborting the copy if our selection is empty and that will preserve the existing buffer and the expected behavior. --- lib/note-content-editor.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/note-content-editor.tsx b/lib/note-content-editor.tsx index 7f442e85c..251ec6f1e 100644 --- a/lib/note-content-editor.tsx +++ b/lib/note-content-editor.tsx @@ -292,6 +292,9 @@ export default class NoteContentEditor extends Component { */ copyPlainText = event => { const textToCopy = getSelectedText(this.state.editorState); + if (!textToCopy) { + return; + } event.clipboardData.setData('text/plain', textToCopy); event.preventDefault(); };