English

@vimee/react

vimee の React フックとバインディング

vimee の React バインディング。シームレスな統合のための useVim フックを提供します。

インストール

npm install @vimee/core @vimee/react

useVim

React コンポーネントに vimee を統合するための主要フック:

import { useVim } from "@vimee/react";

function Editor() {
  const { content, cursor, mode, handleKeyDown } = useVim({
    content: "Hello, vimee!",
  });

  return (
    <div onKeyDown={handleKeyDown} tabIndex={0}>
      <pre>{content}</pre>
      <div>Mode: {mode} | Cursor: {cursor.line}:{cursor.col}</div>
    </div>
  );
}

オプション

オプションデフォルト説明
contentstring(必須)初期エディターコンテンツ
cursorPositionstring"1:1"初期カーソル位置(1ベース、"line:col"
readOnlybooleanfalse編集を無効にする
onChange(content: string) => voidコンテンツ変更時に呼ばれる
onYank(text: string) => voidヤンク時に呼ばれる
onSave(content: string) => void:w 時に呼ばれる
onModeChange(mode: VimMode) => voidモード変更時に呼ばれる
onAction(action: VimAction, key: string) => voidすべてのアクションで呼ばれる
indentStyle"space" | "tab""space"インデント文字
indentWidthnumber2インデント幅
keybindsKeybindEntry[]カスタムキーバインド
commandsCommandEntry[]カスタム ex コマンド

戻り値

フィールド説明
contentstring現在のバッファコンテンツ
cursorCursorPosition現在のカーソル位置(0ベース)
modeVimMode現在の Vim モード
statusMessagestringステータスバーメッセージ
statusErrorbooleanステータスがエラーかどうか
visualAnchorCursorPosition | nullビジュアルモードのアンカー
commandLinestring入力中の Ex コマンド
handleKeyDown(e: React.KeyboardEvent) => voidonKeyDown にアタッチ
handleScroll(direction, visibleLines, amount?) => voidスクロールハンドラー
updateViewport(topLine, height) => voidビューポート同期