Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1885 - Global name collision #1897

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ $.extend(Selectize.prototype, {
var self = this;

direction = (e && e.keyCode === KEY_BACKSPACE) ? -1 : 1;
selection = getSelection(self.$control_input[0]);
selection = getInputSelection(self.$control_input[0]);

if (self.$activeOption && !self.settings.hideSelected) {
if (typeof self.settings.deselectBehavior === 'string' && self.settings.deselectBehavior === 'top') {
Expand Down Expand Up @@ -2172,7 +2172,7 @@ $.extend(Selectize.prototype, {
if (self.rtl) direction *= -1;

tail = direction > 0 ? 'last' : 'first';
selection = getSelection(self.$control_input[0]);
selection = getInputSelection(self.$control_input[0]);

if (self.isFocused && !self.isInputHidden) {
valueLength = self.$control_input.val().length;
Expand Down
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ var watchChildEvent = function ($parent, event, selector, fn) {
* @param {object} input
* @returns {object}
*/
var getSelection = function (input) {
var getInputSelection = function (input) {
var result = {};
if (input === undefined) {
console.warn('WARN getSelection cannot locate input control');
console.warn('WARN getInputSelection cannot locate input control');
return result;
}
if ('selectionStart' in input) {
Expand Down Expand Up @@ -302,7 +302,7 @@ var autoGrow = function ($input) {
);

if (keyCode === KEY_DELETE || keyCode === KEY_BACKSPACE) {
selection = getSelection($input[0]);
selection = getInputSelection($input[0]);
if (selection.length) {
value = value.substring(0, selection.start) + value.substring(selection.start + selection.length);
} else if (keyCode === KEY_BACKSPACE && selection.start) {
Expand Down
6 changes: 3 additions & 3 deletions test/support/syn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ define('syn/key', [
'syn/typeable',
'syn/browsers'
], function (syn) {
var h = syn.helpers, getSelection = function (el) {
var h = syn.helpers, getInputSelection = function (el) {
var real, r, start;
if (el.selectionStart !== undefined) {
if (document.activeElement && document.activeElement !== el && el.selectionStart === el.selectionEnd && el.selectionStart === 0) {
Expand Down Expand Up @@ -1752,7 +1752,7 @@ define('syn/key', [
},
getText: function (el) {
if (syn.typeable.test(el)) {
var sel = getSelection(el);
var sel = getInputSelection(el);
return el.value.substring(sel.start, sel.end);
}
var win = syn.helpers.getWindow(el);
Expand Down Expand Up @@ -2120,7 +2120,7 @@ define('syn/key', [
syn.trigger(element, 'keyup', options.replace('-up', ''));
return callback(true, element);
}
var activeElement = h.getWindow(element).document.activeElement, caret = syn.typeable.test(element) && getSelection(element), key = convert[options] || options, runDefaults = syn.trigger(element, 'keydown', key), getDefault = syn.key.getDefault, prevent = syn.key.browser.prevent, defaultResult, keypressOptions = syn.key.options(key, 'keypress');
var activeElement = h.getWindow(element).document.activeElement, caret = syn.typeable.test(element) && getInputSelection(element), key = convert[options] || options, runDefaults = syn.trigger(element, 'keydown', key), getDefault = syn.key.getDefault, prevent = syn.key.browser.prevent, defaultResult, keypressOptions = syn.key.options(key, 'keypress');
if (runDefaults) {
if (!keypressOptions) {
defaultResult = getDefault(key).call(element, keypressOptions, h.getWindow(element), key, undefined, caret);
Expand Down