Skip to content

Commit

Permalink
Stop erasing the copy buffer if copying empty editor selections
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmsnell committed Jan 17, 2020
1 parent 3f75e82 commit 1714d68
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/note-content-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down

0 comments on commit 1714d68

Please sign in to comment.