1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-15 23:53:33 +01:00

separate Ex command and search commandline history

This commit is contained in:
Doug Kearns
2007-09-23 14:14:36 +00:00
parent 17a37d5864
commit db4a3f3f7d
2 changed files with 64 additions and 37 deletions

4
NEWS
View File

@@ -1,6 +1,7 @@
<pre> <pre>
2007-XX-XX: 2007-XX-XX:
* version 0.5.2 * version 0.5.2
* separated search and Ex command history
* added 'visualbellstyle' for styling/hiding the visual bell * added 'visualbellstyle' for styling/hiding the visual bell
* merge the existing status bar with the standard FF status bar so that * merge the existing status bar with the standard FF status bar so that
security information and extension buttons are included security information and extension buttons are included
@@ -13,7 +14,8 @@
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
and \u can be used in the search pattern to override 'linksearch' and \u can be used in the search pattern to override 'linksearch'
* vimperator trys to stay in command mode after loading pages instead of having a text field focused * vimperator trys to stay in command mode after loading pages instead
of having a text field focused
* added a visual bell and replaced 'beep' with 'visualbell' * added a visual bell and replaced 'beep' with 'visualbell'
* added vimperator logo (can be seen in the addons manager) * added vimperator logo (can be seen in the addons manager)
* added 'hlsearch','incsearch', 'ignorecase' and 'smartcase' options * added 'hlsearch','incsearch', 'ignorecase' and 'smartcase' options

View File

