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

merge new 'incsearch', 'ignorecase', 'smartcase', 'hlsearch' options from MAIN

This commit is contained in:
Doug Kearns
2007-09-06 00:04:10 +00:00
parent fe87657307
commit 30d9b25d35
5 changed files with 123 additions and 33 deletions

1
NEWS
View File

@@ -1,6 +1,7 @@
<pre> <pre>
2007-XX-XX: 2007-XX-XX:
* version 0.5.2 * version 0.5.2
* added 'hlsearch','incsearch', 'ignorecase' and 'smartcase' options
2007-09-03: 2007-09-03:
* version 0.5.1 * version 0.5.1

View File

@@ -26,25 +26,64 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL. the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/ }}} ***** END LICENSE BLOCK *****/
// TODO: <ESC> should cancel search highlighting in 'incsearch' mode
// make sure you only create this object when the "vimperator" object is ready // make sure you only create this object when the "vimperator" object is ready
// vimperator.search = new function()
function Search() //{{{ function Search() //{{{
{ {
var self = this; // needed for callbacks since "this" is the "vimperator" object in a callback var self = this; // needed for callbacks since "this" is the "vimperator" object in a callback
var found = false; // true if the last search was successful var found = false; // true if the last search was successful
var backwards = false; var backwards = false; // currently searching backwards
var lastsearch = ""; // keep track of the last searched string var lastsearch = ""; // keep track of the last searched string
var lastsearch_backwards = false; // like "backwards", but for the last search, so if you cancel a search with <esc> this is not set var lastsearch_backwards = false; // like "backwards", but for the last search, so if you cancel a search with <esc> this is not set
var case_sensitive = true;
// Event handlers for search - closure is needed // Event handlers for search - closure is needed
vimperator.registerCallback("change", vimperator.modes.SEARCH_FORWARD, function(command){ self.searchKeyPressed(command); }); vimperator.registerCallback("change", vimperator.modes.SEARCH_FORWARD, function(command) { self.searchKeyPressed(command); });
vimperator.registerCallback("submit", vimperator.modes.SEARCH_FORWARD, function(command){ self.searchSubmitted(command); }); vimperator.registerCallback("submit", vimperator.modes.SEARCH_FORWARD, function(command) { self.searchSubmitted(command); });
vimperator.registerCallback("cancel", vimperator.modes.SEARCH_FORWARD, function(){ self.searchCanceled(); }); vimperator.registerCallback("cancel", vimperator.modes.SEARCH_FORWARD, function() { self.searchCanceled(); });
// TODO: allow advanced modes in register/triggerCallback // TODO: allow advanced modes in register/triggerCallback
vimperator.registerCallback("change", vimperator.modes.SEARCH_BACKWARD, function(command){ self.searchKeyPressed(command); }); vimperator.registerCallback("change", vimperator.modes.SEARCH_BACKWARD, function(command) { self.searchKeyPressed(command); });
vimperator.registerCallback("submit", vimperator.modes.SEARCH_BACKWARD, function(command){ self.searchSubmitted(command); }); vimperator.registerCallback("submit", vimperator.modes.SEARCH_BACKWARD, function(command) { self.searchSubmitted(command); });
vimperator.registerCallback("cancel", vimperator.modes.SEARCH_BACKWARD, function(){ self.searchCanceled(); }); vimperator.registerCallback("cancel", vimperator.modes.SEARCH_BACKWARD, function() { self.searchCanceled(); });
// clean the pattern search string of modifiers and set the
// case-sensitivity flag
function processPattern(pattern)
{
// strip off pattern terminator and trailing /junk
if (backwards)
pattern = pattern.replace(/\?.*/, "");
else
pattern = pattern.replace(/\/.*/, "");
if (!pattern)
pattern = lastsearch;
if (/\\C/.test(pattern))
{
case_sensitive = true;
pattern = pattern.replace(/\\C/, "");
}
else if (/\\c/.test(pattern))
{
case_sensitive = false;
pattern = pattern.replace(/\\c/, "");
}
else if (vimperator.options["ignorecase"] && vimperator.options["smartcase"] && /[A-Z]/.test(pattern))
{
case_sensitive = true;
}
else if (vimperator.options["ignorecase"])
{
case_sensitive = false;
}
else
{
case_sensitive = true;
}
return pattern;
}
// Called when the search dialog is asked for // Called when the search dialog is asked for
// If you omit "mode", it will default to forward searching // If you omit "mode", it will default to forward searching
@@ -52,12 +91,12 @@ function Search() //{{{
{ {
if (mode == vimperator.modes.SEARCH_BACKWARD) if (mode == vimperator.modes.SEARCH_BACKWARD)
{ {
vimperator.commandline.open('?', '', vimperator.modes.SEARCH_BACKWARD); vimperator.commandline.open("?", "", vimperator.modes.SEARCH_BACKWARD);
backwards = true; backwards = true;
} }
else else
{ {
vimperator.commandline.open('/', '', vimperator.modes.SEARCH_FORWARD); vimperator.commandline.open("/", "", vimperator.modes.SEARCH_FORWARD);
backwards = false; backwards = false;
} }
@@ -68,11 +107,10 @@ function Search() //{{{
// TODO: backwards seems impossible i fear :( // TODO: backwards seems impossible i fear :(
this.find = function(str, backwards) this.find = function(str, backwards)
{ {
const FIND_NORMAL = 0; var fastFind = getBrowser().fastFind;
const FIND_TYPEAHEAD = 1;
const FIND_LINKS = 2;
found = getBrowser().fastFind.find(str, false) != Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND; fastFind.caseSensitive = case_sensitive;
found = fastFind.find(str, false) != Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND;
return found; return found;
} }
@@ -82,11 +120,12 @@ function Search() //{{{
{ {
// this hack is needed to make n/N work with the correct string, if // this hack is needed to make n/N work with the correct string, if
// we typed /foo<esc> after the original search // we typed /foo<esc> after the original search
// TODO: this should also clear the current item highlighting
if (getBrowser().fastFind.searchString != lastsearch) if (getBrowser().fastFind.searchString != lastsearch)
{ {
this.clear(); this.clear();
this.find(lastsearch, false); this.find(lastsearch, false);
gFindBar.highlightDoc("yellow", "black", lastsearch); this.highlight(lastsearch);
} }
var up = reverse ? !lastsearch_backwards : lastsearch_backwards; var up = reverse ? !lastsearch_backwards : lastsearch_backwards;
@@ -98,12 +137,14 @@ function Search() //{{{
result = getBrowser().fastFind.findNext(); result = getBrowser().fastFind.findNext();
if (result == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND) if (result == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND)
{
vimperator.echoerr("E486: Pattern not found: " + lastsearch); vimperator.echoerr("E486: Pattern not found: " + lastsearch);
}
else if (result == Components.interfaces.nsITypeAheadFind.FIND_WRAPPED) else if (result == Components.interfaces.nsITypeAheadFind.FIND_WRAPPED)
{ {
// hack needed, because wrapping causes a "scroll" event which clears // hack needed, because wrapping causes a "scroll" event which clears
// our command line // our command line
setTimeout( function() { setTimeout(function() {
if (up) if (up)
vimperator.echoerr("search hit TOP, continuing at BOTTOM"); vimperator.echoerr("search hit TOP, continuing at BOTTOM");
else else
@@ -111,26 +152,32 @@ function Search() //{{{
}, 10); }, 10);
} }
else // just clear the command line if something has been found else // just clear the command line if something has been found
{
vimperator.echo(""); vimperator.echo("");
} }
}
// Called when the user types a key in the search dialog. Triggers a find attempt // Called when the user types a key in the search dialog. Triggers a find attempt
this.searchKeyPressed = function(command) this.searchKeyPressed = function(command)
{ {
// TODO: check for 'incsearch' if (!vimperator.options["incsearch"])
var backward = vimperator.hasMode(vimperator.modes.SEARCH_BACKWARD); return;
this.find(command, backward);
command = processPattern(command);
this.find(command, backwards);
} }
// Called when the enter key is pressed to trigger a search // Called when the enter key is pressed to trigger a search
this.searchSubmitted = function(command) this.searchSubmitted = function(command)
{ {
this.clear(); this.clear();
gFindBar.highlightDoc("yellow", "black", command); command = processPattern(command);
this.find(command, backwards);
this.highlight(command);
// need to find again to draw the highlight of the current search // need to find again to draw the highlight of the current search
// result over the "highlight all" search results // result over the "highlight all" search results
// very hacky, but seem to work // very hacky, but seems to work
setTimeout(function() { self.findAgain(false); }, 10); setTimeout(function() { self.findAgain(false); }, 10);
lastsearch_backwards = backwards; lastsearch_backwards = backwards;
@@ -150,6 +197,15 @@ function Search() //{{{
vimperator.focusContent(); vimperator.focusContent();
} }
this.highlight = function(word)
{
if (!word)
word = lastsearch;
gFindBar.setCaseSensitivity(case_sensitive)
gFindBar.highlightDoc("yellow", "black", word);
}
this.clear = function() this.clear = function()
{ {
gFindBar.highlightDoc(); gFindBar.highlightDoc();

View File

@@ -942,16 +942,21 @@ function Mappings() //{{{
function() { vimperator.search.openSearchDialog(vimperator.modes.SEARCH_FORWARD); }, function() { vimperator.search.openSearchDialog(vimperator.modes.SEARCH_FORWARD); },
{ {
short_help: "Search forward for a pattern", short_help: "Search forward for a pattern",
usage: ["/{pattern}<CR>"], usage: ["/{pattern}[/]<CR>"],
help: "Search forward for the first occurance of <code class=\"argument\">{pattern}</code>." help: "Search forward for the first occurance of <code class=\"argument\">{pattern}</code>.<br/>" +
"When \"\\c\" appears anywhere in the pattern the whole pattern is handled as though <code class=\"option\">'ignorecase'</code> is on. " +
"\"\\C\" forces case-sensitive matching for the whole pattern."
} }
)); ));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["?"], addDefaultMap(new Map(vimperator.modes.NORMAL, ["?"],
function() { vimperator.search.openSearchDialog(vimperator.modes.SEARCH_BACKWARD); }, function() { vimperator.search.openSearchDialog(vimperator.modes.SEARCH_BACKWARD); },
{ {
short_help: "Search backwards for a pattern", short_help: "Search backwards for a pattern",
usage: ["?{pattern}<CR>"], usage: ["?{pattern}[?]<CR>"],
help: "Search backward for the first occurance of <code class=\"argument\">{pattern}</code>." help: "Search backward for the first occurance of <code class=\"argument\">{pattern}</code>.<br/>" +
"When '\\c' appears anywhere in the pattern the whole pattern is handled as though <code class=\"option\">'ignorecase'</code> is on. " +
"'\\C' forces case-sensitive matching for the whole pattern.<br/>" +
"NOTE: incremental searching currenly only works in the forward direction."
} }
)); ));
addDefaultMap(new Map(vimperator.modes.NORMAL, ["n"], addDefaultMap(new Map(vimperator.modes.NORMAL, ["n"],

View File

@@ -425,6 +425,26 @@ function Options() //{{{
default_value: DEFAULT_HINTTAGS default_value: DEFAULT_HINTTAGS
} }
)); ));
addOption(new Option(["hlsearch", "hls"], "boolean",
{
short_help: "Highlight previous search pattern matches",
setter: function(value) { if (value) vimperator.search.highlight(); else vimperator.search.clear(); },
default_value: true
}
));
addOption(new Option(["ignorecase", "ic"], "boolean",
{
short_help: "Ignore case in search patterns",
default_value: true
}
));
addOption(new Option(["incsearch", "is"], "boolean",
{
short_help: "Show where the search pattern matches as it is typed",
help: "NOTE: Incremental searching currently only works in the forward direction.",
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",
@@ -492,6 +512,13 @@ function Options() //{{{
validator: function (value) { if (value >= 0 && value <= 2) return true; else return false; } validator: function (value) { if (value >= 0 && value <= 2) return true; else return false; }
} }
)); ));
addOption(new Option(["smartcase", "scs"], "boolean",
{
short_help: "Override the 'ignorecase' option if the pattern contains uppercase characters",
help: "This is only used if the <code class=\"option\">'ignorecase'</code> option is set.",
default_value: false
}
));
addOption(new Option(["titlestring"], "string", addOption(new Option(["titlestring"], "string",
{ {
short_help: "Change the title of the browser window", short_help: "Change the title of the browser window",

View File

@@ -29,10 +29,11 @@ syn keyword vimperatorCommand addo[ns] ba[ck] bd[elete] bw[ipeout] bun[load] tab
syn match vimperatorCommandWrapper "\<\h\w*\>" contains=vimperatorCommand syn match vimperatorCommandWrapper "\<\h\w*\>" contains=vimperatorCommand
syn region vimperatorSet matchgroup=vimperatorCommand start="\<set\=\>" end="$" keepend oneline contains=vimperatorOption syn region vimperatorSet matchgroup=vimperatorCommand start="\<set\=\>" end="$" keepend oneline contains=vimperatorOption
syn keyword vimperatorOption activate beep nobeep beep complete cpt defsearch ds extendedhinttags eht focusedhintstyle fhs syn keyword vimperatorOption activate act complete cpt defsearch ds extendedhinttags eht focusedhintstyle fhs fullscreen fs
\ fullscreen fs nofullscreen nofs guioptions go hintchars hc hintstyle hs hinttags maxhints mh preload nopreload \ nofullscreen nofs guioptions go hintchars hc hintstyle hs hinttags incsearch is noincsearch nois ignorecase ic
\ previewheight pvh showmode smd noshowmode nosmd showstatuslinks ssli showtabline stal titlestring usermode um nousermode \ noignorecase noic maxhints mh preload nopreload previewheight pvh showmode smd noshowmode nosmd showstatuslinks ssli
\ noum verbose vbs wildmode wim wildoptions wop \ showtabline stal smartcase scs nosmartcase noscs titlestring usermode um nousermode noum verbose vbs visualbell vb
\ wildmode wim wildoptions wop
\ contained \ contained
syn region vimperatorJavascript start="\%(^\s*\%(javascript\|js\)\s\+\)\@<=" end="$" contains=@javascriptTop keepend oneline syn region vimperatorJavascript start="\%(^\s*\%(javascript\|js\)\s\+\)\@<=" end="$" contains=@javascriptTop keepend oneline