From be83821ef7885ca45da36f15ea7a26cbf3e33fd9 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 1 Dec 2016 20:54:33 -0500 Subject: Improve cross-browsers compatiblity for text editor --- assets/js/core/utils.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'assets/js/core') diff --git a/assets/js/core/utils.js b/assets/js/core/utils.js index 7d631526..e8e74b17 100644 --- a/assets/js/core/utils.js +++ b/assets/js/core/utils.js @@ -11,3 +11,24 @@ KB.utils.formatDuration = function (d) { return d + "s"; }; + +KB.utils.getSelectionPosition = function (element) { + var selectionStart, selectionEnd; + + if (element.value.length < element.selectionStart) { + selectionStart = element.value.length; + } else { + selectionStart = element.selectionStart; + } + + if (element.selectionStart === element.selectionEnd) { + selectionEnd = selectionStart; + } else { + selectionEnd = element.selectionEnd; + } + + return { + selectionStart: selectionStart, + selectionEnd: selectionEnd + }; +}; -- cgit v1.2.3