Commit f6a3fa83 authored by Yogi's avatar Yogi Committed by Nathan Friend

Keyboard shortcut for switching to GitLab next (Canary)

parent 67d0cc39
...@@ -29,6 +29,7 @@ export const customizations = parsedCustomizations; ...@@ -29,6 +29,7 @@ export const customizations = parsedCustomizations;
// All available commands // All available commands
export const TOGGLE_PERFORMANCE_BAR = 'globalShortcuts.togglePerformanceBar'; export const TOGGLE_PERFORMANCE_BAR = 'globalShortcuts.togglePerformanceBar';
export const TOGGLE_CANARY = 'globalShortcuts.toggleCanary';
/** All keybindings, grouped and ordered with descriptions */ /** All keybindings, grouped and ordered with descriptions */
export const keybindingGroups = [ export const keybindingGroups = [
...@@ -42,6 +43,12 @@ export const keybindingGroups = [ ...@@ -42,6 +43,12 @@ export const keybindingGroups = [
// eslint-disable-next-line @gitlab/require-i18n-strings // eslint-disable-next-line @gitlab/require-i18n-strings
defaultKeys: ['p b'], defaultKeys: ['p b'],
}, },
{
description: s__('KeyboardShortcuts|Toggle GitLab Next'),
command: TOGGLE_CANARY,
// eslint-disable-next-line @gitlab/require-i18n-strings
defaultKeys: ['g x'],
},
], ],
}, },
] ]
......
...@@ -9,7 +9,7 @@ import axios from '../../lib/utils/axios_utils'; ...@@ -9,7 +9,7 @@ import axios from '../../lib/utils/axios_utils';
import { refreshCurrentPage, visitUrl } from '../../lib/utils/url_utility'; 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';
import { keysFor, TOGGLE_PERFORMANCE_BAR } from './keybindings'; import { keysFor, TOGGLE_PERFORMANCE_BAR, TOGGLE_CANARY } from './keybindings';
const defaultStopCallback = Mousetrap.prototype.stopCallback; const defaultStopCallback = Mousetrap.prototype.stopCallback;
Mousetrap.prototype.stopCallback = function customStopCallback(e, element, combo) { Mousetrap.prototype.stopCallback = function customStopCallback(e, element, combo) {
...@@ -72,6 +72,7 @@ export default class Shortcuts { ...@@ -72,6 +72,7 @@ export default class Shortcuts {
Mousetrap.bind('/', Shortcuts.focusSearch); Mousetrap.bind('/', Shortcuts.focusSearch);
Mousetrap.bind('f', this.focusFilter.bind(this)); Mousetrap.bind('f', this.focusFilter.bind(this));
Mousetrap.bind(keysFor(TOGGLE_PERFORMANCE_BAR), Shortcuts.onTogglePerfBar); Mousetrap.bind(keysFor(TOGGLE_PERFORMANCE_BAR), Shortcuts.onTogglePerfBar);
Mousetrap.bind(keysFor(TOGGLE_CANARY), Shortcuts.onToggleCanary);
const findFileURL = document.body.dataset.findFile; const findFileURL = document.body.dataset.findFile;
...@@ -124,6 +125,14 @@ export default class Shortcuts { ...@@ -124,6 +125,14 @@ export default class Shortcuts {
refreshCurrentPage(); refreshCurrentPage();
} }
static onToggleCanary(e) {
e.preventDefault();
const canaryCookieName = 'gitlab_canary';
const currentValue = parseBoolean(Cookies.get(canaryCookieName));
Cookies.set(canaryCookieName, (!currentValue).toString(), { expires: 365, path: '/' });
refreshCurrentPage();
}
static toggleMarkdownPreview(e) { static toggleMarkdownPreview(e) {
// Check if short-cut was triggered while in Write Mode // Check if short-cut was triggered while in Write Mode
const $target = $(e.target); const $target = $(e.target);
......
...@@ -60,6 +60,12 @@ ...@@ -60,6 +60,12 @@
%kbd p %kbd p
%kbd b %kbd b
%td= _('Toggle the Performance Bar') %td= _('Toggle the Performance Bar')
- if Gitlab.com?
%tr
%td.shortcut
%kbd g
%kbd x
%td= _('Toggle GitLab Next')
%tbody %tbody
%tr %tr
%th %th
......
---
title: Keyboard shortcut for switching to GitLab next (Canary)
merge_request: 51834
author: Yogi (@yo)
type: added
...@@ -16406,6 +16406,9 @@ msgstr "" ...@@ -16406,6 +16406,9 @@ msgstr ""
msgid "KeyboardShortcuts|Global Shortcuts" msgid "KeyboardShortcuts|Global Shortcuts"
msgstr "" msgstr ""
msgid "KeyboardShortcuts|Toggle GitLab Next"
msgstr ""
msgid "KeyboardShortcuts|Toggle the Performance Bar" msgid "KeyboardShortcuts|Toggle the Performance Bar"
msgstr "" msgstr ""
...@@ -29907,6 +29910,9 @@ msgstr "" ...@@ -29907,6 +29910,9 @@ msgstr ""
msgid "Today" msgid "Today"
msgstr "" msgstr ""
msgid "Toggle GitLab Next"
msgstr ""
msgid "Toggle Markdown preview" msgid "Toggle Markdown preview"
msgstr "" msgstr ""
......
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