Skip to content

Commit

Permalink
fix: Remove handlers (rather than setting to {}) in eachUnbind (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwoenker authored Apr 8, 2022
1 parent b1ad86a commit 1b34ff3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 37 deletions.
11 changes: 3 additions & 8 deletions dist/hotkeys.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* hotkeys-js v3.8.7
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2021 kenny wong <wowohoo@qq.com>
* Copyright (c) 2022 kenny wong <wowohoo@qq.com>
* http://jaywcjlove.github.io/hotkeys
*
* Licensed under the MIT license.
Expand Down Expand Up @@ -308,15 +308,10 @@ var eachUnbind = function eachUnbind(_ref) {

if (!scope) scope = getScope();
var mods = len > 1 ? getMods(_modifier, unbindKeys) : [];
_handlers[keyCode] = _handlers[keyCode].map(function (record) {
_handlers[keyCode] = _handlers[keyCode].filter(function (record) {
// 通过函数判断,是否解除绑定,函数相等直接返回
var isMatchingMethod = method ? record.method === method : true;

if (isMatchingMethod && record.scope === scope && compareArray(record.mods, mods)) {
return {};
}

return record;
return !(isMatchingMethod && record.scope === scope && compareArray(record.mods, mods));
});
});
}; // 对监听对应快捷键的回调函数进行处理
Expand Down
4 changes: 2 additions & 2 deletions dist/hotkeys.common.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions dist/hotkeys.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* hotkeys-js v3.8.7
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2021 kenny wong <wowohoo@qq.com>
* Copyright (c) 2022 kenny wong <wowohoo@qq.com>
* http://jaywcjlove.github.io/hotkeys
*
* Licensed under the MIT license.
Expand Down Expand Up @@ -306,15 +306,10 @@ var eachUnbind = function eachUnbind(_ref) {

if (!scope) scope = getScope();
var mods = len > 1 ? getMods(_modifier, unbindKeys) : [];
_handlers[keyCode] = _handlers[keyCode].map(function (record) {
_handlers[keyCode] = _handlers[keyCode].filter(function (record) {
// 通过函数判断,是否解除绑定,函数相等直接返回
var isMatchingMethod = method ? record.method === method : true;

if (isMatchingMethod && record.scope === scope && compareArray(record.mods, mods)) {
return {};
}

return record;
return !(isMatchingMethod && record.scope === scope && compareArray(record.mods, mods));
});
});
}; // 对监听对应快捷键的回调函数进行处理
Expand Down Expand Up @@ -569,4 +564,4 @@ if (typeof window !== 'undefined') {
window.hotkeys = hotkeys;
}

export default hotkeys;
export { hotkeys as default };
15 changes: 5 additions & 10 deletions dist/hotkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* hotkeys-js v3.8.7
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2021 kenny wong <wowohoo@qq.com>
* Copyright (c) 2022 kenny wong <wowohoo@qq.com>
* http://jaywcjlove.github.io/hotkeys
*
* Licensed under the MIT license.
Expand All @@ -12,7 +12,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.hotkeys = factory());
}(this, (function () { 'use strict';
})(this, (function () { 'use strict';

var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; // 绑定事件

Expand Down Expand Up @@ -312,15 +312,10 @@

if (!scope) scope = getScope();
var mods = len > 1 ? getMods(_modifier, unbindKeys) : [];
_handlers[keyCode] = _handlers[keyCode].map(function (record) {
_handlers[keyCode] = _handlers[keyCode].filter(function (record) {
// 通过函数判断,是否解除绑定,函数相等直接返回
var isMatchingMethod = method ? record.method === method : true;

if (isMatchingMethod && record.scope === scope && compareArray(record.mods, mods)) {
return {};
}

return record;
return !(isMatchingMethod && record.scope === scope && compareArray(record.mods, mods));
});
});
}; // 对监听对应快捷键的回调函数进行处理
Expand Down Expand Up @@ -577,4 +572,4 @@

return hotkeys;

})));
}));
Loading

0 comments on commit 1b34ff3

Please sign in to comment.