pull/662/head
Zef Hemel 2024-01-24 14:03:14 +01:00
parent 488fa84d50
commit a9ce68860e
4 changed files with 12 additions and 16 deletions

View File

@ -14,8 +14,8 @@ safeRun(async () => {
document.getElementById("sb-root")!,
syncMode,
);
await client.init();
window.client = client;
await client.init();
});
if (navigator.serviceWorker) {

View File

@ -20,6 +20,7 @@ import {
vim,
vimGetCm,
} from "../deps.ts";
import { createCommandKeyBindings } from "../editor_state.ts";
type MiniEditorEvents = {
onEnter: (newText: string, shiftDown?: boolean) => void;
@ -197,6 +198,7 @@ export function MiniEditor(
...standardKeymap,
...historyKeymap,
...completionKeymap,
...createCommandKeyBindings(window.client),
]),
EditorView.domEventHandlers({
click: (e) => {

View File

@ -261,7 +261,7 @@ export function createEditorState(
});
}
export function createKeyBindings(client: Client): Extension {
export function createCommandKeyBindings(client: Client): KeyBinding[] {
const commandKeyBindings: KeyBinding[] = [];
// Track which keyboard shortcuts for which commands we've overridden, so we can skip them later
@ -336,8 +336,13 @@ export function createKeyBindings(client: Client): Extension {
});
}
}
return commandKeyBindings;
}
export function createKeyBindings(client: Client): Extension {
return keymap.of([
...commandKeyBindings,
...createCommandKeyBindings(client),
...smartQuoteKeymap,
...closeBracketsKeymap,
...standardKeymap,
@ -345,16 +350,5 @@ export function createKeyBindings(client: Client): Extension {
...historyKeymap,
...completionKeymap,
indentWithTab,
{
key: "Ctrl-.",
mac: "Cmd-.",
run: (): boolean => {
client.ui.viewDispatch({
type: "show-palette",
context: client.getContext(),
});
return true;
},
},
]);
}

View File

@ -12,7 +12,6 @@ import {
preactRender,
RefreshCwIcon,
runScopeHandlers,
TemplateIcon,
TerminalIcon,
useEffect,
useReducer,
@ -30,10 +29,11 @@ export class MainUI {
// Make keyboard shortcuts work even when the editor is in read only mode or not focused
globalThis.addEventListener("keydown", (ev) => {
if (!client.editorView.hasFocus) {
if ((ev.target as any).closest(".cm-editor")) {
if ((ev.target as any).closest(".cm-content")) {
// In some cm element, let's back out
return;
}
console.log("Delegated keydown", ev, "to editor");
if (runScopeHandlers(client.editorView, ev, "editor")) {
ev.preventDefault();
}