1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 22:07:59 +01:00

improve the frame motion command - add [f to the existing ]f and support

{count} for both
This commit is contained in:
Doug Kearns
2007-06-21 11:45:45 +00:00
parent 3d08bb8dc3
commit 8680e36d8c
2 changed files with 78 additions and 24 deletions

View File

@@ -1031,34 +1031,78 @@ function isDirectory(url)
// frame related functions //////////////////////////////////////// {{{1 // frame related functions //////////////////////////////////////// {{{1
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
function focusNextFrame(count) // TODO: allow callback for filtering out unwanted frames? User defined?
function focusNextFrame(count, forward)
{ {
try try
{ {
var frames = window.content.frames; var frames = [];
if (frames.length == 0)
{ // find all frames - depth-first search
vimperator.echo("No frames found"); (function(frame)
beep(); {
if (frame.document.body.localName.toLowerCase() == "body")
frames.push(frame);
for (var i = 0; i < frame.frames.length; i++)
arguments.callee(frame.frames[i])
})(window.content);
if (frames.length == 0) // currently top is always included
return; return;
}
var w = document.commandDispatcher.focusedWindow; // remove all unfocusable frames
var next = 0; var start = document.commandDispatcher.focusedWindow;
frames = frames.filter(function(frame) {
frame.focus();
if (document.commandDispatcher.focusedWindow == frame)
return frame;
});
start.focus();
// Find the next frame to focus // find the currently focused frame index
for (var i=0; i<frames.length; i++) { // TODO: If the window is a frameset then the first _frame_ should be
if (w == frames[i]) { // focused. Since this is not the current FF behaviour,
next = i+1; // we initalise current to -1 so the first call takes us to the
// first frame.
var current = -1;
for (var i = 0; i < frames.length; i++)
{
if (frames[i] == document.commandDispatcher.focusedWindow)
{
var current = i;
break; break;
} }
} }
// Focus the next one, 0 if we're at the last one
if (next >= frames.length)
next = 0;
// calculate the next frame to focus
var next = current;
if (forward)
{
if (count > 1)
next = current + count;
else
next++;
if (next > frames.length - 1)
next = frames.length - 1;
}
else
{
if (count > 1)
next = current - count;
else
next--;
if (next < 0)
next = 0;
}
// focus next frame and scroll into view
frames[next].focus(); frames[next].focus();
if (frames[next] != window.content)
frames[next].frameElement.scrollIntoView(false);
// add the frame indicator
var doc = frames[next].document; var doc = frames[next].document;
var indicator = doc.createElement("div"); var indicator = doc.createElement("div");
indicator.id = "vimperator-frame-indicator"; indicator.id = "vimperator-frame-indicator";
@@ -1068,12 +1112,16 @@ function focusNextFrame(count)
indicator.setAttribute("style", style); indicator.setAttribute("style", style);
doc.body.appendChild(indicator); doc.body.appendChild(indicator);
setTimeout(function() { doc.body.removeChild(indicator); }, 300); // remove the frame indicator
} catch(e) { alert(e); } setTimeout(function() { doc.body.removeChild(indicator); }, 500);
}
catch (e)
{
//vimperator.echoerr(e);
// FIXME: fail silently here for now
}
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// location handling ////////////////////////////////////////////// {{{1 // location handling ////////////////////////////////////////////// {{{1
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View File

@@ -191,12 +191,18 @@ function Mappings()//{{{
flags: Mappings.flags.ARGUMENT flags: Mappings.flags.ARGUMENT
} }
)); ));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["]f"], addDefaultMap(new Map(vimperator.modes.NORMAL, ["]f"], function(count) { focusNextFrame(count > 1 ? count : 1, true); },
focusNextFrame,
{ {
short_help: "Focus next frame", short_help: "Focus next frame",
help: "Flashes the next frame in order with a red color, to quickly show where keyboard focus is.<br/>" + help: "Transfers keyboard focus to the [count]th next frame in order. The newly focused frame is briefly colored red.",
"This may not work correctly for frames with lots of CSS code." flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["[f"], function(count) { focusNextFrame(count > 1 ? count : 1, false); },
{
short_help: "Focus previous frame",
help: "Transfers keyboard focus to the [count]th previous frame in order. The newly focused frame is briefly colored red.",
flags: Mappings.flags.COUNT
} }
)); ));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["b"], addDefaultMap(new Map(vimperator.modes.NORMAL, ["b"],