mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-14 05:15:19 +00:00
26 lines
759 B
TypeScript
26 lines
759 B
TypeScript
|
|
'use client';
|
||
|
|
|
||
|
|
import { EditorView, keymap } from "@uiw/react-codemirror";
|
||
|
|
import { useExtensionWithDependency } from "./useExtensionWithDependency";
|
||
|
|
import { useKeymapType } from "./useKeymapType";
|
||
|
|
import { defaultKeymap } from "@codemirror/commands";
|
||
|
|
import { vim } from "@replit/codemirror-vim";
|
||
|
|
|
||
|
|
export const useKeymapExtension = (view: EditorView | undefined) => {
|
||
|
|
const [keymapType] = useKeymapType();
|
||
|
|
|
||
|
|
const extension = useExtensionWithDependency(
|
||
|
|
view ?? null,
|
||
|
|
() => {
|
||
|
|
switch (keymapType) {
|
||
|
|
case "default":
|
||
|
|
return keymap.of(defaultKeymap);
|
||
|
|
case "vim":
|
||
|
|
return vim();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
[keymapType]
|
||
|
|
);
|
||
|
|
|
||
|
|
return extension;
|
||
|
|
}
|