Skip to content

Desktop: Fix inconsistency when pasting text #2431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ElectronClient/app/gui/NoteText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ class NoteTextComponent extends React.Component {
}

editorPasteText() {
this.wrapSelectionWithStrings('', '', '', clipboard.readText());
this.wrapSelectionWithStrings(clipboard.readText(), '', '', '');
}

selectionRangePreviousLine() {
Expand All @@ -1417,7 +1417,7 @@ class NoteTextComponent extends React.Component {
return this.selectionRange_ ? this.rangeToTextOffsets(this.selectionRange_, this.state.note.body) : null;
}

wrapSelectionWithStrings(string1, string2 = '', defaultText = '', replacementText = '') {
wrapSelectionWithStrings(string1, string2 = '', defaultText = '', replacementText = null) {
if (!this.rawEditor() || !this.state.note) return;

const selection = this.textOffsetSelection();
Expand All @@ -1426,7 +1426,7 @@ class NoteTextComponent extends React.Component {

if (selection && selection.start !== selection.end) {
const s1 = this.state.note.body.substr(0, selection.start);
const s2 = replacementText ? replacementText : this.state.note.body.substr(selection.start, selection.end - selection.start);
const s2 = replacementText !== null ? replacementText : this.state.note.body.substr(selection.start, selection.end - selection.start);
const s3 = this.state.note.body.substr(selection.end);
newBody = s1 + string1 + s2 + string2 + s3;

Expand All @@ -1444,7 +1444,7 @@ class NoteTextComponent extends React.Component {
column: r.end.column + str1Split[str1Split.length - 1].length },
};

if (replacementText) {
if (replacementText !== null) {
const diff = replacementText.length - (selection.end - selection.start);
newRange.end.column += diff;
}
Expand All @@ -1460,7 +1460,7 @@ class NoteTextComponent extends React.Component {
editor.focus();
});
} else {
let middleText = replacementText ? replacementText : defaultText;
let middleText = replacementText !== null ? replacementText : defaultText;
const textOffset = this.currentTextOffset();
const s1 = this.state.note.body.substr(0, textOffset);
const s2 = this.state.note.body.substr(textOffset);
Expand Down