mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-08 11:25:51 +01:00
advanced scrolling when focus is at a wrong element/frame
This commit is contained in:
@@ -179,10 +179,28 @@ vimperator.Buffer = function () //{{{
|
|||||||
vimperator.beep();
|
vimperator.beep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findScrollableWindow()
|
||||||
|
{
|
||||||
|
var win = window.document.commandDispatcher.focusedWindow;
|
||||||
|
if (win.scrollMaxX > 0 || win.scrollMaxY > 0)
|
||||||
|
return win;
|
||||||
|
|
||||||
|
win = window.content;
|
||||||
|
if (win.scrollMaxX > 0 || win.scrollMaxY > 0)
|
||||||
|
return win;
|
||||||
|
|
||||||
|
for (var i = 0; i < win.frames.length; i++)
|
||||||
|
if (win.frames[i].scrollMaxX > 0 || win.frames[i].scrollMaxY > 0)
|
||||||
|
return win.frames[i];
|
||||||
|
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// both values are given in percent, -1 means no change
|
// both values are given in percent, -1 means no change
|
||||||
function scrollToPercentiles(horizontal, vertical)
|
function scrollToPercentiles(horizontal, vertical)
|
||||||
{
|
{
|
||||||
var win = document.commandDispatcher.focusedWindow;
|
var win = findScrollableWindow();
|
||||||
var h, v;
|
var h, v;
|
||||||
|
|
||||||
if (horizontal < 0)
|
if (horizontal < 0)
|
||||||
@@ -376,7 +394,7 @@ vimperator.Buffer = function () //{{{
|
|||||||
|
|
||||||
scrollColumns: function (cols)
|
scrollColumns: function (cols)
|
||||||
{
|
{
|
||||||
var win = window.document.commandDispatcher.focusedWindow;
|
var win = findScrollableWindow();
|
||||||
const COL_WIDTH = 20;
|
const COL_WIDTH = 20;
|
||||||
|
|
||||||
if (cols > 0 && win.scrollX >= win.scrollMaxX || cols < 0 && win.scrollX == 0)
|
if (cols > 0 && win.scrollX >= win.scrollMaxX || cols < 0 && win.scrollX == 0)
|
||||||
@@ -392,18 +410,32 @@ vimperator.Buffer = function () //{{{
|
|||||||
|
|
||||||
scrollLines: function (lines)
|
scrollLines: function (lines)
|
||||||
{
|
{
|
||||||
var win = window.document.commandDispatcher.focusedWindow;
|
var win = findScrollableWindow();
|
||||||
checkScrollYBounds(win, lines);
|
checkScrollYBounds(win, lines);
|
||||||
win.scrollByLines(lines);
|
win.scrollByLines(lines);
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollPages: function (pages)
|
scrollPages: function (pages)
|
||||||
{
|
{
|
||||||
var win = window.document.commandDispatcher.focusedWindow;
|
var win = findScrollableWindow();
|
||||||
checkScrollYBounds(win, pages);
|
checkScrollYBounds(win, pages);
|
||||||
win.scrollByPages(pages);
|
win.scrollByPages(pages);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
scrollByScrollSize: function (count, direction)
|
||||||
|
{
|
||||||
|
if (count > 0)
|
||||||
|
vimperator.options["scroll"] = count;
|
||||||
|
|
||||||
|
var win = findScrollableWindow();
|
||||||
|
checkScrollYBounds(win, direction);
|
||||||
|
|
||||||
|
if (vimperator.options["scroll"] > 0)
|
||||||
|
this.scrollLines(vimperator.options["scroll"] * direction);
|
||||||
|
else // scroll half a page down in pixels
|
||||||
|
win.scrollBy(0, win.innerHeight / 2 * direction);
|
||||||
|
},
|
||||||
|
|
||||||
scrollToPercentile: function (percentage)
|
scrollToPercentile: function (percentage)
|
||||||
{
|
{
|
||||||
scrollToPercentiles(-1, percentage);
|
scrollToPercentiles(-1, percentage);
|
||||||
|
|||||||
@@ -1018,24 +1018,8 @@ vimperator.Mappings = function () //{{{
|
|||||||
flags: vimperator.Mappings.flags.COUNT
|
flags: vimperator.Mappings.flags.COUNT
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
function scrollByScrollSize(count, direction)
|
|
||||||
{
|
|
||||||
if (count > 0)
|
|
||||||
vimperator.options["scroll"] = count;
|
|
||||||
|
|
||||||
if (vimperator.options["scroll"] > 0)
|
|
||||||
{
|
|
||||||
vimperator.buffer.scrollLines(vimperator.options["scroll"] * direction);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// scroll half a page down in pixels
|
|
||||||
var win = document.commandDispatcher.focusedWindow;
|
|
||||||
win.scrollBy(0, vimperator.buffer.pageHeight / 2 * direction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["<C-d>"],
|
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["<C-d>"],
|
||||||
function (count) { scrollByScrollSize(count, 1); },
|
function (count) { vimperator.buffer.scrollByScrollSize(count, 1); },
|
||||||
{
|
{
|
||||||
shortHelp: "Scroll window downwards in the buffer",
|
shortHelp: "Scroll window downwards in the buffer",
|
||||||
help: "The number of lines is set by the <code class=\"option\">'scroll'</code> option which defaults to half a page. " +
|
help: "The number of lines is set by the <code class=\"option\">'scroll'</code> option which defaults to half a page. " +
|
||||||
@@ -1044,7 +1028,7 @@ vimperator.Mappings = function () //{{{
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["<C-u>"],
|
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["<C-u>"],
|
||||||
function (count) { scrollByScrollSize(count, -1); },
|
function (count) { vimperator.buffer.scrollByScrollSize(count, -1); },
|
||||||
{
|
{
|
||||||
shortHelp: "Scroll window upwards in the buffer",
|
shortHelp: "Scroll window upwards in the buffer",
|
||||||
help: "The number of lines is set by the <code class=\"option\">'scroll'</code> option which defaults to half a page. " +
|
help: "The number of lines is set by the <code class=\"option\">'scroll'</code> option which defaults to half a page. " +
|
||||||
|
|||||||
Reference in New Issue
Block a user