@@ -39,12 +39,55 @@ function CommandLine() //{{{
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
const UNINITIALIZED = -2; // notifies us, if we need to start history/tab-completion from the beginning const UNINITIALIZED = -2; // notifies us, if we need to start history/tab-completion from the beginning
const HISTORY_SIZE = 500;
var completionlist = new InformationList("vimperator-completion", { min_items: 2, max_items: 10 }); var completionlist = new InformationList("vimperator-completion", { min_items: 2, max_items: 10 });
var completions = []; var completions = [];
var history = []; // TODO: clean this up when it's not 3am...
var history = {
SIZE: 500,
get _mode() { return (vimperator.hasMode(vimperator.modes.EX)) ? "cmd" : "search"; },
cmd: null, // ex command history
search: null, // text search history
get: function() { return this[this._mode]; },
set: function(lines) { this[this._mode] = lines; },
load: function()
{
this.cmd = Options.getPref("commandline_cmd_history", "").split("\n");
this.search = Options.getPref("commandline_search_history", "").split("\n");
},
save: function()
{
Options.setPref("commandline_cmd_history", this.cmd.join("\n"));
Options.setPref("commandline_search_history", this.search.join("\n"));
},
add: function(str)
{
if (!str)
return;
var lines = this.get();
// remove all old history lines which have this string
lines = lines.filter(function(line) {
return line != str;
});
// add string to the command line history
if (lines.push(str) > this.SIZE) // remove the first 10% of the history
lines = lines.slice(this.SIZE / 10);
this.set(lines);
}
};
history.load();
var history_index = UNINITIALIZED; var history_index = UNINITIALIZED;
var history_start = ""; var history_start = "";
@@ -88,9 +131,6 @@ function CommandLine() //{{{
var multiline_regexp = null; var multiline_regexp = null;
var multiline_callback = null; var multiline_callback = null;
// load the commandline history
history = Options.getPref("commandline_history", "").split("\n");
// TODO: these styles should be moved to the .css file // TODO: these styles should be moved to the .css file
function setNormalStyle() function setNormalStyle()
{ {
@@ -199,20 +239,6 @@ function CommandLine() //{{{
multiline_input_widget.setAttribute("rows", lines.toString()); multiline_input_widget.setAttribute("rows", lines.toString());
} }
function addToHistory(str)
{
if (str.length < 1)
return;
// first remove all old history elements which have this string
history = history.filter(function(elem) {
return elem != str;
});
// add string to the command line history
if (history.push(str) > HISTORY_SIZE) //remove the first 10% of the history
history = history.slice(HISTORY_SIZE / 10);
}
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
@@ -222,9 +248,6 @@ function CommandLine() //{{{
return command_widget.value; return command_widget.value;
}; };
/**
* All arguments can be ommited and will be defaulted to "" or null
*/
this.open = function(prompt, cmd, ext_mode) this.open = function(prompt, cmd, ext_mode)
{ {
// save the current prompts, we need it later if the command widget // save the current prompts, we need it later if the command widget
@@ -353,11 +376,11 @@ function CommandLine() //{{{
{ {
var key = vimperator.events.toString(event); var key = vimperator.events.toString(event);
/* user pressed ENTER to carry out a command */ // user pressed ENTER to carry out a command
if (vimperator.events.isAcceptKey(key)) if (vimperator.events.isAcceptKey(key))
{ {
var mode = cur_extended_mode; // save it here, as setMode() resets it var mode = cur_extended_mode; // save it here, as setMode() resets it
addToHistory(command); history.add(command);
vimperator.setMode(old_mode, old_extended_mode); vimperator.setMode(old_mode, old_extended_mode);
vimperator.focusContent(); vimperator.focusContent();
completionlist.hide(); completionlist.hide();
@@ -365,11 +388,11 @@ function CommandLine() //{{{
return vimperator.triggerCallback("submit", mode, command); return vimperator.triggerCallback("submit", mode, command);
} }
/* user pressed ESCAPE to cancel this prompt */ // user pressed ESCAPE to cancel this prompt
else if (vimperator.events.isCancelKey(key)) else if (vimperator.events.isCancelKey(key))
{ {
var res = vimperator.triggerCallback("cancel", cur_extended_mode); var res = vimperator.triggerCallback("cancel", cur_extended_mode);
addToHistory(command); history.add(command);
vimperator.setMode(old_mode, old_extended_mode); vimperator.setMode(old_mode, old_extended_mode);
vimperator.focusContent(); vimperator.focusContent();
completionlist.hide(); completionlist.hide();
@@ -378,9 +401,11 @@ function CommandLine() //{{{
return res; return res;
} }
/* user pressed UP or DOWN arrow to cycle history completion */ // user pressed UP or DOWN arrow to cycle history completion
else if (key == "<Up>" || key == "<Down>") else if (key == "<Up>" || key == "<Down>")
{ {
var lines = history.get();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@@ -390,18 +415,18 @@ function CommandLine() //{{{
// save 'start' position for iterating through the history // save 'start' position for iterating through the history
if (history_index == UNINITIALIZED) if (history_index == UNINITIALIZED)
{ {
history_index = history.length; history_index = lines.length;
history_start = command; history_start = command;
} }
// search the history for the first item matching the current // search the history for the first item matching the current
// commandline string // commandline string
while (history_index >= -1 && history_index <= history.length) while (history_index >= -1 && history_index <= lines.length)
{ {
key == "<Up>" ? history_index-- : history_index++; key == "<Up>" ? history_index-- : history_index++;
// user pressed DOWN when there is no newer history item // user pressed DOWN when there is no newer history item
if (history_index == history.length) if (history_index == lines.length)
{ {
setCommand(history_start); setCommand(history_start);
return; return;
@@ -414,22 +439,22 @@ function CommandLine() //{{{
vimperator.beep(); vimperator.beep();
break; break;
} }
if (history_index >= history.length + 1) if (history_index >= lines.length + 1)
{ {
history_index = history.length; history_index = lines.length;
vimperator.beep(); vimperator.beep();
break; break;
} }
if (history[history_index].indexOf(history_start) == 0) if (lines[history_index].indexOf(history_start) == 0)
{ {
setCommand(history[history_index]); setCommand(lines[history_index]);
return; return;
} }
} }
} }
/* user pressed TAB to get completions of a command */ // user pressed TAB to get completions of a command
else if (key == "<Tab>" || key == "<S-Tab>") else if (key == "<Tab>" || key == "<S-Tab>")
{ {
//always reset our completion history so up/down keys will start with new values //always reset our completion history so up/down keys will start with new values
@@ -784,7 +809,7 @@ function CommandLine() //{{{
// it would be better if we had a destructor in javascript ... // it would be better if we had a destructor in javascript ...
this.destroy = function() this.destroy = function()
{ {
Options.setPref("commandline_history", history.join("\n")); history.save();
} }
//}}} //}}}
} //}}} } //}}}