generated at
ScrapVim-lite-2
ScrapVim-liteからいらないcodeを消し、moduleに分割する
command実行
座標から文字の位置を取得したいな
command解釈
入力されたキーを一つづつ解釈する
keymapを解釈し、それにあったcommandを実行する
mode changeも内包していて、ややこしくなっている
class使ったほうがよさそうなので使うtakker

2020-11-26
07:35:56 Insert Mode以外でIMEを使えないようにした
入力確定後に流し込まれた文字を全て消す
2020-11-24
17:33:03 ^ の挙動を少し直した
リンクやコードブロック名が先頭にあると動かない
21:21:47 dd , D , cc を追加した
21:11:14 initial version

既知の問題とか
単語移動がややバグっている
b が空行にはまると移動しなくなる
LFの扱いがいい加減なのが原因?
これも一つの原因
code blockやリンクの中にcursorをmouseで動かせないのが原因の一つ
前versionみたくキー連打で動かすしかなさそう
cursorの扱いをvimに揃えよう
Normal→insert
cursorの左側に縦棒が出る
insert → normal
縦棒の右側にcursorが出る
縦棒が行頭にあるときは左側に出る
doinghl
行頭及び行末に到達したらそれ以上動かない
行を変えられない
折返しのある行を正常に認識できない
折り返した地点から、 cursor.index 0 にresetされてしまう
^ がバグっている
リンクがある行とかでうまく動かない?
2020-11-25 17:17:41 原因その1
先頭に空白がないとき、 match()?.[0] にはその行の非空白文字が入ってしまう
原因その2
jumpToChar ではリンク内部に飛べない
mode changeを一つの独立した機能に分割する
modeを切り替えるごとにParserを切り替える?
parserも分割するか
実際のキー入力を読み取ってコマンド文字列を組み立てる
コマンド文字列から適切なコマンドを呼び出す
この分け方もなんか違うな。いやこれでいいか
コマンドと文字列の対応リストを作っておけばいい
そして動的にも組み替えられるからカスタムkeymapの反映もしやすくなりそう
parserの方はキー入力の解釈に専念できる
visual modeを実装したい
commandに渡すparameterを全て同じにする?
command側で必要な変数だけを取り出す
failNormal modeで間違ってIMEに入力してしまったキーを解釈してcommandとして実行したい
1文字入力されるごとにcompositionupdateで検知する
IMEに入力した文字はEnter+Backspaceで削除する
scrapbox-keyboard-emulationではIMEにキー入力を渡せないみたい
KeyboardEvent.isComposingをtrueにすれば渡せるか?
done仕方ないので、ScrapVim-lite#5fb8c6581280f0000041d123を使って入力され文字を消すだけにする
line.id ではなく行番号を使って位置をやり取りするように変える
id だと getElementById をつかっていちいち探さないといけないが、 lines[number] なら配列から取得する操作だけで済む

import
script.js
import {getCharFromPosision} from '/api/code/takker/scrapbox-line-info/script.js'; import {isMobile} from '/api/code/takker/mobile版scrapboxの判定/script.js'; import {Parser} from '/api/code/takker/ScrapVim-lite-2%2Fparser/script.js';

script.js
export class ScrapVim { constructor() { if (isMobile()) { this._enable = false; return; } this._enable = true; this._isDebug = false; //this.statusBar = createKeyViewer(); this.editor = document.getElementById('editor'); this.lines = this.editor.getElementsByClassName('lines')?.[0]; this.cursor = document.getElementById('text-input'); this.cursorBar = document.getElementsByClassName('cursor')?.[0]; this.parser = new Parser({ editor: this.editor, lines: this.lines, cursorBar: this.cursorBar, cursor: this.cursor, cursorInfo: () => this.cursorInfo, }); } start() { if (!this._enable) return; this.parser.start(); const cssId = 'scrapbox-normal-mode'; let style = document.getElementById(cssId); style?.remove() document.head.insertAdjacentHTML('beforeend',` <style id="${cssId}"> @import "/api/code/takker/ScrapVim-lite/cursor.css"; </style> `); } get cursorLine() { return this.lines.getElementsByClassName('cursor-line')?.[0]; } get cursorInfo() { const {left} = this.cursorBar.getBoundingClientRect(); const line = this.cursorLine; const {target, index} = getCharFromPosision(left, line); this._log('%o',{target: target, cursor: {line: line, index: index}}); return {target: target, cursor: {line: line, index: index}}; }

debug用
script.js
_log(msg, ...objects) { if (!this._isDebug) return; if (objects.length > 0) { console.log(`[scrapVim-lite-2] ${msg}`, ...objects); return; } console.log(`[scrapVim-lite-2] ${msg}`); } }

#2020-11-26 06:32:34
#2020-11-25 10:03:08
#2020-11-25 09:40:07
#2020-11-24 15:47:14