mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 18:17:58 +01:00
extract better text for input or select fields
This commit is contained in:
@@ -49,7 +49,6 @@ vimperator.Hints = function() //{{{
|
||||
var elem = valid_hints[0];
|
||||
var elemTagName = elem.tagName;
|
||||
elem.focus();
|
||||
|
||||
if (elemTagName == 'FRAME' || elemTagName == 'IFRAME')
|
||||
return 0;
|
||||
|
||||
@@ -74,6 +73,38 @@ vimperator.Hints = function() //{{{
|
||||
return true;
|
||||
};
|
||||
|
||||
function focusHint()
|
||||
{
|
||||
if (valid_hints.length < 1)
|
||||
return false;
|
||||
|
||||
var elem = valid_hints[0];
|
||||
var doc = window.content.document;
|
||||
if (elem.tagName == 'FRAME' || elem.tagName == 'IFRAME')
|
||||
{
|
||||
elem.contentWindow.focus();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
elem.focus();
|
||||
}
|
||||
|
||||
var evt = doc.createEvent('MouseEvents');
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
// for imagemap
|
||||
if (elem.tagName == 'AREA')
|
||||
{
|
||||
var coords = elem.getAttribute("coords").split(",");
|
||||
x = Number(coords[0]);
|
||||
y = Number(coords[1]);
|
||||
}
|
||||
|
||||
evt.initMouseEvent('mouseover', true, true, doc.defaultView, 1, x, y, 0, 0, 0, 0, 0, 0, 0, null);
|
||||
elem.dispatchEvent(evt);
|
||||
};
|
||||
|
||||
function yankHint(text)
|
||||
{
|
||||
if (valid_hints.length < 1)
|
||||
@@ -138,8 +169,6 @@ vimperator.Hints = function() //{{{
|
||||
for (var i = 0; i < res.snapshotLength; i++)
|
||||
{
|
||||
elem = res.snapshotItem(i);
|
||||
tagname = elem.tagName.toLowerCase();
|
||||
text = elem.textContent.toLowerCase();
|
||||
rect = elem.getBoundingClientRect();
|
||||
if (!rect || rect.bottom < 0 || rect.top > height || rect.right < 0 || rect.left > width)
|
||||
continue;
|
||||
@@ -148,6 +177,19 @@ vimperator.Hints = function() //{{{
|
||||
if (!rect)
|
||||
continue;
|
||||
|
||||
tagname = elem.tagName.toLowerCase();
|
||||
if (tagname == "input" || tagname == "textarea")
|
||||
text = elem.value.toLowerCase();
|
||||
else if (tagname == "select")
|
||||
{
|
||||
if (elem.selectedIndex >= 0)
|
||||
text = elem.item(elem.selectedIndex).text.toLowerCase();
|
||||
else
|
||||
text = "";
|
||||
}
|
||||
else
|
||||
text = elem.textContent.toLowerCase();
|
||||
|
||||
span = baseNodeAbsolute.cloneNode(true);
|
||||
span.innerHTML = "";
|
||||
span.style.display = "none";
|
||||
@@ -257,7 +299,7 @@ outer:
|
||||
// TODO: implement framesets
|
||||
this.show = function(mode, minor)
|
||||
{
|
||||
if (mode == vimperator.modes.EXTENDED_HINT && !/^[aoOstTwWyY]$/.test(minor))
|
||||
if (mode == vimperator.modes.EXTENDED_HINT && !/^[afoOstTwWyY]$/.test(minor))
|
||||
{
|
||||
vimperator.beep();
|
||||
return;
|
||||
@@ -304,8 +346,13 @@ outer:
|
||||
vimperator.beep();
|
||||
else if (valid_hints.length >= 1)
|
||||
{
|
||||
var first_href = valid_hints[0].getAttribute("href");
|
||||
if (!first_href || valid_hints.some( function(e) { return e.getAttribute("href") != first_href; } ))
|
||||
var first_href = valid_hints[0].getAttribute("href") || null;
|
||||
if (first_href)
|
||||
{
|
||||
if (valid_hints.some( function(e) { return e.getAttribute("href") != first_href; } ))
|
||||
return;
|
||||
}
|
||||
else if (valid_hints.length > 1)
|
||||
return;
|
||||
|
||||
vimperator.echo(" ");
|
||||
@@ -318,6 +365,7 @@ outer:
|
||||
var loc = valid_hints.length > 0 ? valid_hints[0].href : "";
|
||||
switch (submode)
|
||||
{
|
||||
case "f": focusHint(); break;
|
||||
case "o": openHint(false, false); break;
|
||||
case "O": vimperator.commandline.open(":", "open " + loc, vimperator.modes.EX); break;
|
||||
case "t": openHint(true, false); break;
|
||||
@@ -336,7 +384,11 @@ outer:
|
||||
|
||||
this.hide();
|
||||
// only close this mode half a second later, so we don't trigger accidental actions so easily
|
||||
setTimeout( function() { if (vimperator.mode == vimperator.modes.HINTS) vimperator.modes.reset(true); }, 500);
|
||||
// XXX: currently closes SELECT fields, need have an own mode for that
|
||||
setTimeout( function() {
|
||||
if (vimperator.mode == vimperator.modes.HINTS)
|
||||
vimperator.modes.reset(true);
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,34 +415,6 @@ outer:
|
||||
// };
|
||||
//
|
||||
//
|
||||
// function setMouseOverElement(elem)
|
||||
// {
|
||||
// var doc = window.document;
|
||||
//
|
||||
// if (elem.tagName == 'FRAME' || elem.tagName == 'IFRAME')
|
||||
// {
|
||||
// elem.contentWindow.focus();
|
||||
// return;
|
||||
// }
|
||||
// //else
|
||||
// //{
|
||||
// // elem.focus();
|
||||
// //}
|
||||
//
|
||||
// var evt = doc.createEvent('MouseEvents');
|
||||
// var x = 0;
|
||||
// var y = 0;
|
||||
// // for imagemap
|
||||
// if (elem.tagName == 'AREA')
|
||||
// {
|
||||
// var coords = elem.getAttribute("coords").split(",");
|
||||
// x = Number(coords[0]);
|
||||
// y = Number(coords[1]);
|
||||
// }
|
||||
//
|
||||
// evt.initMouseEvent('mouseover', true, true, doc.defaultView, 1, x, y, 0, 0, 0, 0, 0, 0, 0, null);
|
||||
// elem.dispatchEvent(evt);
|
||||
// }
|
||||
|
||||
} //}}}
|
||||
|
||||
|
||||
@@ -1053,6 +1053,7 @@ vimperator.Mappings = function() //{{{
|
||||
"<ul>" +
|
||||
"<li><code class=\"mapping\">a</code> to save its destination (prompting for save location)</li>" +
|
||||
"<li><code class=\"mapping\">s</code> to save its destination</li>" +
|
||||
"<li><code class=\"mapping\">f</code> to focus a link and hover it with the mouse</li>" +
|
||||
"<li><code class=\"mapping\">o</code> to open its location in the current tab</li>" +
|
||||
"<li><code class=\"mapping\">t</code> to open its location in a new tab</li>" +
|
||||
"<li><code class=\"mapping\">O</code> to open its location in an <code class=\"command\">:open</code> query</li>" +
|
||||
|
||||
@@ -112,7 +112,8 @@ vimperator.modes = (function()
|
||||
vimperator.options.setFirefoxPref("accessibility.browsewithcaret", false);
|
||||
|
||||
vimperator.statusline.updateUrl();
|
||||
vimperator.focusContent();
|
||||
// XXX: auto-focusing of content disabled, as it breaks hints partly
|
||||
//vimperator.focusContent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user