Fixes #638
parent
488fa84d50
commit
a9ce68860e
|
@ -14,8 +14,8 @@ safeRun(async () => {
|
|||
document.getElementById("sb-root")!,
|
||||
syncMode,
|
||||
);
|
||||
await client.init();
|
||||
window.client = client;
|
||||
await client.init();
|
||||
});
|
||||
|
||||
if (navigator.serviceWorker) {
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue