ScrapVim-lite-3/KeyInput
code:script.js
import {js2vim} from '/api/code/takker/Vim-keymap-converter/script.js';
import {scrapboxDOM} from '/api/code/takker/scrapbox-dom-accessor/script.js';
export class KeyInput {
constructor() {
this._started = false;
this._preventDefaultCallback = undefined;
this._deleteCompositionCharsCallback = undefined;
}
start() {
if (this._started) return;
scrapboxDOM.editor.addEventListener('keydown', e => this._handleKeyDown(e));
scrapboxDOM.editor.addEventListener('compositionend', e => this._handleCompositionEnd(e));
this._started = true;
}
やること
キー入力を取得する
keydownのイベント監視
code:script.js
_handleKeyDown(e) {
const keyMap = js2vim(e);
}
compositionendのイベント監視
流し込まれた文字列を削除するかどうかは外部の関数で決める
callback関数を外部から指定してもらう?
キー入力のイベント監視と、キー入力を変換する部分とを切り分ける?
イメージ
this.converter(e, (key)=>this.mode.preventDefault(key)).forEach(key=>this.mode.parse(key))
default動作を握りつぶす
Normal Modeで文字入力を無効にしたりするのに使う