-
Notifications
You must be signed in to change notification settings - Fork 1.2k
VIM-like Navigation #7336
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
base: development
Are you sure you want to change the base?
VIM-like Navigation #7336
Changes from all commits
076bebe
99e2120
2bd8ba9
48310ee
e4b381d
e010f52
32a250e
fb4e273
3b9f62d
2912fed
afa614e
fabe9ec
721352e
e2d3c67
c06dfd5
b3d424f
72274ac
fed12b8
aaa777e
5d67b25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -76,6 +76,9 @@ export default defineComponent({ | |||||||||||||||||||||||||||||
isKeyboardShortcutPromptShown: function () { | ||||||||||||||||||||||||||||||
return this.$store.getters.getIsKeyboardShortcutPromptShown | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
areVimWaypointsShown: function () { | ||||||||||||||||||||||||||||||
return this.$store.getters.getAreVimWaypointsShown | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
showAddToPlaylistPrompt: function () { | ||||||||||||||||||||||||||||||
return this.$store.getters.getShowAddToPlaylistPrompt | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
|
@@ -156,6 +159,10 @@ export default defineComponent({ | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
openDeepLinksInNewWindow: function () { | ||||||||||||||||||||||||||||||
return this.$store.getters.getOpenDeepLinksInNewWindow | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
enableVimNavigation: function () { | ||||||||||||||||||||||||||||||
return this.$store.getters.getEnableVimNavigation | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
watch: { | ||||||||||||||||||||||||||||||
|
@@ -344,20 +351,59 @@ export default defineComponent({ | |||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
activateKeyboardShortcuts: function () { | ||||||||||||||||||||||||||||||
if (this.enableVimNavigation) { | ||||||||||||||||||||||||||||||
['click', 'scroll'].forEach((eventName) => | ||||||||||||||||||||||||||||||
document.addEventListener(eventName, (e) => { | ||||||||||||||||||||||||||||||
this.$store.commit('setAreVimWaypointsShown', { key: 'Esc' }) | ||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
document.addEventListener('keydown', (e) => { | ||||||||||||||||||||||||||||||
// Only handle if not in an input field and not in waypoint mode | ||||||||||||||||||||||||||||||
if (e.target.tagName !== 'INPUT' && !this.areVimWaypointsShown.selector.length) { | ||||||||||||||||||||||||||||||
if (e.key === 'j') { | ||||||||||||||||||||||||||||||
// If the 'J' key is pressed | ||||||||||||||||||||||||||||||
window.scrollBy({ | ||||||||||||||||||||||||||||||
top: 30, | ||||||||||||||||||||||||||||||
behavior: 'auto' | ||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||
} else if (e.key === 'k') { | ||||||||||||||||||||||||||||||
// If the 'K' key is pressed | ||||||||||||||||||||||||||||||
Comment on lines
+363
to
+370
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is self-explanatory, so these code comments don't add any value.
Suggested change
|
||||||||||||||||||||||||||||||
window.scrollBy({ | ||||||||||||||||||||||||||||||
top: -30, | ||||||||||||||||||||||||||||||
behavior: 'auto' | ||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
document.addEventListener('keydown', this.handleKeyboardShortcuts) | ||||||||||||||||||||||||||||||
document.addEventListener('mousedown', () => { | ||||||||||||||||||||||||||||||
this.hideOutlines() | ||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
handleKeyboardShortcuts: function (event) { | ||||||||||||||||||||||||||||||
// If this.areVimWaypointsShown.selector starts with an f it means | ||||||||||||||||||||||||||||||
// the user is in nav mode so capture any input and pass it to | ||||||||||||||||||||||||||||||
// setAreVimWaypointsShown | ||||||||||||||||||||||||||||||
if (this.areVimWaypointsShown.selector[0] === 'w' && !event.ctrlKey && this.enableVimNavigation) { | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please reorder the checks (not just in this if) so that the check for the setting is first. For people that have the setting enabled it won't change anything, but for people that have it disabled it skips having to do unnecessary checks. |
||||||||||||||||||||||||||||||
this.$store.commit('setAreVimWaypointsShown', { key: event.key }) | ||||||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
// ignore user typing in HTML `input` elements | ||||||||||||||||||||||||||||||
if (event.shiftKey && event.key === '?' && event.target.tagName !== 'INPUT') { | ||||||||||||||||||||||||||||||
this.$store.commit('setIsKeyboardShortcutPromptShown', !this.isKeyboardShortcutPromptShown) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (event.key === 'Tab') { | ||||||||||||||||||||||||||||||
this.showOutlines() | ||||||||||||||||||||||||||||||
switch (event.key) { | ||||||||||||||||||||||||||||||
case 'w': | ||||||||||||||||||||||||||||||
if (event.target.tagName !== 'INPUT' && this.enableVimNavigation && !event.ctrlKey) { | ||||||||||||||||||||||||||||||
this.$store.commit('setAreVimWaypointsShown', { key: event.key }) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||||
case 'Tab': | ||||||||||||||||||||||||||||||
this.showOutlines() | ||||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid confusing users, the VIM specific shortcuts should be hidden in the popup when the setting is disabled. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -81,6 +81,10 @@ const situationalAppShortcuts = computed(() => | |||||
getLocalizedShortcutNamesAndValues(KeyboardShortcuts.APP.SITUATIONAL) | ||||||
) | ||||||
|
||||||
const VimAppShortcuts = computed(() => | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow the naming conventions that are used in the rest of the code base (remember to rename the references to this variable too).
Suggested change
|
||||||
getLocalizedShortcutNamesAndValues(KeyboardShortcuts.APP.VIM) | ||||||
) | ||||||
|
||||||
const primarySections = computed(() => [ | ||||||
[ | ||||||
{ | ||||||
|
@@ -101,14 +105,24 @@ const primarySections = computed(() => [ | |||||
title: t('KeyboardShortcutPrompt.Sections.App.Situational'), | ||||||
shortcutDictionary: situationalAppShortcuts.value | ||||||
} | ||||||
], | ||||||
[ | ||||||
{ | ||||||
title: t('KeyboardShortcutPrompt.Sections.App.VIM'), | ||||||
shortcutDictionary: VimAppShortcuts.value | ||||||
} | ||||||
] | ||||||
]) | ||||||
|
||||||
const isMac = process.platform === 'darwin' | ||||||
const enableVimNavigation = computed(() => store.getters.getEnableVimNavigation) | ||||||
|
||||||
const localizedShortcutNameToShortcutsMappings = computed(() => { | ||||||
return [ | ||||||
[t('KeyboardShortcutPrompt.Show Keyboard Shortcuts'), ['SHOW_SHORTCUTS']], | ||||||
[t('KeyboardShortcutPrompt.Show Vim Waypoints'), ['SHOW_VIM_WAYPOINTS']], | ||||||
[t('KeyboardShortcutPrompt.Scroll Down'), ['SCROLL_DOWN']], | ||||||
[t('KeyboardShortcutPrompt.Scroll Up'), ['SCROLL_UP']], | ||||||
[t('KeyboardShortcutPrompt.History Backward'), [ | ||||||
'HISTORY_BACKWARD', | ||||||
...isMac ? ['HISTORY_BACKWARD_ALT_MAC'] : [], | ||||||
|
@@ -147,8 +161,7 @@ const localizedShortcutNameToShortcutsMappings = computed(() => { | |||||
[t('KeyboardShortcutPrompt.Take Screenshot'), ['TAKE_SCREENSHOT']], | ||||||
[t('KeyboardShortcutPrompt.Stats'), ['STATS']], | ||||||
|
||||||
[t('KeyboardShortcutPrompt.Play'), ['PLAY']], | ||||||
[t('KeyboardShortcutPrompt.Large Rewind'), ['LARGE_REWIND']], | ||||||
[t('KeyboardShortcutPrompt.Large Rewind'), [enableVimNavigation.value ? 'VIM_ENABLED_LARGE_REWIND' : 'LARGE_REWIND']], | ||||||
[t('KeyboardShortcutPrompt.Large Fast Forward'), ['LARGE_FAST_FORWARD']], | ||||||
[t('KeyboardShortcutPrompt.Small Rewind'), ['SMALL_REWIND']], | ||||||
[t('KeyboardShortcutPrompt.Small Fast Forward'), ['SMALL_FAST_FORWARD']], | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,19 @@ | |
margin-block-end: 1rem; | ||
} | ||
|
||
.proxy-warning { | ||
.proxy-warning, | ||
.vim-warning { | ||
padding-block: 12px; | ||
padding-inline: 4%; | ||
background-color: var(--accent-color); | ||
color: var(--text-with-accent-color); | ||
font-weight: bold; | ||
} | ||
|
||
.vim-warning { | ||
margin-block: 1px; | ||
} | ||
|
||
Comment on lines
+5
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you add CSS to the proxy settings, when your changes are in the general settings? |
||
.warning-icon { | ||
font-size: large; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2061,10 +2061,27 @@ export default defineComponent({ | |
seekBySeconds(dist, true) | ||
} | ||
|
||
const areVimWaypointsShown = computed(() => { | ||
return store.getters.getAreVimWaypointsShown | ||
}) | ||
|
||
const vimEnabled = computed(() => { | ||
return store.getters.getEnableVimNavigation | ||
}) | ||
|
||
/** | ||
* @param {KeyboardEvent} event | ||
*/ | ||
function keyboardShortcutHandler(event) { | ||
const passToVim = | ||
// If vim keys are enabled, ctrl is not held down, and the key is not f, j, or k. | ||
(vimEnabled.value && !event.ctrlKey && ['w', 'j', 'k'].includes(event.key)) || // OR | ||
// The waypoints are already on the screen | ||
((areVimWaypointsShown.value.selector || []).length && areVimWaypointsShown.value.selector[0] === 'w') | ||
|
||
if (passToVim) { | ||
return | ||
} | ||
if (!player || !hasLoaded.value) { | ||
return | ||
} | ||
|
@@ -2105,12 +2122,12 @@ export default defineComponent({ | |
switch (event.key.toLowerCase()) { | ||
case ' ': | ||
case 'spacebar': // older browsers might return spacebar instead of a space character | ||
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.PLAY: | ||
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK[vimEnabled.value ? 'VIM_ENABLED_PLAY' : 'PLAY']: | ||
// Toggle Play/Pause | ||
event.preventDefault() | ||
video_.paused ? video_.play() : video_.pause() | ||
break | ||
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.LARGE_REWIND: | ||
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK[vimEnabled.value ? 'VIM_ENABLED_LARGE_REWIND' : 'LARGE_REWIND']: | ||
// Rewind by 2x the time-skip interval (in seconds) | ||
event.preventDefault() | ||
seekBySeconds(-defaultSkipInterval.value * player.getPlaybackRate() * 2) | ||
|
@@ -2130,7 +2147,7 @@ export default defineComponent({ | |
event.preventDefault() | ||
changePlayBackRate(videoPlaybackRateInterval.value) | ||
break | ||
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.FULLSCREEN: | ||
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL['FULLSCREEN']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert |
||
// Toggle full screen | ||
event.preventDefault() | ||
ui.getControls().toggleFullScreen() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,20 @@ | |
:tooltip="$t('Tooltips.General Settings.Open Deep Links In New Window')" | ||
@change="updateOpenDeepLinksInNewWindow" | ||
/> | ||
<p class="vim-warning"> | ||
<FontAwesomeIcon | ||
:icon="['fas', 'circle-exclamation']" | ||
class="warning-icon" | ||
fixed-width | ||
/> | ||
{{ $t('Settings.General Settings.VIM Warning') }} | ||
</p> | ||
Comment on lines
+48
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This warning should only be shown when the setting is enabled. Just like with the checks inside the ifs, when the setting is disabled, the app and code should also act like it is disabled. |
||
<ft-toggle-switch | ||
:label="$t('Settings.General Settings.Enable VIM key-bindings')" | ||
:default-value="enableVimNavigation" | ||
:compact="true" | ||
@change="updateEnableVimNavigation" | ||
/> | ||
</div> | ||
</div> | ||
<div class="switchGrid"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently one has to restart the app after the setting is enabled and disabled, please change this so the listeners are added and removed when the setting is changed. Also keep in mind that anything that is still on screen such as the way points have to be cleaned up when the setting is disabled.