mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-10-03 14:06:51 +02:00
add editor vim hotkey
Signed-off-by: RonniSkansing <rskansing@gmail.com>
This commit is contained in:
3 files changed
+16
-1
No files matched your search
@@ -1124,6 +1124,7 @@
|
||||
<!-- vim mode toggle button -->
|
||||
<button
|
||||
type="button"
|
||||
title="Toggle vim mode (Ctrl+Alt+V)"
|
||||
on:click={() => {
|
||||
vimModeEnabled.update((v) => !v);
|
||||
}}
|
||||
|
||||
@@ -1136,7 +1136,8 @@ declare var Infinity: number;
|
||||
<span class="text-xs font-mono text-gray-500 dark:text-gray-400">JavaScript</span>
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => vimModeEnabled.update((v) => !v)}
|
||||
title="Toggle vim mode (Ctrl+Alt+V)"
|
||||
on:click={() => vimModeEnabled.update((v) => !v)}
|
||||
class="h-8 border-2 rounded-md w-20 px-3 text-center cursor-pointer hover:opacity-80 flex items-center justify-center gap-2 transition-colors duration-200"
|
||||
class:font-bold={localVimMode}
|
||||
class:bg-blue-600={localVimMode}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
import Header from '$lib/components/header/Header.svelte';
|
||||
import { setupTheme, setupOSThemeListener } from '$lib/theme.js';
|
||||
import { displayMode } from '$lib/store/displayMode';
|
||||
import { toggleVimMode } from '$lib/store/vimMode.js';
|
||||
|
||||
// services
|
||||
const session = Session.instance;
|
||||
@@ -79,6 +80,17 @@
|
||||
const pinned = getCookie('menuPinned');
|
||||
isMenuPinned = pinned === 'true';
|
||||
|
||||
// Ctrl+Alt+V (Cmd+Alt+V on macOS) toggles vim mode in every editor at once.
|
||||
// Uses e.code so it works regardless of keyboard layout, and the capture
|
||||
// phase so an editor with vim active does not swallow it first.
|
||||
const handleVimShortcut = (e) => {
|
||||
if ((e.ctrlKey || e.metaKey) && e.altKey && e.code === 'KeyV') {
|
||||
e.preventDefault();
|
||||
toggleVimMode();
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', handleVimShortcut, true);
|
||||
|
||||
(async () => {
|
||||
// handle session
|
||||
// if the user already has a active session, then the session will be
|
||||
@@ -194,6 +206,7 @@
|
||||
// on unmount
|
||||
return () => {
|
||||
console.log('layout: unmounting');
|
||||
window.removeEventListener('keydown', handleVimShortcut, true);
|
||||
// stop listening for sessions
|
||||
try {
|
||||
session.stop();
|
||||
|
||||
Reference in new issue
Block a user