From 4da331a3ab2c8701c01fb8b3e146d747bd2fc2f8 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 30 Jan 2020 12:28:28 -0800 Subject: [PATCH] Fix entry_with_replacements unable to select text. This hook had a bug where you couldn't select text because every time you push a button, including ctrl+a or shift+left/right, the cursor position gets reset and then deselects immediately. So let's only reset the content and cursor only when text changes, so arrow keys and ctrl don't have any negative effects. --- frontends/etiquette_flask/static/js/common.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontends/etiquette_flask/static/js/common.js b/frontends/etiquette_flask/static/js/common.js index 713bae8..93a2f35 100644 --- a/frontends/etiquette_flask/static/js/common.js +++ b/frontends/etiquette_flask/static/js/common.js @@ -129,9 +129,13 @@ common.entry_with_tagname_replacements = function entry_with_tagname_replacements(event) { var cursor_position = event.target.selectionStart; - event.target.value = common.tagname_replacements(event.target.value); - event.target.selectionStart = cursor_position; - event.target.selectionEnd = cursor_position; + var new_value = common.tagname_replacements(event.target.value); + if (new_value != event.target.value) + { + event.target.value = new_value; + event.target.selectionStart = cursor_position; + event.target.selectionEnd = cursor_position; + } } common.html_to_element =