1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-27 06:45:47 +01:00

prefer let over var in Editor

This commit is contained in:
Doug Kearns
2008-12-13 01:19:05 +11:00
parent e9c53d3776
commit 64f00164cc

View File

@@ -48,7 +48,7 @@ function Editor() //{{{
function getController() function getController()
{ {
var ed = getEditor(); let ed = getEditor();
if (!ed || !ed.controllers) if (!ed || !ed.controllers)
return null; return null;
@@ -71,7 +71,7 @@ function Editor() //{{{
// add mappings for commands like h,j,k,l,etc. in CARET, VISUAL and TEXTAREA mode // add mappings for commands like h,j,k,l,etc. in CARET, VISUAL and TEXTAREA mode
function addMovementMap(keys, hasCount, caretModeMethod, caretModeArg, textareaCommand, visualTextareaCommand) function addMovementMap(keys, hasCount, caretModeMethod, caretModeArg, textareaCommand, visualTextareaCommand)
{ {
var extraInfo = {}; let extraInfo = {};
if (hasCount) if (hasCount)
extraInfo.flags = Mappings.flags.COUNT; extraInfo.flags = Mappings.flags.COUNT;
@@ -152,7 +152,7 @@ function Editor() //{{{
// mode = "i" -> add :iabbrev, :iabclear and :iunabbrev commands // mode = "i" -> add :iabbrev, :iabclear and :iunabbrev commands
function addAbbreviationCommands(ch, modeDescription) function addAbbreviationCommands(ch, modeDescription)
{ {
var mode = ch || "!"; let mode = ch || "!";
modeDescription = modeDescription ? " in " + modeDescription + " mode" : ""; modeDescription = modeDescription ? " in " + modeDescription + " mode" : "";
commands.add([ch ? ch + "a[bbrev]" : "ab[breviate]"], commands.add([ch ? ch + "a[bbrev]" : "ab[breviate]"],
@@ -416,7 +416,7 @@ function Editor() //{{{
} }
else else
{ {
var sel = window.content.document.getSelection(); let sel = window.content.document.getSelection();
if (sel) if (sel)
util.copyToClipboard(sel, true); util.copyToClipboard(sel, true);
else else
@@ -444,7 +444,7 @@ function Editor() //{{{
["f"], "Move to a character on the current line after the cursor", ["f"], "Move to a character on the current line after the cursor",
function (count, arg) function (count, arg)
{ {
var pos = editor.findCharForward(arg, count); let pos = editor.findCharForward(arg, count);
if (pos >= 0) if (pos >= 0)
editor.moveToPosition(pos, true, liberator.mode == modes.VISUAL); editor.moveToPosition(pos, true, liberator.mode == modes.VISUAL);
}, },
@@ -454,7 +454,7 @@ function Editor() //{{{
["F"], "Move to a charater on the current line before the cursor", ["F"], "Move to a charater on the current line before the cursor",
function (count, arg) function (count, arg)
{ {
var pos = editor.findCharBackward(arg, count); let pos = editor.findCharBackward(arg, count);
if (pos >= 0) if (pos >= 0)
editor.moveToPosition(pos, false, liberator.mode == modes.VISUAL); editor.moveToPosition(pos, false, liberator.mode == modes.VISUAL);
}, },
@@ -464,7 +464,7 @@ function Editor() //{{{
["t"], "Move before a character on the current line", ["t"], "Move before a character on the current line",
function (count, arg) function (count, arg)
{ {
var pos = editor.findCharForward(arg, count); let pos = editor.findCharForward(arg, count);
if (pos >= 0) if (pos >= 0)
editor.moveToPosition(pos - 1, true, liberator.mode == modes.VISUAL); editor.moveToPosition(pos - 1, true, liberator.mode == modes.VISUAL);
}, },
@@ -474,7 +474,7 @@ function Editor() //{{{
["T"], "Move before a character on the current line, backwards", ["T"], "Move before a character on the current line, backwards",
function (count, arg) function (count, arg)
{ {
var pos = editor.findCharBackward(arg, count); let pos = editor.findCharBackward(arg, count);
if (pos >= 0) if (pos >= 0)
editor.moveToPosition(pos + 1, false, liberator.mode == modes.VISUAL); editor.moveToPosition(pos + 1, false, liberator.mode == modes.VISUAL);
}, },
@@ -496,14 +496,14 @@ function Editor() //{{{
while (count-- > 0) while (count-- > 0)
{ {
var text = getEditor().value; let text = getEditor().value;
var pos = getEditor().selectionStart; let pos = getEditor().selectionStart;
if (pos >= text.length) if (pos >= text.length)
{ {
liberator.beep(); liberator.beep();
return; return;
} }
var chr = text[pos]; let chr = text[pos];
getEditor().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);
@@ -529,8 +529,8 @@ function Editor() //{{{
line: function () line: function ()
{ {
var line = 1; let line = 1;
var text = getEditor().value; let text = getEditor().value;
for (let i = 0; i < getEditor().selectionStart; i++) for (let i = 0; i < getEditor().selectionStart; i++)
if (text[i] == "\n") if (text[i] == "\n")
line++; line++;
@@ -539,8 +539,8 @@ function Editor() //{{{
col: function () col: function ()
{ {
var col = 1; let col = 1;
var text = getEditor().value; let text = getEditor().value;
for (let i = 0; i < getEditor().selectionStart; i++) for (let i = 0; i < getEditor().selectionStart; i++)
{ {
col++; col++;
@@ -552,30 +552,30 @@ function Editor() //{{{
unselectText: function () unselectText: function ()
{ {
var elt = window.document.commandDispatcher.focusedElement; let elt = window.document.commandDispatcher.focusedElement;
if (elt && elt.selectionEnd) if (elt && elt.selectionEnd)
elt.selectionEnd = elt.selectionStart; elt.selectionEnd = elt.selectionStart;
}, },
selectedText: function () selectedText: function ()
{ {
var text = getEditor().value; let text = getEditor().value;
return text.substring(getEditor().selectionStart, getEditor().selectionEnd); return text.substring(getEditor().selectionStart, getEditor().selectionEnd);
}, },
pasteClipboard: function () pasteClipboard: function ()
{ {
var elt = window.document.commandDispatcher.focusedElement; let elt = window.document.commandDispatcher.focusedElement;
if (elt.setSelectionRange && util.readFromClipboard()) if (elt.setSelectionRange && util.readFromClipboard())
// readFromClipboard would return 'undefined' if not checked // readFromClipboard would return 'undefined' if not checked
// dunno about .setSelectionRange // dunno about .setSelectionRange
{ {
var rangeStart = elt.selectionStart; // caret position let rangeStart = elt.selectionStart; // caret position
var rangeEnd = elt.selectionEnd; let rangeEnd = elt.selectionEnd;
var tempStr1 = elt.value.substring(0, rangeStart); let tempStr1 = elt.value.substring(0, rangeStart);
var tempStr2 = util.readFromClipboard(); let tempStr2 = util.readFromClipboard();
var tempStr3 = elt.value.substring(rangeEnd); let tempStr3 = elt.value.substring(rangeEnd);
elt.value = tempStr1 + tempStr2 + tempStr3; elt.value = tempStr1 + tempStr2 + tempStr3;
elt.selectionStart = rangeStart + tempStr2.length; elt.selectionStart = rangeStart + tempStr2.length;
elt.selectionEnd = elt.selectionStart; elt.selectionEnd = elt.selectionStart;
@@ -585,7 +585,7 @@ function Editor() //{{{
// count is optional, defaults to 1 // count is optional, defaults to 1
executeCommand: function (cmd, count) executeCommand: function (cmd, count)
{ {
var controller = getController(); let controller = getController();
if (!controller || !controller.supportsCommand(cmd) || !controller.isCommandEnabled(cmd)) if (!controller || !controller.supportsCommand(cmd) || !controller.isCommandEnabled(cmd))
{ {
liberator.beep(); liberator.beep();
@@ -595,7 +595,7 @@ function Editor() //{{{
if (typeof count != "number" || count < 1) if (typeof count != "number" || count < 1)
count = 1; count = 1;
var didCommand = false; let didCommand = false;
while (count--) while (count--)
{ {
// some commands need this try/catch workaround, because a cmd_charPrevious triggered // some commands need this try/catch workaround, because a cmd_charPrevious triggered
@@ -747,7 +747,7 @@ function Editor() //{{{
lastFindChar = ch; lastFindChar = ch;
lastFindCharFunc = this.findCharForward; lastFindCharFunc = this.findCharForward;
var text = getEditor().value; let text = getEditor().value;
if (!typeof count == "number" || count < 1) if (!typeof count == "number" || count < 1)
count = 1; count = 1;
@@ -774,7 +774,7 @@ function Editor() //{{{
lastFindChar = ch; lastFindChar = ch;
lastFindCharFunc = this.findCharBackward; lastFindCharFunc = this.findCharBackward;
var text = getEditor().value; let text = getEditor().value;
if (!typeof count == "number" || count < 1) if (!typeof count == "number" || count < 1)
count = 1; count = 1;
@@ -813,11 +813,11 @@ function Editor() //{{{
if (!options["editor"]) if (!options["editor"])
return false; return false;
var textBox = null; let textBox = null;
if (!(config.isComposeWindow)) if (!(config.isComposeWindow))
textBox = document.commandDispatcher.focusedElement; textBox = document.commandDispatcher.focusedElement;
var text = ""; // XXX let text = ""; // XXX
if (textBox) if (textBox)
text = textBox.value; text = textBox.value;
else if (typeof GetCurrentEditor == "function") // Thunderbird composer else if (typeof GetCurrentEditor == "function") // Thunderbird composer
@@ -866,15 +866,15 @@ function Editor() //{{{
// { // {
try try
{ {
var val = io.readFile(tmpfile); let val = io.readFile(tmpfile);
if (textBox) if (textBox)
textBox.value = val; textBox.value = val;
else else
{ {
//document.getElementById("content-frame").contentDocument.designMode = "on"; //document.getElementById("content-frame").contentDocument.designMode = "on";
var editor = GetCurrentEditor(); let editor = GetCurrentEditor();
var wholeDocRange = editor.document.createRange(); let wholeDocRange = editor.document.createRange();
var rootNode = editor.rootElement.QueryInterface(Components.interfaces.nsIDOMNode); let rootNode = editor.rootElement.QueryInterface(Components.interfaces.nsIDOMNode);
wholeDocRange.selectNodeContents(rootNode); wholeDocRange.selectNodeContents(rootNode);
editor.selection.addRange(wholeDocRange); editor.selection.addRange(wholeDocRange);
editor.selection.deleteFromDocument(); editor.selection.deleteFromDocument();
@@ -894,8 +894,8 @@ function Editor() //{{{
// blink the textbox after returning // blink the textbox after returning
if (textBox) if (textBox)
{ {
var timeout = 100; let timeout = 100;
var colors = [tmpBg, oldBg, tmpBg, oldBg]; let colors = [tmpBg, oldBg, tmpBg, oldBg];
(function () { (function () {
textBox.style.backgroundColor = colors.shift(); textBox.style.backgroundColor = colors.shift();
if (colors.length > 0) if (colors.length > 0)
@@ -982,7 +982,7 @@ function Editor() //{{{
if (abbreviations[lhs][0][0] == "!") if (abbreviations[lhs][0][0] == "!")
{ {
var tmpOpp = ("i" == filter) ? "c" : "i"; let tmpOpp = ("i" == filter) ? "c" : "i";
abbreviations[lhs][1] = [tmpOpp, abbreviations[lhs][0][1]]; abbreviations[lhs][1] = [tmpOpp, abbreviations[lhs][0][1]];
abbreviations[lhs][0] = [filter, rhs]; abbreviations[lhs][0] = [filter, rhs];
return; return;
@@ -996,13 +996,13 @@ function Editor() //{{{
expandAbbreviation: function (filter) // try to find an candidate and replace accordingly expandAbbreviation: function (filter) // try to find an candidate and replace accordingly
{ {
var textbox = getEditor(); let textbox = getEditor();
if (!textbox) if (!textbox)
return; return;
var text = textbox.value; let text = textbox.value;
var currStart = textbox.selectionStart; let currStart = textbox.selectionStart;
var currEnd = textbox.selectionEnd; let currEnd = textbox.selectionEnd;
var foundWord = text.substring(0, currStart).replace(/^(.|\n)*?(\S+)$/m, "$2"); // get last word \b word boundary let foundWord = text.substring(0, currStart).replace(/^(.|\n)*?(\S+)$/m, "$2"); // get last word \b word boundary
if (!foundWord) if (!foundWord)
return true; return true;
@@ -1013,8 +1013,8 @@ function Editor() //{{{
if (lhs == foundWord && (abbreviations[lhs][i][0] == filter || abbreviations[lhs][i][0] == "!")) if (lhs == foundWord && (abbreviations[lhs][i][0] == filter || abbreviations[lhs][i][0] == "!"))
{ {
// if found, replace accordingly // if found, replace accordingly
var len = foundWord.length; let len = foundWord.length;
var abbrText = abbreviations[lhs][i][1]; let abbrText = abbreviations[lhs][i][1];
text = text.substring(0, currStart - len) + abbrText + text.substring(currStart); text = text.substring(0, currStart - len) + abbrText + text.substring(currStart);
textbox.value = text; textbox.value = text;
textbox.selectionStart = currStart - len + abbrText.length; textbox.selectionStart = currStart - len + abbrText.length;