1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-09 03:54:11 +01:00

Add {, }, [{arg}, ]{arg}. Closes issue #592.

This commit is contained in:
Kris Maglione
2011-07-28 00:09:37 -04:00
parent 2b43cf0660
commit a63d61612d
8 changed files with 118 additions and 5 deletions

View File

@@ -797,6 +797,37 @@ var Buffer = Module("buffer", {
return win;
},
/**
* Finds the next visible element for the node path in 'jumptags'
* for *arg*.
*
* @param {string} arg The element in 'jumptags' to use for the search.
* @param {number} count The number of elements to jump.
* @optional
* @param {boolean} reverse If true, search backwards. @optional
*/
findJump: function findJump(arg, count, reverse) {
const FUDGE = 10;
let path = options["jumptags"][arg];
dactyl.assert(path, _("error.invalidArgument", arg));
let distance = reverse ? function (rect) -rect.top : function (rect) rect.top;
let elems = [[e, distance(e.getBoundingClientRect())] for (e in path.matcher(this.focusedFrame.document))]
.filter(function (e) e[1] > FUDGE)
.sort(function (a, b) a[1] - b[1])
let idx = Math.min((count || 1) - 1, elems.length);
dactyl.assert(idx in elems);
let elem = elems[idx][0];
elem.scrollIntoView(true);
let sel = elem.ownerDocument.defaultView.getSelection();
sel.removeAllRanges();
sel.addRange(RangeFind.endpoint(RangeFind.nodeRange(elem), true));
},
// TODO: allow callback for filtering out unwanted frames? User defined?
/**
* Shifts the focus to another frame within the buffer. Each buffer
@@ -1742,6 +1773,26 @@ var Buffer = Module("buffer", {
function (args) { buffer.shiftFrameFocus(-Math.max(args.count, 1)); },
{ count: true });
mappings.add([modes.NORMAL], ["["],
"Jump to the previous element as defined by 'jumptags'",
function (args) { buffer.findJump(args.arg, args.count, true); },
{ arg: true, count: true });
mappings.add([modes.NORMAL], ["]"],
"Jump to the next element as defined by 'jumptags'",
function (args) { buffer.findJump(args.arg, args.count, false); },
{ arg: true, count: true });
mappings.add([modes.NORMAL], ["{"],
"Jump to the previous paragraph",
function (args) { buffer.findJump("p", args.count, true); },
{ count: true });
mappings.add([modes.NORMAL], ["}"],
"Jump to the next paragraph",
function (args) { buffer.findJump("p", args.count, false); },
{ count: true });
mappings.add([modes.NORMAL], ["]]", "<next-page>"],
"Follow the link labeled 'next' or '>' if it exists",
function (args) {
@@ -1937,6 +1988,23 @@ var Buffer = Module("buffer", {
validator: function (value) RegExp(value)
});
options.add(["jumptags", "jt"],
"XPath or CSS selector strings of jumpable elements for extended hint modes",
"stringmap", {
"p": "p,table,ul,ol,blockquote",
"h": "h1,h2,h3,h4,h5,h6"
},
{
keepQuotes: true,
setter: function (vals) {
for (let [k, v] in Iterator(vals))
vals[k] = update(new String(v), { matcher: util.compileMatcher(Option.splitList(v)) });
return vals;
},
validator: function (value) util.validateMatcher.call(this, value)
&& Object.keys(value).every(function (v) v.length == 1)
});
options.add(["nextpattern"],
"Patterns to use when guessing the next page in a document sequence",
"regexplist", UTF8("'\\bnext\\b',^>$,^(>>|»)$,^(>|»),(>|»)$,'\\bmore\\b'"),

View File

@@ -1016,6 +1016,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
};
}
else if (obj instanceof Option) {
tag = spec = function (name) <>'{name}'</>;
link = function (opt, name) <o>{name}</o>;
args = { value: "", values: [] };
}

View File

@@ -328,6 +328,39 @@
</description>
</item>
<item>
<tags>[h [p [</tags>
<spec><oa>count</oa>[<a>arg</a></spec>
<description short="true">
<p>Jump to the previous element as defined by <o>jumptags</o>.</p>
</description>
</item>
<item>
<tags>]h ]p ]</tags>
<spec><oa>count</oa>]<a>arg</a></spec>
<description short="true">
<p>Jump to the next element as defined by <o>jumptags</o>.</p>
</description>
</item>
<item>
<tags>{</tags>
<spec><oa>count</oa>{</spec>
<description short="true">
<p>Jump to the previous paragraph. Identical to <k>[p</k>.</p>
</description>
</item>
<item>
<tags>}</tags>
<spec><oa>count</oa>}</spec>
<description short="true">
<p>Jump to the next paragraph. Identical to <k>]p</k>.</p>
</description>
</item>
<h2 tag="zooming zoom">Zooming</h2>
<p>

View File

@@ -987,6 +987,16 @@
</description>
</item>
<item>
<tags>'jt' 'jumptags'</tags>
<spec>'jumptags'</spec>
<type>&option.jumptags.type;</type>
<default>&option.jumptags.default;</default>
<description>
<p>XPath or CSS selector strings of jumpable elements for extended hint modes.</p>
</description>
</item>
<item>
<tags>'lpl' 'loadplugins'</tags>
<spec>'loadplugins' 'lpl'</spec>

View File

@@ -247,7 +247,7 @@ var Template = Module("Template", {
linkifyHelp: function linkifyHelp(str, help) {
let re = util.regexp(<![CDATA[
(?P<pre> [/\s]|^)
(?P<tag> '[\w-]+' | :(?:[\w-]+!?|!) | (?:._)?<[\w-]+>\w* | [a-zA-Z]_\w+ | \[[\w-]+\] | E\d{3} )
(?P<tag> '[\w-]+' | :(?:[\w-]+!?|!) | (?:._)?<[\w-]+>\w* | \b[a-zA-Z]_(?:\w+|.) | \[[\w-]+\] | E\d{3} )
(?= [[\)!,:;./\s]|$)
]]>, "gx");
return this.highlightSubstrings(str, (function () {

View File

@@ -620,7 +620,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
range.selectNode(node);
node = range;
}
let doc = (node.getRangeAt ? node.getRangeAt(0) : node).startContainer.ownerDocument;
let doc = (node.getRangeAt ? node.getRangeAt(0) : node).startContainer;
doc = doc.ownerDocument || doc;
let encoder = services.HtmlEncoder();
encoder.init(doc, "text/unicode", encoder.OutputRaw|encoder.OutputPreformatted);