diff options
author | anekos | 2011-03-30 18:34:51 +0900 |
---|---|---|
committer | anekos | 2011-03-30 20:06:05 +0900 |
commit | 370058388cbcaa8b9a3285a76920ed17cd20470c (patch) | |
tree | 822812b16c1c6ba57da91abe8ac28aff584829bf | |
parent | 40da8ca53898600cc7fad9161ccf1535882818c6 (diff) | |
download | vimperator-plugins-370058388cbcaa8b9a3285a76920ed17cd20470c.tar.bz2 |
コマンド :caret を追加。コマンドからヒントを出せるようにした
-rw-r--r-- | caret-hint.js | 103 |
1 files changed, 74 insertions, 29 deletions
diff --git a/caret-hint.js b/caret-hint.js index 0f5826c..ad374cb 100644 --- a/caret-hint.js +++ b/caret-hint.js @@ -38,12 +38,12 @@ let PLUGIN_INFO = <name>Caret Hint</name> <description>Move caret position by hint</description> <description lang="ja">Hint を使ってキャレット位置を移動</description> - <version>1.3.0</version> + <version>1.4.0</version> <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author> <license>new BSD License (Please read the source code comments of this plugin)</license> <license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license> <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/caret-hint.js</updateURL> - <minVersion>2.0pre</minVersion> + <minVersion>3.0</minVersion> <maxVersion>3.1</maxVersion> <detail><![CDATA[ Move caret position by hint. @@ -112,25 +112,25 @@ let PLUGIN_INFO = let swapKey = gval('caret_hint_swap_key', 's'); let hintXPath = liberator.globalVariables.caret_hint_xpath || '//*'; - let extendMode = false; - [ - [[true, false], headMode], - [[false, false], tailMode], - [[true, true ], selectHeadMode], - [[false, true ], selectTailMode], - ].forEach(function ([[h, s], m, d]) { - if (!m) - return; - hints.addMode( - m, - 'Move caret position to ' + (h ? 'head' : 'tail') + (s ? ' and Select' : ''), - function (elem, loc, count) { - moveCaret(elem, h, s); - extendMode = false; - }, - function () hintXPath - ); + [[true, false], ['caret-hint-move-head', headMode]], + [[false, false], ['caret-hint-move-tail', tailMode]], + [[true, true ], ['caret-hint-select-head', selectHeadMode]], + [[false, true ], ['caret-hint-select-tail', selectTailMode]], + ].forEach(function ([[h, s], ms]) { + ms.forEach(function (m) { + if (!m) + return; + hints.addMode( + m, + 'Move caret position to ' + (h ? 'head' : 'tail') + (s ? ' and Select' : ''), + function (elem, loc, count) { + moveCaret(elem, h, s); + extendMode = false; + }, + function () hintXPath + ); + }); }); if (swapKey) { @@ -143,6 +143,60 @@ let PLUGIN_INFO = ); } + commands.addUserCommand( + ['caret'], + 'Caret control with hint', + function (args) { + }, + { + subCommands: [ + new Command( + ['m[ove]'], + 'Move caret', + function () {}, + { + subCommands: [ + new Command( + ['h[ead]'], + 'Move caret to head of selected element', + function () hints.show('caret-hint-move-head'), + {} + ), + new Command( + ['t[ail]'], + 'Move caret to head of selected element', + function () hints.show('caret-hint-move-tail'), + {} + ) + ] + } + ), + new Command( + ['select'], + 'Select a element', + function () {}, + { + subCommands: [ + new Command( + ['h[ead]'], + 'Select and move caret to head of selected element', + function () hints.show('caret-hint-select-head'), + {} + ), + new Command( + ['t[ail]'], + 'Select and move caret to tail of selected element', + function () hints.show('caret-hint-select-tail'), + {} + ) + ] + } + ) + ] + }, + true + ); + function gval (name, def) { let v = liberator.globalVariables[name]; @@ -187,15 +241,6 @@ let PLUGIN_INFO = mappings.getDefault(modes.NORMAL, CaretKey).action(); } - if (extendMode) { - let a = sel.getRangeAt(0); - if (r.compareBoundaryPoints(Range.END_TO_START, a) < 0) { - r.setEnd(a.endContainer, a.endOffset); - } else { - r.setStart(a.startContainer, a.startOffset); - } - } - sel.addRange(r); if (select && head) |