diff --git a/NEWS b/NEWS index de394988..4e5b0f59 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@
2007-XX-XX:
* version 0.5.2
+ * separated search and Ex command history
* added 'visualbellstyle' for styling/hiding the visual bell
* merge the existing status bar with the standard FF status bar so that
security information and extension buttons are included
@@ -13,7 +14,8 @@
highlighted text strings when 'hlsearch' is set
* added 'linksearch' option to restrict page searches to link text - \U
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 vimperator logo (can be seen in the addons manager)
* added 'hlsearch','incsearch', 'ignorecase' and 'smartcase' options
diff --git a/chrome/content/vimperator/ui.js b/chrome/content/vimperator/ui.js
index 56c87195..94cd34d2 100644
--- a/chrome/content/vimperator/ui.js
+++ b/chrome/content/vimperator/ui.js
@@ -39,12 +39,55 @@ function CommandLine() //{{{
/////////////////////////////////////////////////////////////////////////////{{{
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 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_start = "";
@@ -88,9 +131,6 @@ function CommandLine() //{{{
var multiline_regexp = 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
function setNormalStyle()
{
@@ -199,20 +239,6 @@ function CommandLine() //{{{
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 //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
@@ -222,9 +248,6 @@ function CommandLine() //{{{
return command_widget.value;
};
- /**
- * All arguments can be ommited and will be defaulted to "" or null
- */
this.open = function(prompt, cmd, ext_mode)
{
// save the current prompts, we need it later if the command widget
@@ -353,11 +376,11 @@ function CommandLine() //{{{
{
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))
{
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.focusContent();
completionlist.hide();
@@ -365,11 +388,11 @@ function CommandLine() //{{{
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))
{
var res = vimperator.triggerCallback("cancel", cur_extended_mode);
- addToHistory(command);
+ history.add(command);
vimperator.setMode(old_mode, old_extended_mode);
vimperator.focusContent();
completionlist.hide();
@@ -378,9 +401,11 @@ function CommandLine() //{{{
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 == "" || key == "")
{
+ var lines = history.get();
+
event.preventDefault();
event.stopPropagation();
@@ -390,18 +415,18 @@ function CommandLine() //{{{
// save 'start' position for iterating through the history
if (history_index == UNINITIALIZED)
{
- history_index = history.length;
+ history_index = lines.length;
history_start = command;
}
// search the history for the first item matching the current
// commandline string
- while (history_index >= -1 && history_index <= history.length)
+ while (history_index >= -1 && history_index <= lines.length)
{
key == "" ? history_index-- : history_index++;
// user pressed DOWN when there is no newer history item
- if (history_index == history.length)
+ if (history_index == lines.length)
{
setCommand(history_start);
return;
@@ -414,22 +439,22 @@ function CommandLine() //{{{
vimperator.beep();
break;
}
- if (history_index >= history.length + 1)
+ if (history_index >= lines.length + 1)
{
- history_index = history.length;
+ history_index = lines.length;
vimperator.beep();
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;
}
}
}
- /* user pressed TAB to get completions of a command */
+ // user pressed TAB to get completions of a command
else if (key == "" || key == "")
{
//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 ...
this.destroy = function()
{
- Options.setPref("commandline_history", history.join("\n"));
+ history.save();
}
//}}}
} //}}}