TextAreaのundoの実装3
残りは、KEY_DOWNにundoしたときの処理を書くだけ。
KEY_DOWN
private function onKeyDown(e : KeyboardEvent) : void { prepareHistory(); if (e.ctrlKey && e.keyCode == Keyboard.Z) { var item : Object = history.pop(); if (item) { ta.text = ta.text.substring(0, item.index) + item.minus + ta.text.substring(item.index + item.plus.length); ta.selectionBeginIndex = item.index; ta.selectionEndIndex = item.index; } } next(run); }
historyに何もない場合はpopの結果はundefinedになるので何もしない。
ta.textに対してsubstringを実行している時点でO(L)かかっているんだろうか・・