ScrapVim-lite-3/CommandStorage
コマンドと入力文字列との対応表を管理するクラス
やること
各種類ごとの対応表の取得
カスタムコマンドの登録
map {lhs} {rhs}の解決は別のクラスでやる
globalに定義して、任意の場所からaccessできるようにしたいけど、難しいか?
02:35:52 できるみたい!
普通に変数をexportすればいいようだ
簡単じゃん!
interface
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を渡すと、そのコマンド定義を削除する
どう作ろうかな
入り組んでいるしちょっと無理か。
具体的なStateに対して考えてみる
OperatorState
code:ts
const operators = {
'd': ({register?: Register, count?: number, range: {
command: (props: RangeParams) => Selections;
params: RangeParams;
}}) => void,
};
それぞれのコマンドで違う型にしちゃうか。
MotionState
基本的にこのstateでcommandが確定する
RegisterState
"aなど、いくつかの文字列が対象
OperatorState, UseRegisterState, CountStateを返す
UseRegisterState
registerは使うがmotionは使わないcommandを扱う
x, p, dd, Dなど
CountState