Skip to content

Instantly share code, notes, and snippets.

@amzyang
Created April 28, 2011 10:55
Show Gist options
  • Select an option

  • Save amzyang/946158 to your computer and use it in GitHub Desktop.

Select an option

Save amzyang/946158 to your computer and use it in GitHub Desktop.
var INFO =
<plugin name="findhere" version="0.0.1"
href="http://www.slimeden.com"
summary="Find from the start of current screen"
xmlns="http://vimperator.org/namespaces/liberator">
<author email="wuxiaoshan@gmail.com">Xiao Shan</author>
<license href="http://people.freebsd.org/~phk/">BEER-WARE</license>
<project name="Vimperator" minVersion="2.3"/>
<p>
This plugin makes inner find from the start of current screen.
</p>
<item>
<tags>'findhere'</tags>
<spec>:findhere</spec>
<description>
<p>This plugin makes inner find from the start of current screen.</p>
</description>
</item>
</plugin>;
(function() {
function moveCaret(elem) {
let doc = elem.ownerDocument;
let win = new XPCNativeWrapper(window.content.window);
let sel = win.getSelection();
let r = doc.createRange();
sel.removeAllRanges();
r.selectNodeContents(elem);
sel.addRange(r);
r.setEnd(r.startContainer, r.startOffset);
modes.push(modes.CARET);
modes.pop();
}
window.findFirstTarget = function(){
var win = content;
var doc = win.document;
function getContainerOffsets(doc) {
var body = doc.body || doc.documentElement;
var style = util.computedStyle(body);
if (style && /^(absolute|fixed|relative)$/.test(style.position)) {
let rect = body.getClientRects()[0];
return [-rect.left, -rect.top];
}
else
return [doc.defaultView.scrollX, doc.defaultView.scrollY];
}
var offsets = { left: 0, right: 0, top: 0, bottom: 0 };
offsets.right = win.innerWidth - offsets.right;
offsets.bottom = win.innerHeight - offsets.bottom;
function isVisible(elem) {
let rect = elem.getBoundingClientRect();
if (!rect || !rect.width || !rect.height ||
rect.top < offsets.top || rect.bottom > offsets.bottom ||
rect.left < offsets.left || rect.right > offsets.right) {
return false;
}
let computedStyle = doc.defaultView.getComputedStyle(elem, null);
if (computedStyle.visibility != "visible" || computedStyle.display == "none") {
return false;
}
return true;
}
hints.addMode(
'/',
'Mode used to position the text element',
function (elem) {}
);
var mode = hints.modes['/'];
var res = mode.matcher(doc);
for (let elem in res) {
//alert(elem.innerHTML);
if (isVisible(elem) && (!mode.filter || mode.filter(elem))) {
return elem;
} else {
}
}
/*
Array.forEach(win.frames, function (f) {
if (isVisible(f.frameElement)) {
let rect = f.frameElement.getBoundingClientRect();
generate(f, {
left: Math.max(offsets.left - rect.left, 0),
right: Math.max(rect.right - offsets.right, 0),
top: Math.max(offsets.top - rect.top, 0),
bottom: Math.max(rect.bottom - offsets.bottom, 0)
});
}
}, this);
*/
};
group.commands.add(
["findhere"],
"Find from the start of current screen",
function(args){
moveCaret(findFirstTarget());
if (args.bang)
rangefinder.openPrompt(modes.FIND_BACKWARD);
else
rangefinder.openPrompt(modes.FIND_FORWARD);
},
{
literal: 0,
bang: true
}, true);
dactyl.execute("se eht& | se eht+=[/]:*")
})();
@amzyang
Copy link
Copy Markdown
Author

amzyang commented Aug 3, 2011

I don't update and maintain this script for now.

see here:
https://g.mozest.com/thread-38443-3-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment