Skip to content

Commit

Permalink
feat(web): Improve vim key map
Browse files Browse the repository at this point in the history
  • Loading branch information
thien-do committed Sep 3, 2022
1 parent 84b7a27 commit 472999d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/web/editor/status/status.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef } from "react";
import { initVimMode } from "monaco-vim";
import { initVimMode, VimMode } from "monaco-vim";
import { Settings } from "../../settings/type";
import { Editor } from "../type";
import * as s from "./status.module.css";
Expand All @@ -10,13 +10,23 @@ interface Props {
settings: Settings;
}

const envDone = { current: false };

const createEnv = () => {
if (envDone.current) return;
VimMode.Vim.map("jj", "<Esc>", "insert");
VimMode.Vim.map("jk", "<Esc>", "insert");
envDone.current = true;
};

export const EditorStatus = (props: Props): JSX.Element => {
const { editor, settings } = props;
const statusRef = useRef<HTMLDivElement>(null);

const { vim: settingsVim } = settings;
useEffect(() => {
if (settingsVim === false) return;
createEnv();

const status = statusRef.current;
if (status === null) throw Error("`status` is null");
Expand Down

1 comment on commit 472999d

@vercel
Copy link

@vercel vercel bot commented on 472999d Sep 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.