ScrapVim-lite-3/CommandStorage
コマンドと入力文字列との対応表を管理するクラス
ScrapVim-lite-3/CommandStorage
やること
各種類ごとの対応表の取得
カスタムコマンドの登録
map {lhs} {rhs}の解決は別のクラスでやる
globalに定義して、任意の場所からaccessできるようにしたいけど、難しいか?
propsバケツリレーみたいなことは避けたいのだが
02:35:52 できるみたい!
モジュールコードはインポート時の初回にのみ評価されます | モジュール, 導入
普通に変数をexportすればいいようだ
簡単じゃん!
interface
ScrapVim-lite-3/command文字列とVimCommandとの対応リストは別のファイルで定義しておく
code:script.js
import {normalModeCommands} from ;
class CommandStorage {
constructor() {
this._normalMode = {...normalModeCommands};
this._insertMode = {};
};
コマンドリストの取得
modeごとにcommandを提供する
get normalMode()
get insertMode()
get visualMode()
これmodeが増えたらscaleしないのでは?
そんなにmodeがたくさんあるわけでもないし、別に良いか。
コマンドの追加と削除
this.push({mode: string,type: string, keys: string, command: object})
typeにコマンドの種類を渡す
operatorやmotionなど
commandにundefinedを渡すと、そのコマンド定義を削除する
ScrapVim-lite-3/command文字列とVimCommandとの対応リスト
どう作ろうかな
安直なのは、文字列とScrapVim-lite-3/VimCommandとのセットを作ることだけど
入り組んでいるしちょっと無理か。
具体的なStateに対して考えてみる
OperatorState
code:ts
const operators = {
'd': ({register?: Register, count?: number, range: {
command: (props: RangeParams) => Selections;
params: RangeParams;
}}) => void,
};
それぞれのコマンドで違う型にしちゃうか。
MotionState
motion (vim)を扱う
基本的にこのstateでcommandが確定する
RegisterState
register (vim)を扱う
"aなど、いくつかの文字列が対象
OperatorState, UseRegisterState, CountStateを返す
UseRegisterState
registerは使うがmotionは使わないcommandを扱う
x, p, dd, Dなど
CountState
#2020-12-18 02:13:35