diff options
author | Clement Ho <ClemMakesApps@gmail.com> | 2017-01-06 16:10:30 -0600 |
---|---|---|
committer | Clement Ho <ClemMakesApps@gmail.com> | 2017-01-06 16:10:30 -0600 |
commit | 41bdcccd1eb83113eca7ac92b21091737ab6d540 (patch) | |
tree | ab57e90541dc6944405a13225913e858f8197c0c /app/assets/javascripts/lib/utils/common_utils.js | |
parent | cfc9f13b209c359d8b1b428a3da5a69b2d9f647f (diff) | |
download | gitlab-ce-41bdcccd1eb83113eca7ac92b21091737ab6d540.tar.gz |
Get selected word from cursor positionselectable-autocomplete-dropdown
Diffstat (limited to 'app/assets/javascripts/lib/utils/common_utils.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/common_utils.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index 27f2f4a41eb..0edf1dae165 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -145,6 +145,28 @@ return decodeURIComponent(results[2].replace(/\+/g, ' ')); }; + gl.utils.getCursorPosition = function(input) { + var cursorPosition = 0; + + // IE Support + if (document.selection) { + input.focus(); + + // To get cursor position, get empty selection range + var range = document.selection.createRange(); + + // Move selection start to 0 position + range.moveStart('character', -1 * input.value.length); + + // The cursor position is selection length + cursorPosition = range.text.length; + } else if (input.selectionStart || input.selectionStart === '0') { + cursorPosition = input.selectionStart; + } + + return cursorPosition; + }; + gl.utils.isMetaKey = function(e) { return e.metaKey || e.ctrlKey || e.altKey || e.shiftKey; }; |