mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 17:57:58 +01:00
use the 'singleton' construction idiom rather than classical constructors for
creating the bookmarks, history, commandline, search, previewwindow, bufferwindow, statusline, buffer, editor, marks and quickmarks objects
This commit is contained in:
1000
content/bookmarks.js
1000
content/bookmarks.js
File diff suppressed because it is too large
Load Diff
1150
content/buffers.js
1150
content/buffers.js
File diff suppressed because it is too large
Load Diff
@@ -610,7 +610,7 @@ vimperator.Completion = function () // {{{
|
||||
return [start, completions];
|
||||
} //}}}
|
||||
|
||||
}
|
||||
};
|
||||
} // }}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
1062
content/editor.js
1062
content/editor.js
File diff suppressed because it is too large
Load Diff
284
content/find.js
284
content/find.js
@@ -39,7 +39,8 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||
// make sure you only create this object when the "vimperator" object is ready
|
||||
vimperator.Search = function () //{{{
|
||||
{
|
||||
var self = this; // needed for callbacks since "this" is the "vimperator" object in a callback
|
||||
// FIXME:
|
||||
//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 backwards = false; // currently searching backwards
|
||||
var search_string = ""; // current search string (without modifiers)
|
||||
@@ -51,13 +52,13 @@ vimperator.Search = function () //{{{
|
||||
var links_only = false; // search is limited to link text only
|
||||
|
||||
// Event handlers for search - closure is needed
|
||||
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("cancel", vimperator.modes.SEARCH_FORWARD, function () { self.searchCanceled(); });
|
||||
vimperator.registerCallback("change", vimperator.modes.SEARCH_FORWARD, function (command) { vimperator.search.searchKeyPressed(command); });
|
||||
vimperator.registerCallback("submit", vimperator.modes.SEARCH_FORWARD, function (command) { vimperator.search.searchSubmitted(command); });
|
||||
vimperator.registerCallback("cancel", vimperator.modes.SEARCH_FORWARD, function () { vimperator.search.searchCanceled(); });
|
||||
// TODO: allow advanced modes in register/triggerCallback
|
||||
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("cancel", vimperator.modes.SEARCH_BACKWARD, function () { self.searchCanceled(); });
|
||||
vimperator.registerCallback("change", vimperator.modes.SEARCH_BACKWARD, function (command) { vimperator.search.searchKeyPressed(command); });
|
||||
vimperator.registerCallback("submit", vimperator.modes.SEARCH_BACKWARD, function (command) { vimperator.search.searchSubmitted(command); });
|
||||
vimperator.registerCallback("cancel", vimperator.modes.SEARCH_BACKWARD, function () { vimperator.search.searchCanceled(); });
|
||||
|
||||
// set search_string, search_pattern, case_sensitive, links_only
|
||||
function processUserPattern(pattern)
|
||||
@@ -104,158 +105,161 @@ vimperator.Search = function () //{{{
|
||||
search_string = pattern;
|
||||
}
|
||||
|
||||
// Called when the search dialog is asked for
|
||||
// If you omit "mode", it will default to forward searching
|
||||
this.openSearchDialog = function (mode)
|
||||
{
|
||||
if (mode == vimperator.modes.SEARCH_BACKWARD)
|
||||
return {
|
||||
|
||||
// Called when the search dialog is asked for
|
||||
// If you omit "mode", it will default to forward searching
|
||||
openSearchDialog: function (mode)
|
||||
{
|
||||
vimperator.commandline.open("?", "", vimperator.modes.SEARCH_BACKWARD);
|
||||
backwards = true;
|
||||
}
|
||||
else
|
||||
if (mode == vimperator.modes.SEARCH_BACKWARD)
|
||||
{
|
||||
vimperator.commandline.open("?", "", vimperator.modes.SEARCH_BACKWARD);
|
||||
backwards = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
vimperator.commandline.open("/", "", vimperator.modes.SEARCH_FORWARD);
|
||||
backwards = false;
|
||||
}
|
||||
|
||||
// TODO: focus the top of the currently visible screen
|
||||
},
|
||||
|
||||
// Finds text in a page
|
||||
// TODO: backwards seems impossible i fear :(
|
||||
find: function (str, backwards)
|
||||
{
|
||||
vimperator.commandline.open("/", "", vimperator.modes.SEARCH_FORWARD);
|
||||
backwards = false;
|
||||
}
|
||||
var fastFind = getBrowser().fastFind;
|
||||
|
||||
// TODO: focus the top of the currently visible screen
|
||||
}
|
||||
processUserPattern(str);
|
||||
|
||||
// Finds text in a page
|
||||
// TODO: backwards seems impossible i fear :(
|
||||
this.find = function (str, backwards)
|
||||
{
|
||||
var fastFind = getBrowser().fastFind;
|
||||
fastFind.caseSensitive = case_sensitive;
|
||||
found = fastFind.find(search_string, links_only) != Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND;
|
||||
|
||||
processUserPattern(str);
|
||||
if (!found)
|
||||
vimperator.echoerr("E486: Pattern not found: " + search_pattern);
|
||||
|
||||
fastFind.caseSensitive = case_sensitive;
|
||||
found = fastFind.find(search_string, links_only) != Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND;
|
||||
return found;
|
||||
},
|
||||
|
||||
if (!found)
|
||||
vimperator.echoerr("E486: Pattern not found: " + search_pattern);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
// Called when the current search needs to be repeated
|
||||
this.findAgain = function (reverse)
|
||||
{
|
||||
// this hack is needed to make n/N work with the correct string, if
|
||||
// we typed /foo<esc> after the original search. Since searchString is
|
||||
// readonly we have to call find() again to update it.
|
||||
if (getBrowser().fastFind.searchString != last_search_string)
|
||||
this.find(last_search_string, false);
|
||||
|
||||
var up = reverse ? !last_search_backwards : last_search_backwards;
|
||||
var result = getBrowser().fastFind.findAgain(up, links_only);
|
||||
|
||||
if (result == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND)
|
||||
// Called when the current search needs to be repeated
|
||||
findAgain: function (reverse)
|
||||
{
|
||||
vimperator.echoerr("E486: Pattern not found: " + last_search_pattern);
|
||||
}
|
||||
else if (result == Components.interfaces.nsITypeAheadFind.FIND_WRAPPED)
|
||||
// this hack is needed to make n/N work with the correct string, if
|
||||
// we typed /foo<esc> after the original search. Since searchString is
|
||||
// readonly we have to call find() again to update it.
|
||||
if (getBrowser().fastFind.searchString != last_search_string)
|
||||
this.find(last_search_string, false);
|
||||
|
||||
var up = reverse ? !last_search_backwards : last_search_backwards;
|
||||
var result = getBrowser().fastFind.findAgain(up, links_only);
|
||||
|
||||
if (result == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND)
|
||||
{
|
||||
vimperator.echoerr("E486: Pattern not found: " + last_search_pattern);
|
||||
}
|
||||
else if (result == Components.interfaces.nsITypeAheadFind.FIND_WRAPPED)
|
||||
{
|
||||
// hack needed, because wrapping causes a "scroll" event which clears
|
||||
// our command line
|
||||
setTimeout(function () {
|
||||
if (up)
|
||||
vimperator.commandline.echo("search hit TOP, continuing at BOTTOM", vimperator.commandline.HL_WARNING);
|
||||
else
|
||||
vimperator.commandline.echo("search hit BOTTOM, continuing at TOP", vimperator.commandline.HL_WARNING);
|
||||
}, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
vimperator.echo((up ? "?" : "/") + last_search_pattern, null, vimperator.commandline.FORCE_SINGLELINE);
|
||||
|
||||
if (vimperator.options["hlsearch"])
|
||||
this.highlight(last_search_string);
|
||||
}
|
||||
},
|
||||
|
||||
// Called when the user types a key in the search dialog. Triggers a find attempt if 'incsearch' is set
|
||||
searchKeyPressed: function (command)
|
||||
{
|
||||
// hack needed, because wrapping causes a "scroll" event which clears
|
||||
// our command line
|
||||
setTimeout(function () {
|
||||
if (up)
|
||||
vimperator.commandline.echo("search hit TOP, continuing at BOTTOM", vimperator.commandline.HL_WARNING);
|
||||
else
|
||||
vimperator.commandline.echo("search hit BOTTOM, continuing at TOP", vimperator.commandline.HL_WARNING);
|
||||
}, 0);
|
||||
}
|
||||
else
|
||||
if (vimperator.options["incsearch"])
|
||||
this.find(command, backwards);
|
||||
},
|
||||
|
||||
// Called when the enter key is pressed to trigger a search
|
||||
// use forced_direction if you call this function directly
|
||||
searchSubmitted: function (command, forced_backward)
|
||||
{
|
||||
vimperator.echo((up ? "?" : "/") + last_search_pattern, null, vimperator.commandline.FORCE_SINGLELINE);
|
||||
if (typeof forced_backward === "boolean")
|
||||
backwards = forced_backward;
|
||||
|
||||
// use the last pattern if none specified
|
||||
if (!command)
|
||||
command = last_search_pattern;
|
||||
|
||||
this.clear();
|
||||
this.find(command, backwards);
|
||||
|
||||
last_search_backwards = backwards;
|
||||
last_search_pattern = command.replace(backwards ? /\?.*/ : /\/.*/, ""); // XXX
|
||||
last_search_string = search_string;
|
||||
|
||||
// TODO: move to find() when reverse incremental searching is kludged in
|
||||
// need to find again for reverse searching
|
||||
if (backwards)
|
||||
setTimeout(function () { self.findAgain(false); }, 0);
|
||||
|
||||
if (vimperator.options["hlsearch"])
|
||||
this.highlight(last_search_string);
|
||||
}
|
||||
}
|
||||
this.highlight(search_string);
|
||||
|
||||
// Called when the user types a key in the search dialog. Triggers a find attempt if 'incsearch' is set
|
||||
this.searchKeyPressed = function (command)
|
||||
{
|
||||
if (vimperator.options["incsearch"])
|
||||
this.find(command, backwards);
|
||||
}
|
||||
vimperator.modes.reset();
|
||||
},
|
||||
|
||||
// Called when the enter key is pressed to trigger a search
|
||||
// use forced_direction if you call this function directly
|
||||
this.searchSubmitted = function (command, forced_backward)
|
||||
{
|
||||
if (typeof forced_backward === "boolean")
|
||||
backwards = forced_backward;
|
||||
|
||||
// use the last pattern if none specified
|
||||
if (!command)
|
||||
command = last_search_pattern;
|
||||
|
||||
this.clear();
|
||||
this.find(command, backwards);
|
||||
|
||||
last_search_backwards = backwards;
|
||||
last_search_pattern = command.replace(backwards ? /\?.*/ : /\/.*/, ""); // XXX
|
||||
last_search_string = search_string;
|
||||
|
||||
// TODO: move to find() when reverse incremental searching is kludged in
|
||||
// need to find again for reverse searching
|
||||
if (backwards)
|
||||
setTimeout(function () { self.findAgain(false); }, 0);
|
||||
|
||||
if (vimperator.options["hlsearch"])
|
||||
this.highlight(search_string);
|
||||
|
||||
vimperator.modes.reset();
|
||||
}
|
||||
|
||||
// Called when the search is canceled - for example if someone presses
|
||||
// escape while typing a search
|
||||
this.searchCanceled = function ()
|
||||
{
|
||||
this.clear();
|
||||
// TODO: code to reposition the document to the place before search started
|
||||
}
|
||||
|
||||
// this is not dependent on the value of 'hlsearch'
|
||||
this.highlight = function (text)
|
||||
{
|
||||
// already highlighted?
|
||||
if (window.content.document.getElementsByClassName("__mozilla-findbar-search").length > 0)
|
||||
return;
|
||||
|
||||
if (!text)
|
||||
text = last_search_string;
|
||||
|
||||
gFindBar._setCaseSensitivity(case_sensitive);
|
||||
gFindBar._highlightDoc("white", "black", text);
|
||||
|
||||
// TODO: seems fast enough for now...just
|
||||
(function (win)
|
||||
// Called when the search is canceled - for example if someone presses
|
||||
// escape while typing a search
|
||||
searchCanceled: function ()
|
||||
{
|
||||
for (var i = 0; i < win.frames.length; i++)
|
||||
arguments.callee(win.frames[i]);
|
||||
var spans = window.content.document.getElementsByClassName("__mozilla-findbar-search");
|
||||
for (var i = 0; i < spans.length; i++)
|
||||
spans[i].setAttribute("style", vimperator.options["hlsearchstyle"]);
|
||||
})(window.content);
|
||||
this.clear();
|
||||
// TODO: code to reposition the document to the place before search started
|
||||
},
|
||||
|
||||
// recreate selection since _highlightDoc collapses the selection backwards
|
||||
getBrowser().fastFind.findAgain(false, links_only);
|
||||
// this is not dependent on the value of 'hlsearch'
|
||||
highlight: function (text)
|
||||
{
|
||||
// already highlighted?
|
||||
if (window.content.document.getElementsByClassName("__mozilla-findbar-search").length > 0)
|
||||
return;
|
||||
|
||||
// TODO: remove highlighting from non-link matches (HTML - A/AREA with href attribute; XML - Xlink [type="simple"])
|
||||
}
|
||||
if (!text)
|
||||
text = last_search_string;
|
||||
|
||||
this.clear = function ()
|
||||
{
|
||||
gFindBar._highlightDoc();
|
||||
// need to manually collapse the selection if the document is not
|
||||
// highlighted
|
||||
getBrowser().fastFind.collapseSelection();
|
||||
}
|
||||
gFindBar._setCaseSensitivity(case_sensitive);
|
||||
gFindBar._highlightDoc("white", "black", text);
|
||||
|
||||
// TODO: seems fast enough for now...just
|
||||
(function (win)
|
||||
{
|
||||
for (var i = 0; i < win.frames.length; i++)
|
||||
arguments.callee(win.frames[i]);
|
||||
var spans = window.content.document.getElementsByClassName("__mozilla-findbar-search");
|
||||
for (var i = 0; i < spans.length; i++)
|
||||
spans[i].setAttribute("style", vimperator.options["hlsearchstyle"]);
|
||||
})(window.content);
|
||||
|
||||
// recreate selection since _highlightDoc collapses the selection backwards
|
||||
getBrowser().fastFind.findAgain(false, links_only);
|
||||
|
||||
// TODO: remove highlighting from non-link matches (HTML - A/AREA with href attribute; XML - Xlink [type="simple"])
|
||||
},
|
||||
|
||||
clear: function ()
|
||||
{
|
||||
gFindBar._highlightDoc();
|
||||
// need to manually collapse the selection if the document is not
|
||||
// highlighted
|
||||
getBrowser().fastFind.collapseSelection();
|
||||
}
|
||||
|
||||
};
|
||||
} //}}}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -234,7 +234,7 @@ vimperator.IO = function ()
|
||||
ocstream.close();
|
||||
ofstream.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -92,9 +92,11 @@ vimperator.modes = (function ()
|
||||
{
|
||||
// clear any selection made
|
||||
var selection = window.content.getSelection();
|
||||
try { // a simple if (selection) does not work
|
||||
try
|
||||
{ // a simple if (selection) does not work
|
||||
selection.collapseToStart();
|
||||
} catch (e) { }
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
else
|
||||
vimperator.editor.unselectText();
|
||||
@@ -122,6 +124,7 @@ vimperator.modes = (function ()
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
// main modes, only one should ever be active
|
||||
NONE: 0,
|
||||
NORMAL: 1 << 0,
|
||||
@@ -219,7 +222,8 @@ vimperator.modes = (function ()
|
||||
set extended(value) {
|
||||
extended = value; this.show();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
})();
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
1494
content/ui.js
1494
content/ui.js
File diff suppressed because it is too large
Load Diff
@@ -584,37 +584,37 @@ const vimperator = (function () //{{{
|
||||
vimperator.log("Loading module commands...", 3);
|
||||
vimperator.commands = new vimperator.Commands();
|
||||
vimperator.log("Loading module bookmarks...", 3);
|
||||
vimperator.bookmarks = new vimperator.Bookmarks();
|
||||
vimperator.bookmarks = vimperator.Bookmarks();
|
||||
vimperator.log("Loading module history...", 3);
|
||||
vimperator.history = new vimperator.History();
|
||||
vimperator.history = vimperator.History();
|
||||
vimperator.log("Loading module commandline...", 3);
|
||||
vimperator.commandline = new vimperator.CommandLine();
|
||||
vimperator.commandline = vimperator.CommandLine();
|
||||
vimperator.log("Loading module search...", 3);
|
||||
vimperator.search = new vimperator.Search();
|
||||
vimperator.search = vimperator.Search();
|
||||
vimperator.log("Loading module preview window...", 3);
|
||||
vimperator.previewwindow = new vimperator.InformationList("vimperator-previewwindow", { incremental_fill: false, max_items: 10 });
|
||||
vimperator.previewwindow = vimperator.InformationList("vimperator-previewwindow", { incremental_fill: false, max_items: 10 });
|
||||
vimperator.log("Loading module buffer window...", 3);
|
||||
vimperator.bufferwindow = new vimperator.InformationList("vimperator-bufferwindow", { incremental_fill: false, max_items: 10 });
|
||||
vimperator.bufferwindow = vimperator.InformationList("vimperator-bufferwindow", { incremental_fill: false, max_items: 10 });
|
||||
vimperator.log("Loading module mappings...", 3);
|
||||
vimperator.mappings = new vimperator.Mappings();
|
||||
vimperator.log("Loading module statusline...", 3);
|
||||
vimperator.statusline = new vimperator.StatusLine();
|
||||
vimperator.statusline = vimperator.StatusLine();
|
||||
vimperator.log("Loading module buffer...", 3);
|
||||
vimperator.buffer = new vimperator.Buffer();
|
||||
vimperator.buffer = vimperator.Buffer();
|
||||
vimperator.log("Loading module editor...", 3);
|
||||
vimperator.editor = new vimperator.Editor();
|
||||
vimperator.editor = vimperator.Editor();
|
||||
vimperator.log("Loading module tabs...", 3);
|
||||
vimperator.tabs = new vimperator.Tabs();
|
||||
vimperator.log("Loading module marks...", 3);
|
||||
vimperator.marks = new vimperator.Marks();
|
||||
vimperator.marks = vimperator.Marks();
|
||||
vimperator.log("Loading module quickmarks...", 3);
|
||||
vimperator.quickmarks = new vimperator.QuickMarks();
|
||||
vimperator.quickmarks = vimperator.QuickMarks();
|
||||
vimperator.log("Loading module hints...", 3);
|
||||
vimperator.hints = new vimperator.Hints();
|
||||
vimperator.log("Loading module io...", 3);
|
||||
vimperator.io = new vimperator.IO();
|
||||
vimperator.io = vimperator.IO();
|
||||
vimperator.log("Loading module completion...", 3);
|
||||
vimperator.completion = new vimperator.Completion();
|
||||
vimperator.completion = vimperator.Completion();
|
||||
vimperator.log("All modules loaded", 3);
|
||||
|
||||
vimperator.echo = function (str, flags) { vimperator.commandline.echo(str, vimperator.commandline.HL_NORMAL, flags); };
|
||||
|
||||
Reference in New Issue
Block a user