Commit 5def8037 authored by Nathan Friend's avatar Nathan Friend Committed by Olena Horal-Koretska

Update mousetrap from 1.4.6 to 1.6.5

This commit update mousetrap to the latest version (1.6.5). It includes
some small fixes necessary for the update.
parent b434e085
......@@ -9,13 +9,13 @@ import { refreshCurrentPage, visitUrl } from '../../lib/utils/url_utility';
import findAndFollowLink from '../../lib/utils/navigation_utility';
import { parseBoolean, getCspNonceValue } from '~/lib/utils/common_utils';
const defaultStopCallback = Mousetrap.stopCallback;
Mousetrap.stopCallback = (e, element, combo) => {
const defaultStopCallback = Mousetrap.prototype.stopCallback;
Mousetrap.prototype.stopCallback = function customStopCallback(e, element, combo) {
if (['ctrl+shift+p', 'command+shift+p'].indexOf(combo) !== -1) {
return false;
}
return defaultStopCallback(e, element, combo);
return defaultStopCallback.call(this, e, element, combo);
};
function initToggleButton() {
......
......@@ -5,12 +5,11 @@ export default class ShortcutsFindFile extends ShortcutsNavigation {
constructor(projectFindFile) {
super();
const oldStopCallback = Mousetrap.stopCallback;
this.projectFindFile = projectFindFile;
const oldStopCallback = Mousetrap.prototype.stopCallback;
Mousetrap.stopCallback = (e, element, combo) => {
Mousetrap.prototype.stopCallback = function customStopCallback(e, element, combo) {
if (
element === this.projectFindFile.inputElement[0] &&
element === projectFindFile.inputElement[0] &&
(combo === 'up' || combo === 'down' || combo === 'esc' || combo === 'enter')
) {
// when press up/down key in textbox, cursor prevent to move to home/end
......@@ -18,12 +17,12 @@ export default class ShortcutsFindFile extends ShortcutsNavigation {
return false;
}
return oldStopCallback(e, element, combo);
return oldStopCallback.call(this, e, element, combo);
};
Mousetrap.bind('up', this.projectFindFile.selectRowUp);
Mousetrap.bind('down', this.projectFindFile.selectRowDown);
Mousetrap.bind('esc', this.projectFindFile.goToTree);
Mousetrap.bind('enter', this.projectFindFile.goToBlob);
Mousetrap.bind('up', projectFindFile.selectRowUp);
Mousetrap.bind('down', projectFindFile.selectRowDown);
Mousetrap.bind('esc', projectFindFile.goToTree);
Mousetrap.bind('enter', projectFindFile.goToBlob);
}
}
......@@ -9,7 +9,7 @@ export const MAX_FILE_FINDER_RESULTS = 40;
export const FILE_FINDER_ROW_HEIGHT = 55;
export const FILE_FINDER_EMPTY_ROW_HEIGHT = 33;
const originalStopCallback = Mousetrap.stopCallback;
const originalStopCallback = Mousetrap.prototype.stopCallback;
export default {
components: {
......@@ -134,7 +134,18 @@ export default {
this.toggle(!this.visible);
});
Mousetrap.stopCallback = (e, el, combo) => this.mousetrapStopCallback(e, el, combo);
Mousetrap.prototype.stopCallback = function customStopCallback(e, el, combo) {
if (
(combo === 't' && el.classList.contains('dropdown-input-field')) ||
el.classList.contains('inputarea')
) {
return true;
} else if (combo === 'command+p' || combo === 'ctrl+p') {
return false;
}
return originalStopCallback.call(this, e, el, combo);
};
},
methods: {
toggle(visible) {
......@@ -199,18 +210,6 @@ export default {
this.cancelMouseOver = false;
this.onMouseOver(index);
},
mousetrapStopCallback(e, el, combo) {
if (
(combo === 't' && el.classList.contains('dropdown-input-field')) ||
el.classList.contains('inputarea')
) {
return true;
} else if (combo === 'command+p' || combo === 'ctrl+p') {
return false;
}
return originalStopCallback(e, el, combo);
},
},
};
</script>
......
......@@ -313,3 +313,9 @@
:why: "https://github.com/cure53/DOMPurify/blob/main/LICENSE and https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31928#note_346604841"
:versions: []
:when: 2020-08-13 13:42:46.508082000 Z
- - :whitelist
- Apache-2.0 WITH LLVM-exception
- :who: Nathan Friend
:why: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40670#note_403946372
:versions: []
:when: 2020-08-28 15:01:59.329048917 Z
......@@ -343,26 +343,36 @@ describe('File finder item spec', () => {
it('always allows `command+p` to trigger toggle', () => {
expect(
vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 'command+p'),
Mousetrap.prototype.stopCallback(
null,
vm.$el.querySelector('.dropdown-input-field'),
'command+p',
),
).toBe(false);
});
it('always allows `ctrl+p` to trigger toggle', () => {
expect(
vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 'ctrl+p'),
Mousetrap.prototype.stopCallback(
null,
vm.$el.querySelector('.dropdown-input-field'),
'ctrl+p',
),
).toBe(false);
});
it('onlys handles `t` when focused in input-field', () => {
expect(
vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 't'),
Mousetrap.prototype.stopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 't'),
).toBe(true);
});
it('stops callback in monaco editor', () => {
setFixtures('<div class="inputarea"></div>');
expect(vm.mousetrapStopCallback(null, document.querySelector('.inputarea'), 't')).toBe(true);
expect(
Mousetrap.prototype.stopCallback(null, document.querySelector('.inputarea'), 't'),
).toBe(true);
});
});
});
......@@ -8374,10 +8374,10 @@ monaco-yaml@^2.4.1:
optionalDependencies:
prettier "^1.19.1"
mousetrap@^1.4.6:
version "1.4.6"
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.4.6.tgz#eaca72e22e56d5b769b7555873b688c3332e390a"
integrity sha1-6spy4i5W1bdpt1VYc7aIwzMuOQo=
mousetrap@1.6.5:
version "1.6.5"
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.5.tgz#8a766d8c272b08393d5f56074e0b5ec183485bf9"
integrity sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA==
move-concurrently@^1.0.1:
version "1.0.1"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment