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

add 'more' option and standard more-prompt key mappings

This commit is contained in:
Doug Kearns
2007-09-16 12:18:11 +00:00
parent 6735ac3ad1
commit 93acaadbd0
4 changed files with 177 additions and 66 deletions

2
NEWS
View File

@@ -2,6 +2,8 @@
2007-xx-xx: 2007-xx-xx:
* version 0.6 * version 0.6
* THIS VERSION ONLY WORKS WITH FIREFOX 3.0 * THIS VERSION ONLY WORKS WITH FIREFOX 3.0
* added 'more' and standard more-prompt key mappings to control
behaviour of the message list pager
* added 'hlsearchstyle' option to allow for user CSS styling of the * added 'hlsearchstyle' option to allow for user CSS styling of the
highlighted text strings when 'hlsearch' is set highlighted text strings when 'hlsearch' is set
* added 'linksearch' option to restrict page searches to link text - \U * added 'linksearch' option to restrict page searches to link text - \U

View File

@@ -473,6 +473,12 @@ function Options() //{{{
default_value: false default_value: false
} }
)); ));
addOption(new Option(["more"], "boolean",
{
short_help: "Pause the message list window when more than one screen of listings is displayed",
default_value: true
}
));
addOption(new Option(["maxhints", "mh"], "number", addOption(new Option(["maxhints", "mh"], "number",
{ {
short_help: "Maximum number of simultaneously shown hints", short_help: "Maximum number of simultaneously shown hints",

View File

@@ -133,7 +133,11 @@ function CommandLine() //{{{
command_widget.value = cmd; command_widget.value = cmd;
} }
function setMultiline(cmd) // TODO: the invoking command should be pasted at the top of the MOW and
// the MOW messages should actually be displayed in the commandline
// : extract CSS
// : resize upon a window resize
function setMultiline(str)
{ {
// TODO: we should retain any previous command output like Vim // TODO: we should retain any previous command output like Vim
if (!multiline_output_widget.collapsed) if (!multiline_output_widget.collapsed)
@@ -141,21 +145,37 @@ function CommandLine() //{{{
multiline_input_widget.collapsed = true; multiline_input_widget.collapsed = true;
// vimperator.log(content_height); var output = str.replace(/\n|\\n/g, "<br/>");
cmd = cmd.replace(/\n|\\n/g, "<br/>") + "<br/><span style=\"color: green;\">Press ENTER or type command to continue</span>"; //output = ":" + command_widget.value + "<br/>" + output;
multiline_output_widget.contentDocument.body.innerHTML = cmd; output += "<br/>"
output += '<span id="end-prompt" style="color: green; background-color: white;">Press ENTER or type command to continue</span>';
output += '<span id="more-prompt" style="display: none; position: fixed; top: auto; bottom: 0; left: 0; right: 0; color: green; background-color: white;">';
output += "-- More --";
output += '</span>';
output += '<span id="more-help-prompt" style="display: none; position: fixed; top: auto; bottom: 0; left: 0; right: 0; color: green; background-color: white;">';
output += "-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit";
output += '</span>';
multiline_output_widget.contentDocument.body.innerHTML = output;
// TODO: resize upon a window resize
var available_height = getBrowser().mPanelContainer.boxObject.height; var available_height = getBrowser().mPanelContainer.boxObject.height;
var content_height = multiline_output_widget.contentDocument.height; var content_height = multiline_output_widget.contentDocument.height;
// vimperator.log(content_height);
var height = content_height < available_height ? content_height : available_height; var height = content_height < available_height ? content_height : available_height;
//multiline_output_widget.style.height = height + "px"; //multiline_output_widget.style.height = height + "px";
multiline_output_widget.height = height + "px"; multiline_output_widget.height = height + "px";
multiline_output_widget.collapsed = false; multiline_output_widget.collapsed = false;
//multiline_output_widget.contentWindow.scrollTo(0, content_height); // scroll to the end when 'nomore' is set
multiline_output_widget.contentWindow.scrollTo(0, 0); // scroll to the end when 'nomore' is set if (vimperator.options["more"] && multiline_output_widget.contentWindow.scrollMaxY > 0)
{
multiline_output_widget.contentWindow.document.getElementById("more-prompt").style.display = "inline";
multiline_output_widget.contentWindow.scrollTo(0, 0);
}
else
{
multiline_output_widget.contentWindow.scrollTo(0, content_height);
}
multiline_output_widget.contentWindow.focus(); multiline_output_widget.contentWindow.focus();
vimperator.modes.set(vimperator.modes.COMMAND_LINE, vimperator.modes.OUTPUT_MULTILINE); vimperator.modes.set(vimperator.modes.COMMAND_LINE, vimperator.modes.OUTPUT_MULTILINE);
@@ -583,88 +603,171 @@ function CommandLine() //{{{
} }
} }
// TODO: differentiate between scrollable and not scrollable // FIXME: if 'more' is set and the MOW is not scrollable we should still
// allow a down motion after an up rather than closing
this.onMultilineOutputEvent = function(event) this.onMultilineOutputEvent = function(event)
{
// return 0 if window can never scroll
// 1 if window can scroll, but is at the end
// 2 if window can scroll
function canScroll()
{ {
var win = multiline_output_widget.contentWindow; var win = multiline_output_widget.contentWindow;
var percent = win.scrollMaxY == 0 ? -1 : win.scrollY / win.scrollMaxY;
if (percent < 0) var show_more_help_prompt = false;
return 0; var show_more_prompt = false;
else if (percent >= 1)
return 1; function isScrollable() { return !win.scrollMaxY == 0; }
else
return 2; function atEnd() { return win.scrollY / win.scrollMaxY >= 1; }
}
function pass(event) function pass(event)
{ {
multiline_output_widget.collapsed = true; multiline_output_widget.collapsed = true;
// FIXME: use mode stack // FIXME: use mode stack
vimperator.modes.reset(); vimperator.modes.reset();
vimperator.events.onKeyPress(event); vimperator.events.onKeyPress(event);
} }
var key = vimperator.events.toString(event); var key = vimperator.events.toString(event);
// TODO: move to events.toString()
if (event.type == "click" && event.button == 0)
key = "<LeftMouse>"
switch (key) switch (key)
{ {
case ":": case ":":
vimperator.commandline.open(":", "", vimperator.modes.EX); vimperator.commandline.open(":", "", vimperator.modes.EX);
break; break;
// down a line
case "j": case "j":
case "<Down>": case "<Down>":
case "<Return>": if (vimperator.options["more"] && isScrollable())
if (canScroll() == 2) win.scrollByLines(1);
multiline_output_widget.contentWindow.scrollByLines(1);
else
pass(event);
break;
case "k":
case "<Up>":
case "<BS>":
if (canScroll() >= 1)
multiline_output_widget.contentWindow.scrollByLines(-1);
else
pass(event);
break;
case "f":
if (canScroll() == 2)
multiline_output_widget.contentWindow.scrollByPages(1);
else
pass(event);
break;
case "b":
if (canScroll() >= 1)
multiline_output_widget.contentWindow.scrollByPages(-1);
else
pass(event);
break;
case "g":
if (canScroll() >= 1)
multiline_output_widget.contentWindow.scrollTo(0, 0);
else
pass(event);
break;
case "G":
if (canScroll() >= 1)
multiline_output_widget.contentWindow.scrollTo(0, multiline_output_widget.contentWindow.scrollMaxY);
else else
pass(event); pass(event);
break; break;
default: case "<Return>":
if (canScroll() == 0 || vimperator.events.isCancelKey(key)) if (vimperator.options["more"] && isScrollable() && !atEnd())
win.scrollByLines(1);
else
pass(event); pass(event);
else if (canScroll() == 1 && vimperator.events.isAcceptKey(key)) break;
// up a line
case "k":
case "<Up>":
case "<BS>":
if (vimperator.options["more"] && isScrollable())
win.scrollByLines(-1);
else if (vimperator.options["more"] && !isScrollable())
show_more_prompt = true;
else
pass(event);
break;
// half page down
case "d":
if (vimperator.options["more"] && isScrollable())
win.scrollBy(0, win.innerHeight / 2);
else
pass(event);
break;
case "<LeftMouse>":
if (!/^(end|more(-help)?)-prompt$/.test(event.target.id))
break;
else
; // fall through
// page down
case "<Space>":
case "<PageDown>":
if (vimperator.options["more"] && isScrollable() && !atEnd())
win.scrollByPages(1);
else
pass(event);
break;
// half page up
case "u":
// if (more and scrollable)
if (vimperator.options["more"] && isScrollable())
win.scrollBy(0, -(win.innerHeight / 2));
else
pass(event);
break;
// page up
case "b":
if (vimperator.options["more"] && isScrollable())
win.scrollByPages(-1);
else if (vimperator.options["more"] && !isScrollable())
show_more_prompt = true;
else
pass(event);
break;
case "<PageUp>":
if (vimperator.options["more"] && isScrollable())
win.scrollByPages(-1);
else
pass(event);
break;
// top of page
case "g":
if (vimperator.options["more"] && isScrollable())
win.scrollTo(0, 0);
else if (vimperator.options["more"] && !isScrollable())
show_more_prompt = true;
else
pass(event);
break;
// bottom of page
case "G":
if (vimperator.options["more"] && isScrollable() && !atEnd())
win.scrollTo(0, win.scrollMaxY);
else
pass(event);
break;
// copy text to clipboard
case "<C-y>":
vimperator.copyToClipboard(win.getSelection());
break;
// close the window
case "q":
this.clear();
break;
// invalid key
default:
if (!vimperator.options["more"] || !isScrollable() || atEnd() || vimperator.events.isCancelKey(key))
pass(event);
else if (atEnd() && vimperator.events.isAcceptKey(key))
pass(event); pass(event);
else else
; // show a more help inline like in vim show_more_help_prompt = true;
}
// set appropriate prompt string
var more_prompt = win.document.getElementById("more-prompt");
var more_help_prompt = win.document.getElementById("more-help-prompt");
if (show_more_help_prompt)
{
more_prompt.style.display = "none";
more_help_prompt.style.display = "inline";
}
else if (show_more_prompt || (vimperator.options["more"] && isScrollable() && !atEnd()))
{
more_help_prompt.style.display = "none";
more_prompt.style.display = "inline";
}
else
{
more_prompt.style.display = more_help_prompt.style.display = "none";
} }
} }

View File

@@ -94,6 +94,9 @@ the terms of any one of the MPL, the GPL or the LGPL.
</listcols> </listcols>
</listbox> </listbox>
<iframe id="vimperator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true" onclick="vimperator.commandline.onMultilineOutputEvent(event)"/>
<!--onkeypress="vimperator.commandline.onMultilineOutputEvent(event)"/-->
<hbox id="vimperator-commandline" flex="1" hidden="false"> <hbox id="vimperator-commandline" flex="1" hidden="false">
<label class="plain" id="vimperator-commandline-prompt" flex="0" crop="end" value="" collapsed="true"/> <label class="plain" id="vimperator-commandline-prompt" flex="0" crop="end" value="" collapsed="true"/>
<textbox class="plain" id="vimperator-commandline-command" flex="1" hidden="false" type="timed" timeout="100" <textbox class="plain" id="vimperator-commandline-command" flex="1" hidden="false" type="timed" timeout="100"
@@ -103,9 +106,6 @@ the terms of any one of the MPL, the GPL or the LGPL.
onblur="vimperator.commandline.onEvent(event);"/> onblur="vimperator.commandline.onEvent(event);"/>
</hbox> </hbox>
<iframe id="vimperator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true"/>
<!--onkeypress="vimperator.commandline.onMultilineOutputEvent(event)"/-->
<textbox id="vimperator-multiline-input" class="plain" flex="1" rows="10" hidden="false" collapsed="true" multiline="true" <textbox id="vimperator-multiline-input" class="plain" flex="1" rows="10" hidden="false" collapsed="true" multiline="true"
onkeypress="vimperator.commandline.onMultilineInputEvent(event);" onkeypress="vimperator.commandline.onMultilineInputEvent(event);"
oninput="vimperator.commandline.onMultilineInputEvent(event);" oninput="vimperator.commandline.onMultilineInputEvent(event);"