Handling Unicode #6

そういうわけでぼちぼちと wasavi に組み込み始める。

まずは簡単そうな [cci]motionLeft()[/cci] からとりかかってみよう。

function motionLeft (c, count) {
// カウントの値を正規化
count || (count = 1);

// 現在のカーソル位置
var n = buffer.selectionStart;

// 現在行の書記素クラスタ群
var clusters = getGraphemeClusters(n);

// カーソルが位置する書記素クラスタのインデックス
var clusterIndex = clusters.getClusterIndexFromUTF16Index(n.col);

// 移動できないならメッセージを生成
if (c != '' && clusterIndex <= 0) { requestNotice({silent:_('Top of line.')}); } // 書記素クラスタ単位でカウント分戻る // ただし、0 未満にはしない if (clusters.length) { n.col = clusters.rawIndexAt(Math.max( clusterIndex - count, 0)); } // バッファのカーソル位置に上書き buffer.selectionStart = n; // キー名をコマンド列に追加 prefixInput.motion = c; // 水平移動なので、"記憶された水平位置" は更新する必要がある invalidateIdealWidthPixels(); // コマンド実行完了 return true; }

とこんなように Unicode のめんどくさい部分は全て Unistring が面倒を見てくれる。

Leave a Reply

Your email address will not be published. Required fields are marked *