diff options
Diffstat (limited to 'assets/js/core')
-rw-r--r-- | assets/js/core/utils.js | 21 |
1 files changed, 21 insertions, 0 deletions
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 + }; +}; |