1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 11:48:00 +01:00

Fix ^L and liberator.editor

This commit is contained in:
Kris Maglione
2008-10-13 01:29:57 +00:00
parent cd0fb01dd4
commit 85dda8da9b
3 changed files with 29 additions and 27 deletions

View File

@@ -40,14 +40,14 @@ with (liberator) liberator.Editor = function () //{{{
var lastFindCharFunc = null; var lastFindCharFunc = null;
var abbrev = {}; // abbrev["lhr"][0]["{i,c,!}","rhs"] var abbrev = {}; // abbrev["lhr"][0]["{i,c,!}","rhs"]
function editor() function getEditor()
{ {
return window.document.commandDispatcher.focusedElement; return window.document.commandDispatcher.focusedElement;
} }
function getController() function getController()
{ {
var ed = editor(); var ed = getEditor();
if (!ed || !ed.controllers) if (!ed || !ed.controllers)
return null; return null;
@@ -474,7 +474,7 @@ with (liberator) liberator.Editor = function () //{{{
{ {
if (modes.main == modes.VISUAL) if (modes.main == modes.VISUAL)
{ {
count = editor().selectionEnd - editor().selectionStart; count = getEditor().selectionEnd - getEditor().selectionStart;
} }
if (typeof count != "number" || count < 1) if (typeof count != "number" || count < 1)
{ {
@@ -483,15 +483,15 @@ with (liberator) liberator.Editor = function () //{{{
while (count-- > 0) while (count-- > 0)
{ {
var text = editor().value; var text = getEditor().value;
var pos = editor().selectionStart; var pos = getEditor().selectionStart;
if (pos >= text.length) if (pos >= text.length)
{ {
beep(); beep();
return; return;
} }
var chr = text[pos]; var chr = text[pos];
editor().value = text.substring(0, pos) + getEditor().value = text.substring(0, pos) +
(chr == chr.toLocaleLowerCase() ? chr.toLocaleUpperCase() : chr.toLocaleLowerCase()) + (chr == chr.toLocaleLowerCase() ? chr.toLocaleUpperCase() : chr.toLocaleLowerCase()) +
text.substring(pos + 1); text.substring(pos + 1);
editor.moveToPosition(pos + 1, true, false); editor.moveToPosition(pos + 1, true, false);
@@ -517,8 +517,8 @@ with (liberator) liberator.Editor = function () //{{{
line: function () line: function ()
{ {
var line = 1; var line = 1;
var text = editor().value; var text = getEditor().value;
for (let i = 0; i < editor().selectionStart; i++) for (let i = 0; i < getEditor().selectionStart; i++)
if (text[i] == "\n") if (text[i] == "\n")
line++; line++;
return line; return line;
@@ -527,8 +527,8 @@ with (liberator) liberator.Editor = function () //{{{
col: function () col: function ()
{ {
var col = 1; var col = 1;
var text = editor().value; var text = getEditor().value;
for (let i = 0; i < editor().selectionStart; i++) for (let i = 0; i < getEditor().selectionStart; i++)
{ {
col++; col++;
if (text[i] == "\n") if (text[i] == "\n")
@@ -546,8 +546,8 @@ with (liberator) liberator.Editor = function () //{{{
selectedText: function () selectedText: function ()
{ {
var text = editor().value; var text = getEditor().value;
return text.substring(editor().selectionStart, editor().selectionEnd); return text.substring(getEditor().selectionStart, getEditor().selectionEnd);
}, },
pasteClipboard: function () pasteClipboard: function ()
@@ -697,48 +697,48 @@ with (liberator) liberator.Editor = function () //{{{
{ {
if (!select) if (!select)
{ {
editor().setSelectionRange(pos, pos); getEditor().setSelectionRange(pos, pos);
return; return;
} }
if (forward) if (forward)
{ {
if (pos <= editor().selectionEnd || pos > editor().value.length) if (pos <= getEditor().selectionEnd || pos > getEditor().value.length)
return false; return false;
do // TODO: test code for endless loops do // TODO: test code for endless loops
{ {
this.executeCommand("cmd_selectCharNext", 1); this.executeCommand("cmd_selectCharNext", 1);
} }
while (editor().selectionEnd != pos); while (getEditor().selectionEnd != pos);
} }
else else
{ {
if (pos >= editor().selectionStart || pos < 0) if (pos >= getEditor().selectionStart || pos < 0)
return false; return false;
do // TODO: test code for endless loops do // TODO: test code for endless loops
{ {
this.executeCommand("cmd_selectCharPrevious", 1); this.executeCommand("cmd_selectCharPrevious", 1);
} }
while (editor().selectionStart != pos); while (getEditor().selectionStart != pos);
} }
}, },
// returns the position of char // returns the position of char
findCharForward: function (ch, count) findCharForward: function (ch, count)
{ {
if (!editor()) if (!getEditor())
return -1; return -1;
lastFindChar = ch; lastFindChar = ch;
lastFindCharFunc = this.findCharForward; lastFindCharFunc = this.findCharForward;
var text = editor().value; var text = getEditor().value;
if (!typeof count == "number" || count < 1) if (!typeof count == "number" || count < 1)
count = 1; count = 1;
for (let i = editor().selectionEnd + 1; i < text.length; i++) for (let i = getEditor().selectionEnd + 1; i < text.length; i++)
{ {
if (text[i] == "\n") if (text[i] == "\n")
break; break;
@@ -755,17 +755,17 @@ with (liberator) liberator.Editor = function () //{{{
// returns the position of char // returns the position of char
findCharBackward: function (ch, count) findCharBackward: function (ch, count)
{ {
if (!editor()) if (!getEditor())
return -1; return -1;
lastFindChar = ch; lastFindChar = ch;
lastFindCharFunc = this.findCharBackward; lastFindCharFunc = this.findCharBackward;
var text = editor().value; var text = getEditor().value;
if (!typeof count == "number" || count < 1) if (!typeof count == "number" || count < 1)
count = 1; count = 1;
for (let i = editor().selectionStart - 1; i >= 0; i--) for (let i = getEditor().selectionStart - 1; i >= 0; i--)
{ {
if (text[i] == "\n") if (text[i] == "\n")
break; break;
@@ -1096,7 +1096,7 @@ with (liberator) liberator.Editor = function () //{{{
expandAbbreviation: function (filter) // try to find an candidate and replace accordingly expandAbbreviation: function (filter) // try to find an candidate and replace accordingly
{ {
var textbox = editor(); var textbox = getEditor();
var text = textbox.value; var text = textbox.value;
var currStart = textbox.selectionStart; var currStart = textbox.selectionStart;
var currEnd = textbox.selectionEnd; var currEnd = textbox.selectionEnd;

View File

@@ -546,6 +546,7 @@ with (liberator) liberator.Events = function () //{{{
echoerr("Processing " + event.type + " event: " + (e.echoerr || e)); echoerr("Processing " + event.type + " event: " + (e.echoerr || e));
if (Components.utils.reportError) if (Components.utils.reportError)
Components.utils.reportError(e); Components.utils.reportError(e);
liberator.dump(e);
} }
} }
} }

View File

@@ -250,7 +250,7 @@ with (liberator) liberator.config = { //{{{
mappings.add([modes.NORMAL], ["<C-l>"], mappings.add([modes.NORMAL], ["<C-l>"],
"Redraw the screen", "Redraw the screen",
function () { commands.get("redraw").execute(); }); function () { commands.get("redraw").execute("", false); });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// COMMANDS //////////////////////////////////////////////// ////////////////////// COMMANDS ////////////////////////////////////////////////
@@ -291,9 +291,10 @@ with (liberator) liberator.config = { //{{{
"Redraw the screen", "Redraw the screen",
function () function ()
{ {
var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor). var wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
getInterface(Components.interfaces.nsIDOMWindowUtils); .getInterface(Components.interfaces.nsIDOMWindowUtils);
wu.redraw(); wu.redraw();
modes.show(); // Clears the shadow of the last command, as in vim.
}, },
{ argCount: "0" }); { argCount: "0" });