diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-12-01 20:54:33 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-12-01 20:54:33 -0500 |
commit | be83821ef7885ca45da36f15ea7a26cbf3e33fd9 (patch) | |
tree | 80c8a978db27445b52b02f7a3aef22bbd14519c9 /assets/js/components | |
parent | 9c06bc4ed25a08e75d4677834a29f801f6e42423 (diff) |
Improve cross-browsers compatiblity for text editor
Diffstat (limited to 'assets/js/components')
-rw-r--r-- | assets/js/components/suggest-menu.js | 7 | ||||
-rw-r--r-- | assets/js/components/text-editor.js | 21 |
2 files changed, 12 insertions, 16 deletions
diff --git a/assets/js/components/suggest-menu.js b/assets/js/components/suggest-menu.js index d23e4c37..f1f44eaf 100644 --- a/assets/js/components/suggest-menu.js +++ b/assets/js/components/suggest-menu.js @@ -35,14 +35,17 @@ KB.component('suggest-menu', function(containerElement, options) { } function insertSelectedItem() { + containerElement.focus(); + var element = KB.find('.suggest-menu-item.active'); var value = element.data('value'); var trigger = element.data('trigger'); var content = containerElement.value; var text = getLastWord(containerElement); var substitute = trigger + value + ' '; - var before = content.substring(0, containerElement.selectionStart - text.length); - var after = content.substring(containerElement.selectionEnd); + var selectionPosition = KB.utils.getSelectionPosition(containerElement); + var before = content.substring(0, selectionPosition.selectionStart - text.length); + var after = content.substring(selectionPosition.selectionEnd); var position = before.length + substitute.length; containerElement.value = before + substitute + after; diff --git a/assets/js/components/text-editor.js b/assets/js/components/text-editor.js index 9a185cf2..45b12b01 100644 --- a/assets/js/components/text-editor.js +++ b/assets/js/components/text-editor.js @@ -125,25 +125,18 @@ KB.component('text-editor', function (containerElement, options) { insertText(lines.join('\n')); } + + setCursorBeforeClosingTag(tag, 1); } function insertText(replacedText) { - var result = false; - textarea.focus(); - // Fix issue with IE11 (last line with wrong position) - if (textarea.value.length < textarea.selectionStart) { - selectionStart = textarea.value.length; - } else { - selectionStart = textarea.selectionStart; - } + var result = false; + var selectionPosition = KB.utils.getSelectionPosition(textarea); - if (textarea.selectionStart === textarea.selectionEnd) { - selectionEnd = selectionStart; - } else { - selectionEnd = textarea.selectionEnd; - } + selectionStart = selectionPosition.selectionStart; + selectionEnd = selectionPosition.selectionEnd; if (document.queryCommandSupported('insertText')) { result = document.execCommand('insertText', false, replacedText); @@ -154,7 +147,7 @@ KB.component('text-editor', function (containerElement, options) { document.execCommand('ms-beginUndoUnit'); } catch (error) {} - textarea.value = replaceTextRange(textarea.value, selectionStart, textarea.selectionEnd, replacedText); + textarea.value = replaceTextRange(textarea.value, selectionStart, selectionEnd, replacedText); try { document.execCommand('ms-endUndoUnit'); |