// // _smooziee.js // // LICENSE: {{{ // Copyright (c) 2009 snaka // // distributable under the terms of an MIT-style license. // http://www.opensource.jp/licenses/mit-license.html // }}} // // INFO: {{{ var INFO = xml` snaka MIT style license

j,k key scrolling to be smoothly.

Global vriables

You can configure following variable as you like.

smooziee_scroll_amount
Scrolling amount(unit:px). Default value is 400px.
smooziee_interval
Scrolling interval(unit:ms). Default value is 20ms.

Example

Set scroll amount is 300px and interval is 10ms.

API

smooziee.smoothScrollBy(amount);

Example

snaka MIT style license

普段のj,kキーのスクロールをLDRizeライクにスムースにします。

グローバル変数

以下の変数を.vimperatorrcなどで設定することで動作を調整することができます。

smooziee_scroll_amount
1回にスクロールする幅です(単位:ピクセル)。デフォルトは"400"です。
smooziee_interval
スクロール時のアニメーションのインターバルです(単位:ミリ秒)。 "1"以上の値を設定します。デフォルトは"20"です。

設定例

スクロール量を300pxに、インターバルを10msに設定します。

API

他のキーにマップする場合やスクリプトから呼び出せるようAPIを用意してます。

smooziee.smoothScrollBy(amount);

Example

ToDo

  • 読み込みの順番によっては他のプラグインと競合する可能性があるのをなんとかしたい。
`; // }}} let self = liberator.plugins.smooziee = (function(){ mappings.addUserMap( [modes.NORMAL], ["j"], "Smooth scroll down", function(count){ self.smoothScrollBy(getScrollAmount()); }, { count: true } ); mappings.addUserMap( [modes.NORMAL], ["k"], "Smooth scroll up", function(count){ self.smoothScrollBy(getScrollAmount() * -1); }, { count: true } ); var next; var win; var interval; var PUBLICS = { smoothScrollBy: function(moment) { win = Buffer.findScrollableWindow(); interval = window.eval(liberator.globalVariables.smooth_scroll_interval || '30'); clearTimeout(next); smoothScroll(moment); } } function logBase(x, y) { // Logarithm of arbitrary base `x` return Math.log(y) / Math.log(x); } function getScrollAmount() { // see recognition of Fibonacci Numbers (here approximation is used) // http://en.wikipedia.org/wiki/Fibonacci_number#Recognizing_Fibonacci_numbers phi = 1.618033; sqrt5 = 2.236067; fn = liberator.globalVariables.smooth_scroll_amount || '150' n = Math.ceil(logBase(phi, (fn * sqrt5 + Math.sqrt(5 * Math.pow(fn, 2) + 4)) / 2)) return window.eval(n); } function fib(n){ // see optimized Binet's formula for Fibonacci sequence // http://en.wikipedia.org/wiki/Fibonacci_number#Closed_form_expression phi = 1.618033; sqrt5 = 2.236067; return Math.floor((Math.pow(phi, n) / sqrt5) + 0.5) } function smoothScroll(moment) { if (moment > 0) { moment = moment - 1; win.scrollBy(0, fib(Math.abs(moment))); } else { moment = moment + 1; win.scrollBy(0, -fib(Math.abs(moment))); } if (moment == 0) return; next = setTimeout(function() smoothScroll(moment), interval); } return PUBLICS; })(); // vim: sw=2 ts=2 et si fdm=marker: