mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 20:07:59 +01:00
inputMultiline method finished (some display bug may remain)
:js <<EOF support is back, better than ever (TM)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<pre>
|
||||
2007-07-02:
|
||||
* version 0.5
|
||||
* :javascript <<EOF uses a better multiline input widget now
|
||||
* new :map, :noremap, :mapclear and :unmap commands
|
||||
* :saveas finally works (by calmar)
|
||||
* Shift-insert pastes the selection content in text fields now
|
||||
|
||||
4
TODO
4
TODO
@@ -23,8 +23,6 @@ FEATURES:
|
||||
8 Use our own find-as-you-type mechanism (like conkeror does)
|
||||
8 make hints smarter, not only with characters from from hintchars, but use "NE" or "NP" for 'new posts' e.g. (might be too slow)
|
||||
7 [ctrl-o/i] to Go back to a Previous Position (done partly, however currenty does not use a per tab jumplist)
|
||||
7 provide a buffer on the bottom where more than 1 line messages can be shown, preferrable
|
||||
with color support (for things like :echo line1\nline2)
|
||||
7 whereever possible: get rid of dialogs and ask console-like dialog questions or write error prompts directly on the webpage or with :echo()
|
||||
7 3d should delete 3 tabs
|
||||
6 downloading of links to filesystem (:save <filename>)
|
||||
@@ -36,7 +34,6 @@ FEATURES:
|
||||
6 macros (qq)
|
||||
6 gf = view source?
|
||||
6 make a real one-tab-mode, divert _all_ other targets, possible by setting a firefox option (set popup=0-3)
|
||||
6 Shift-Insert in textboxes pastes selection contents
|
||||
6 page info support (ctrl-g, g<C-g>)
|
||||
5 Use arrow keys in preview window, and ctrl-w+j/k to switch to from preview window
|
||||
5 Sort :open completion by date? (use 'wildsort')
|
||||
@@ -46,6 +43,7 @@ FEATURES:
|
||||
3 Splitting Windows with [:sp :vsp ctrl-w,s ctrl-w,v] and closing with [ctrl-w,q], moving with [ctrl-w,w or tab]
|
||||
have a look into the split browser extension
|
||||
3 :set should also set about:config options (with autocomplete)
|
||||
- many other ideas are listed in the wiki
|
||||
|
||||
RANDOM IDEAS:
|
||||
* numbered tabs
|
||||
|
||||
@@ -488,14 +488,29 @@ function Commands() //{{{
|
||||
if (special) // open javascript console
|
||||
vimperator.open("chrome://global/content/console.xul", vimperator.NEW_TAB);
|
||||
else
|
||||
try
|
||||
{
|
||||
// check for a heredoc
|
||||
var matches = args.match(/(.*)<<\s*([^\s]+)$/);
|
||||
if (matches && matches[2])
|
||||
{
|
||||
eval(args);
|
||||
vimperator.commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"),
|
||||
function(code) {
|
||||
try { eval(matches[1] + "\n" + code); }
|
||||
catch (e) { vimperator.echoerr(e.name + ": " + e.message); }
|
||||
});
|
||||
}
|
||||
catch (e)
|
||||
else // single line javascript code
|
||||
{
|
||||
vimperator.echoerr(e.name + ": " + e.message);
|
||||
try
|
||||
{
|
||||
eval(args);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
vimperator.echoerr(e.name + ": " + e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
usage: ["javas[cript] {cmd}", "javascript <<{endpattern}\\n{script}\\n{endpattern}", "javascript[!]"], // \\n is changed to <br/> in the help.js code
|
||||
|
||||
@@ -102,9 +102,11 @@ function CommandLine() //{{{
|
||||
var prompt_widget = document.getElementById('vimperator-commandline-prompt');
|
||||
// The command bar which contains the current command
|
||||
var command_widget = document.getElementById('vimperator-commandline-command');
|
||||
// The widget used for multiline in-/output
|
||||
var multiline_widget = document.getElementById("vimperator-multiline");
|
||||
multiline_widget.contentDocument.body.setAttribute("style", "margin: 0px; font-family: -moz-fixed;"); // get rid of the default border
|
||||
// The widget used for multiline output
|
||||
var multiline_output_widget = document.getElementById("vimperator-multiline-output");
|
||||
multiline_output_widget.contentDocument.body.setAttribute("style", "margin: 0px; font-family: -moz-fixed;"); // get rid of the default border
|
||||
// The widget used for multiline output
|
||||
var multiline_input_widget = document.getElementById("vimperator-multiline-input");
|
||||
|
||||
// we need to save the mode which were in before opening the command line
|
||||
// this is then used if we focus the command line again without the "official"
|
||||
@@ -119,6 +121,10 @@ function CommandLine() //{{{
|
||||
// and before the blur() event gets fired
|
||||
var echo_allowed = false;
|
||||
|
||||
// save the arguments for the inputMultiline method which are needed in the event handler
|
||||
var multiline_regexp = null;
|
||||
var multiline_callback = null;
|
||||
|
||||
// load the commandline history
|
||||
var hist = Options.getPref("commandline_history", "");
|
||||
history = hist.split("\n");
|
||||
@@ -167,20 +173,22 @@ function CommandLine() //{{{
|
||||
function setMultiline(cmd)
|
||||
{
|
||||
// TODO: we should retain any previous command output like Vim
|
||||
if (!multiline_widget.collapsed)
|
||||
multiline_widget.collapsed = true;
|
||||
if (!multiline_output_widget.collapsed)
|
||||
multiline_output_widget.collapsed = true;
|
||||
|
||||
multiline_input_widget.collapsed = true;
|
||||
|
||||
cmd = cmd.replace(/\n|\\n/g, "<br/>") + "<br/><span style=\"color: green;\">Press ENTER or type command to continue</span>";
|
||||
multiline_widget.contentDocument.body.innerHTML = cmd;
|
||||
multiline_output_widget.contentDocument.body.innerHTML = cmd;
|
||||
|
||||
// TODO: resize upon a window resize
|
||||
var available_height = getBrowser().mPanelContainer.boxObject.height;
|
||||
var content_height = multiline_widget.contentDocument.height;
|
||||
var content_height = multiline_output_widget.contentDocument.height;
|
||||
var height = content_height < available_height ? content_height : available_height;
|
||||
|
||||
multiline_widget.style.height = height + "px";
|
||||
multiline_widget.collapsed = false;
|
||||
multiline_widget.contentWindow.scrollTo(0, content_height); // scroll to the end when 'nomore' is set
|
||||
multiline_output_widget.style.height = height + "px";
|
||||
multiline_output_widget.collapsed = false;
|
||||
multiline_output_widget.contentWindow.scrollTo(0, content_height); // scroll to the end when 'nomore' is set
|
||||
}
|
||||
|
||||
function addToHistory(str)
|
||||
@@ -234,6 +242,9 @@ function CommandLine() //{{{
|
||||
if (!echo_allowed && focused && focused == command_widget.inputField)
|
||||
return false;
|
||||
|
||||
if (typeof str != "string")
|
||||
str = "";
|
||||
|
||||
setNormalStyle();
|
||||
if (flags || str.indexOf("\n") > -1 || str.indexOf("\\n") > -1 || str.indexOf("<br>") > -1 || str.indexOf("<br/>") > -1)
|
||||
{
|
||||
@@ -241,7 +252,8 @@ function CommandLine() //{{{
|
||||
}
|
||||
else
|
||||
{
|
||||
multiline_widget.collapsed = true;
|
||||
multiline_output_widget.collapsed = true;
|
||||
multiline_input_widget.collapsed = true;
|
||||
setPrompt("");
|
||||
setCommand(str);
|
||||
}
|
||||
@@ -275,17 +287,23 @@ function CommandLine() //{{{
|
||||
};
|
||||
|
||||
// reads a multi line input and returns the string once the last line matches
|
||||
// param until_regex
|
||||
this.readMultiline = function(until_regex, callback_func)
|
||||
// @param until_regexp
|
||||
this.inputMultiline = function(until_regexp, callback_func)
|
||||
{
|
||||
// save the mode, because we need to restore it on blur()
|
||||
// [old_mode, old_extended_mode] = vimperator.getMode();
|
||||
// vimperator.setMode(vimperator.modes.COMMAND_LINE, vimperator.modes.READ_MULTLINE, true);
|
||||
|
||||
multiline_widget.collapsed = false;
|
||||
multiline_widget.contentDocument.body.innerHTML = "";
|
||||
multiline_widget.contentDocument.designMode = "on";
|
||||
multiline_widget.contentWindow.focus(); // FIXME: does not work
|
||||
// save the arguments, they are needed in the event handler onEvent
|
||||
multiline_regexp = until_regexp;
|
||||
multiline_callback = callback_func;
|
||||
|
||||
multiline_input_widget.collapsed = false;
|
||||
multiline_input_widget.value = "";
|
||||
setTimeout(function() {
|
||||
multiline_input_widget.focus();
|
||||
}, 10);
|
||||
|
||||
};
|
||||
|
||||
this.clear = function()
|
||||
@@ -355,20 +373,6 @@ function CommandLine() //{{{
|
||||
/* user pressed ENTER to carry out a command */
|
||||
if (key == "<Return>" || key == "<C-j>" || key == "<C-m>")
|
||||
{
|
||||
// FIXME: move to execute() in commands.js
|
||||
// var end = false;
|
||||
// try {
|
||||
// [prev_match, heredoc, end] = multiliner(command, prev_match, heredoc);
|
||||
// } catch(e) {
|
||||
// logObject(e);
|
||||
// echoerr(e.name + ": " + e.message);
|
||||
// prev_match = new Array(5);
|
||||
// heredoc = '';
|
||||
// return;
|
||||
// }
|
||||
// if (!end)
|
||||
// command_line.value = "";
|
||||
|
||||
echo_allowed = true;
|
||||
addToHistory(command);
|
||||
var res = vimperator.triggerCallback("submit", command);
|
||||
@@ -376,6 +380,7 @@ function CommandLine() //{{{
|
||||
echo_allowed = false;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* user pressed ESCAPE to cancel this prompt */
|
||||
else if (key == "<Esc>" || key == "<C-[>" || key == "<C-c>")
|
||||
{
|
||||
@@ -567,6 +572,24 @@ function CommandLine() //{{{
|
||||
}
|
||||
}
|
||||
|
||||
this.onMultilineEvent = function(event)
|
||||
{
|
||||
// for now we just receive keypress events
|
||||
|
||||
var key = event.toString();
|
||||
if (key == "<Return>" || key == "<C-j>" || key == "<C-m>")
|
||||
{
|
||||
//var lines = multiline_input_widget.value.substr(0, multiline_input_widget.selectionStart).split(/\n/);
|
||||
var text = multiline_input_widget.value.substr(0, multiline_input_widget.selectionStart);
|
||||
if (text.match(multiline_regexp))
|
||||
{
|
||||
text = text.replace(multiline_regexp, "");
|
||||
multiline_callback.call(this, text);
|
||||
multiline_input_widget.collapsed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// it would be better if we had a destructor in javascript ...
|
||||
this.destroy = function()
|
||||
{
|
||||
|
||||
@@ -126,7 +126,7 @@ const vimperator = (function() //{{{
|
||||
count: -1 // parsed count from the input buffer
|
||||
},
|
||||
|
||||
/**
|
||||
/** TODO: for now, these callbacks are mostly for the command line, move there?
|
||||
* @param type Can be:
|
||||
* "submit": when the user pressed enter in the command line
|
||||
* "change"
|
||||
@@ -215,7 +215,7 @@ const vimperator = (function() //{{{
|
||||
if (window == ww.activeWindow && document.commandDispatcher.focusedElement)
|
||||
document.commandDispatcher.focusedElement.blur();
|
||||
|
||||
content.focus();
|
||||
content.focus(); // FIXME: shouldn't be window.document.content?
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -253,7 +253,7 @@ const vimperator = (function() //{{{
|
||||
//
|
||||
// @param urls: either a string or an array of urls
|
||||
// @param where: if ommited, CURRENT_TAB is assumed
|
||||
// @param callback: not implmented, will be allowed to specifiy a callback function
|
||||
// @param callback: not implemented, will be allowed to specify a callback function
|
||||
// which is called, when the page finished loading
|
||||
// @returns true when load was initiated, or false on error
|
||||
open: function(urls, where, callback)
|
||||
@@ -309,7 +309,6 @@ const vimperator = (function() //{{{
|
||||
|
||||
restart: function()
|
||||
{
|
||||
// if (!arguments[1]) return;
|
||||
const nsIAppStartup = Components.interfaces.nsIAppStartup;
|
||||
|
||||
// Notify all windows that an application quit has been requested.
|
||||
@@ -466,6 +465,7 @@ const vimperator = (function() //{{{
|
||||
var s = fd.read();
|
||||
fd.close();
|
||||
|
||||
// TODO: simplify and get rid of multiliner (look at "javascript" in commands.js)
|
||||
var prev_match = new Array(5);
|
||||
var heredoc = '';
|
||||
var end = false;
|
||||
@@ -521,10 +521,12 @@ const vimperator = (function() //{{{
|
||||
vimperator.echo = vimperator.commandline.echo;
|
||||
vimperator.echoerr = vimperator.commandline.echoErr;
|
||||
|
||||
// XXX: move elsewhere
|
||||
// TODO: move elsewhere
|
||||
vimperator.registerCallback("submit", vimperator.modes.EX, function(command) { /*vimperator.*/execute(command); } );
|
||||
vimperator.registerCallback("complete", vimperator.modes.EX, function(str) { return exTabCompletion(str); } );
|
||||
|
||||
//TODO: move most of the following code to Options constructor
|
||||
|
||||
// work around firefox popup blocker
|
||||
popup_allowed_events = Options.getFirefoxPref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit');
|
||||
if (!popup_allowed_events.match("keypress"))
|
||||
|
||||
@@ -99,7 +99,11 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||
onfocus="vimperator.commandline.onEvent(event);"
|
||||
onblur="vimperator.commandline.onEvent(event);"/>
|
||||
</hbox>
|
||||
<iframe id="vimperator-multiline" src="about:blank" flex="1" hidden="false" collapsed="true"/>
|
||||
|
||||
<iframe id="vimperator-multiline-output" src="about:blank" flex="1" hidden="false" collapsed="true"/>
|
||||
|
||||
<textbox id="vimperator-multiline-input" class="plain" flex="1" rows="10" hidden="false" collapsed="true" multiline="true"
|
||||
onkeypress="vimperator.commandline.onMultilineEvent(event);"/>
|
||||
</vbox>
|
||||
</toolbar>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user