Commit e3eb7ac2 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch 'nfriend-upgrade-mousetrap' into 'master'

Update mousetrap from 1.4.6 to 1.6.5

See merge request gitlab-org/gitlab!40670
parents 05605d3f 5def8037
...@@ -9,13 +9,13 @@ import { refreshCurrentPage, visitUrl } from '../../lib/utils/url_utility'; ...@@ -9,13 +9,13 @@ import { refreshCurrentPage, visitUrl } from '../../lib/utils/url_utility';
import findAndFollowLink from '../../lib/utils/navigation_utility'; import findAndFollowLink from '../../lib/utils/navigation_utility';
import { parseBoolean, getCspNonceValue } from '~/lib/utils/common_utils'; import { parseBoolean, getCspNonceValue } from '~/lib/utils/common_utils';
const defaultStopCallback = Mousetrap.stopCallback; const defaultStopCallback = Mousetrap.prototype.stopCallback;
Mousetrap.stopCallback = (e, element, combo) => { Mousetrap.prototype.stopCallback = function customStopCallback(e, element, combo) {
if (['ctrl+shift+p', 'command+shift+p'].indexOf(combo) !== -1) { if (['ctrl+shift+p', 'command+shift+p'].indexOf(combo) !== -1) {
return false; return false;
} }
return defaultStopCallback(e, element, combo); return defaultStopCallback.call(this, e, element, combo);
}; };
function initToggleButton() { function initToggleButton() {
......
...@@ -5,12 +5,11 @@ export default class ShortcutsFindFile extends ShortcutsNavigation { ...@@ -5,12 +5,11 @@ export default class ShortcutsFindFile extends ShortcutsNavigation {
constructor(projectFindFile) { constructor(projectFindFile) {
super(); super();
const oldStopCallback = Mousetrap.stopCallback; const oldStopCallback = Mousetrap.prototype.stopCallback;
this.projectFindFile = projectFindFile;
Mousetrap.stopCallback = (e, element, combo) => { Mousetrap.prototype.stopCallback = function customStopCallback(e, element, combo) {
if ( if (
element === this.projectFindFile.inputElement[0] && element === projectFindFile.inputElement[0] &&
(combo === 'up' || combo === 'down' || combo === 'esc' || combo === 'enter') (combo === 'up' || combo === 'down' || combo === 'esc' || combo === 'enter')
) { ) {
// when press up/down key in textbox, cursor prevent to move to home/end // when press up/down key in textbox, cursor prevent to move to home/end
...@@ -18,12 +17,12 @@ export default class ShortcutsFindFile extends ShortcutsNavigation { ...@@ -18,12 +17,12 @@ export default class ShortcutsFindFile extends ShortcutsNavigation {
return false; return false;
} }
return oldStopCallback(e, element, combo); return oldStopCallback.call(this, e, element, combo);
}; };
Mousetrap.bind('up', this.projectFindFile.selectRowUp); Mousetrap.bind('up', projectFindFile.selectRowUp);
Mousetrap.bind('down', this.projectFindFile.selectRowDown); Mousetrap.bind('down', projectFindFile.selectRowDown);
Mousetrap.bind('esc', this.projectFindFile.goToTree); Mousetrap.bind('esc', projectFindFile.goToTree);
Mousetrap.bind('enter', this.projectFindFile.goToBlob); Mousetrap.bind('enter', projectFindFile.goToBlob);
} }
} }
...@@ -9,7 +9,7 @@ export const MAX_FILE_FINDER_RESULTS = 40; ...@@ -9,7 +9,7 @@ export const MAX_FILE_FINDER_RESULTS = 40;
export const FILE_FINDER_ROW_HEIGHT = 55; export const FILE_FINDER_ROW_HEIGHT = 55;
export const FILE_FINDER_EMPTY_ROW_HEIGHT = 33; export const FILE_FINDER_EMPTY_ROW_HEIGHT = 33;
const originalStopCallback = Mousetrap.stopCallback; const originalStopCallback = Mousetrap.prototype.stopCallback;
export default { export default {
components: { components: {
...@@ -134,7 +134,18 @@ export default { ...@@ -134,7 +134,18 @@ export default {
this.toggle(!this.visible); 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: { methods: {
toggle(visible) { toggle(visible) {
...@@ -199,18 +210,6 @@ export default { ...@@ -199,18 +210,6 @@ export default {
this.cancelMouseOver = false; this.cancelMouseOver = false;
this.onMouseOver(index); 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> </script>
......
...@@ -313,3 +313,9 @@ ...@@ -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" :why: "https://github.com/cure53/DOMPurify/blob/main/LICENSE and https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31928#note_346604841"
:versions: [] :versions: []
:when: 2020-08-13 13:42:46.508082000 Z :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', () => { ...@@ -343,26 +343,36 @@ describe('File finder item spec', () => {
it('always allows `command+p` to trigger toggle', () => { it('always allows `command+p` to trigger toggle', () => {
expect( 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); ).toBe(false);
}); });
it('always allows `ctrl+p` to trigger toggle', () => { it('always allows `ctrl+p` to trigger toggle', () => {
expect( 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); ).toBe(false);
}); });
it('onlys handles `t` when focused in input-field', () => { it('onlys handles `t` when focused in input-field', () => {
expect( expect(
vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 't'), Mousetrap.prototype.stopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 't'),
).toBe(true); ).toBe(true);
}); });
it('stops callback in monaco editor', () => { it('stops callback in monaco editor', () => {
setFixtures('<div class="inputarea"></div>'); 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);
}); });
}); });
}); });
...@@ -8371,10 +8371,10 @@ monaco-yaml@^2.4.1: ...@@ -8371,10 +8371,10 @@ monaco-yaml@^2.4.1:
optionalDependencies: optionalDependencies:
prettier "^1.19.1" prettier "^1.19.1"
mousetrap@^1.4.6: mousetrap@1.6.5:
version "1.4.6" version "1.6.5"
resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.4.6.tgz#eaca72e22e56d5b769b7555873b688c3332e390a" resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.5.tgz#8a766d8c272b08393d5f56074e0b5ec183485bf9"
integrity sha1-6spy4i5W1bdpt1VYc7aIwzMuOQo= integrity sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA==
move-concurrently@^1.0.1: move-concurrently@^1.0.1:
version "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