diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-05-19 06:17:59 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-05-19 15:26:28 +0300 |
commit | 7e0a4c5e577769dddc4aec1cfec1db3064a3ff42 (patch) | |
tree | 822ac0d55c6eeab802c144dbe86c60da9665c4a0 /app/assets/javascripts/lib | |
parent | 36ede00876aacd0005eac8e9b4779e3014519e0c (diff) |
Don't wrap pasted code when it's already inside code tags
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r-- | app/assets/javascripts/lib/utils/common_utils.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index 7e62773ae6c..a537267643e 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -198,10 +198,12 @@ const textBefore = value.substring(0, selectionStart); const textAfter = value.substring(selectionEnd, value.length); - const newText = textBefore + text + textAfter; + + const insertedText = text instanceof Function ? text(textBefore, textAfter) : text; + const newText = textBefore + insertedText + textAfter; target.value = newText; - target.selectionStart = target.selectionEnd = selectionStart + text.length; + target.selectionStart = target.selectionEnd = selectionStart + insertedText.length; // Trigger autosave $(target).trigger('input'); |