zzztzbzsze
タイトル通り vim の zz、zt、zb、zs、ze っぽい動作を作ってみた。
NORMAL,VISUAL,CARET で動作します。
NORMAL だと、カーソル位置が見えないので範囲選択していないと、
どこを基準にしているか分からないです。
あと、vim で 水平のセンター移動するmapが 分からなかったので、
「z;」で 定義しています。
基本的に aData を 調整すれば いろいろなタイプを量産できます。
(ご利用していただける方は標準のmappingに すら 被ってる状態なので、適当に調整して下さい)
なお、anchor と focus が 同じノードの
前後判定は 放棄してますorz
// vim: set fdm=marker : (function(){ //{{{ config var aModes = [ modes.NORMAL, modes.CARET, modes.VISUAL ]; var aData = { zb: [100, -1, true], zz: [50 , -1], zt: [0 , -1], zs: [-1, 0], ze: [-1, 100, true], "z;": [-1, 50], }; //}}} function selectionScroll(aVPercent, aHPercent, isFocus){ try{ var win = content.window; var doc = content.document; var selection = win.getSelection(); isFocus = isFocus === true; if(!selection) return; if(!selection.anchorNode || !selection.focusNode) return; //{{{ 指定範囲の方向判定 if(selection.anchorNode !== selection.focusNode){ var r1,r2; r1 = doc.createRange(); r1.setStart(selection.anchorNode,0); r2 = doc.createRange(); r2.setStart(selection.focusNode,0); if(r1.compareBoundaryPoints(Range.START_TOSTART,r2) > 0){ isFocus = !isFocus; } }//}}} selection .QueryInterface(Ci.nsISelection2) .scrollIntoView( isFocus ? Ci.nsISelectionController.SELECTION_FOCUS_REGION : Ci.nsISelectionController.SELECTION_ANCHOR_REGION ,true, aVPercent, aHPercent); }catch(ex){liberator.echoerr(ex);} } for(let [cmd,data] in Iterator(aData)){ mappings.addUserMap(aModes,[cmd], "scroll", (function(a) function(){selectionScroll.apply(this,a);} )(data)); } })();