From 4840671f0e157450162d6cbe5a426dfcec6ed9a5 Mon Sep 17 00:00:00 2001 From: Rishabh Malhotra Date: Thu, 27 Feb 2020 05:48:57 +0530 Subject: [PATCH] Desktop: Fixes #2573: Improved detection of selected text when applying formatting (#2582) * fixes #2573 This fixes the bug with spaces * Update NoteText.jsx --- ElectronClient/gui/NoteText.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ElectronClient/gui/NoteText.jsx b/ElectronClient/gui/NoteText.jsx index 320034632..143ffea8b 100644 --- a/ElectronClient/gui/NoteText.jsx +++ b/ElectronClient/gui/NoteText.jsx @@ -1435,9 +1435,17 @@ class NoteTextComponent extends React.Component { let selectedStrings = byLine ? selectedLines.split(/\r?\n/) : [selectedLines]; newBody = this.state.note.body.substr(0, selection.start); + for (let i = 0; i < selectedStrings.length; i++) { - newBody += string1 + selectedStrings[i] + string2; + if (byLine == false) { + let start = selectedStrings[i].search(/[^\s]/); + let end = selectedStrings[i].search(/[^\s](?=[\s]*$)/); + newBody += selectedStrings[i].substr(0, start) + string1 + selectedStrings[i].substr(start, end - start + 1) + string2 + selectedStrings[i].substr(end + 1); + if (this.state.note.body.substr(selection.end) === '') newBody = newBody.trim(); + } else { newBody += string1 + selectedStrings[i] + string2; } + } + newBody += this.state.note.body.substr(selection.end); const r = this.selectionRange_;