Fixes #638
parent
488fa84d50
commit
a9ce68860e
|
@ -14,8 +14,8 @@ safeRun(async () => {
|
||||||
document.getElementById("sb-root")!,
|
document.getElementById("sb-root")!,
|
||||||
syncMode,
|
syncMode,
|
||||||
);
|
);
|
||||||
await client.init();
|
|
||||||
window.client = client;
|
window.client = client;
|
||||||
|
await client.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (navigator.serviceWorker) {
|
if (navigator.serviceWorker) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import {
|
||||||
vim,
|
vim,
|
||||||
vimGetCm,
|
vimGetCm,
|
||||||
} from "../deps.ts";
|
} from "../deps.ts";
|
||||||
|
import { createCommandKeyBindings } from "../editor_state.ts";
|
||||||
|
|
||||||
type MiniEditorEvents = {
|
type MiniEditorEvents = {
|
||||||
onEnter: (newText: string, shiftDown?: boolean) => void;
|
onEnter: (newText: string, shiftDown?: boolean) => void;
|
||||||
|
@ -197,6 +198,7 @@ export function MiniEditor(
|
||||||
...standardKeymap,
|
...standardKeymap,
|
||||||
...historyKeymap,
|
...historyKeymap,
|
||||||
...completionKeymap,
|
...completionKeymap,
|
||||||
|
...createCommandKeyBindings(window.client),
|
||||||
]),
|
]),
|
||||||
EditorView.domEventHandlers({
|
EditorView.domEventHandlers({
|
||||||
click: (e) => {
|
click: (e) => {
|
||||||
|
|
|
@ -261,7 +261,7 @@ export function createEditorState(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createKeyBindings(client: Client): Extension {
|
export function createCommandKeyBindings(client: Client): KeyBinding[] {
|
||||||
const commandKeyBindings: KeyBinding[] = [];
|
const commandKeyBindings: KeyBinding[] = [];
|
||||||
|
|
||||||
// Track which keyboard shortcuts for which commands we've overridden, so we can skip them later
|
// 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([
|
return keymap.of([
|
||||||
...commandKeyBindings,
|
...createCommandKeyBindings(client),
|
||||||
...smartQuoteKeymap,
|
...smartQuoteKeymap,
|
||||||
...closeBracketsKeymap,
|
...closeBracketsKeymap,
|
||||||
...standardKeymap,
|
...standardKeymap,
|
||||||
|
@ -345,16 +350,5 @@ export function createKeyBindings(client: Client): Extension {
|
||||||
...historyKeymap,
|
...historyKeymap,
|
||||||
...completionKeymap,
|
...completionKeymap,
|
||||||
indentWithTab,
|
indentWithTab,
|
||||||
{
|
|
||||||
key: "Ctrl-.",
|
|
||||||
mac: "Cmd-.",
|
|
||||||
run: (): boolean => {
|
|
||||||
client.ui.viewDispatch({
|
|
||||||
type: "show-palette",
|
|
||||||
context: client.getContext(),
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
preactRender,
|
preactRender,
|
||||||
RefreshCwIcon,
|
RefreshCwIcon,
|
||||||
runScopeHandlers,
|
runScopeHandlers,
|
||||||
TemplateIcon,
|
|
||||||
TerminalIcon,
|
TerminalIcon,
|
||||||
useEffect,
|
useEffect,
|
||||||
useReducer,
|
useReducer,
|
||||||
|
@ -30,10 +29,11 @@ export class MainUI {
|
||||||
// Make keyboard shortcuts work even when the editor is in read only mode or not focused
|
// Make keyboard shortcuts work even when the editor is in read only mode or not focused
|
||||||
globalThis.addEventListener("keydown", (ev) => {
|
globalThis.addEventListener("keydown", (ev) => {
|
||||||
if (!client.editorView.hasFocus) {
|
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
|
// In some cm element, let's back out
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("Delegated keydown", ev, "to editor");
|
||||||
if (runScopeHandlers(client.editorView, ev, "editor")) {
|
if (runScopeHandlers(client.editorView, ev, "editor")) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue