diff options
author | Kris Maglione <maglione.k@gmail.com> | 2011-03-10 18:40:41 -0500 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2011-03-10 18:40:41 -0500 |
commit | 24842777143a44aaf08468a2289a04487cf82dc3 (patch) | |
tree | 4e02895b3751dda7c314c542efe0b403959fb2b1 | |
parent | e77c97b6cb93b5f8e1224bb9fcca9d1d767911fe (diff) | |
download | pentadactyl-24842777143a44aaf08468a2289a04487cf82dc3.tar.gz |
Fix t_f issues. Closes issue #424.
-rw-r--r-- | common/content/commandline.js | 1 | ||||
-rw-r--r-- | common/content/editor.js | 67 |
2 files changed, 30 insertions, 38 deletions
diff --git a/common/content/commandline.js b/common/content/commandline.js index 69e6a3cc..0ef59038 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -152,6 +152,7 @@ var CommandWidgets = Class("CommandWidgets", { return this.commandbar; } }); + this.updateVisibility(); }, addElement: function addElement(obj) { const self = this; diff --git a/common/content/editor.js b/common/content/editor.js index e1df6537..9e0eaa69 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -189,50 +189,41 @@ var Editor = Module("editor", { } }, - // returns the position of char - findCharForward: function (ch, count) { - if (!Editor.getEditor()) + findChar: function (key, count, backward) { + + let editor = Editor.getEditor(); + if (!editor) return -1; - let text = Editor.getEditor().value; // XXX if (count == null) count = 1; - for (let i = Editor.getEditor().selectionEnd + 1; i < text.length; i++) { - if (text[i] == "\n") - break; - if (text[i] == ch) - count--; - if (count == 0) - return i + 1; // always position the cursor after the char - } - - dactyl.beep(); - return -1; - }, - - // returns the position of char - findCharBackward: function (ch, count) { - if (!Editor.getEditor()) - return -1; + let code = events.fromString(key)[0].charCode; + util.assert(code); + let char = String.fromCharCode(code); - let text = Editor.getEditor().value; - // XXX - if (count == null) - count = 1; + let text = editor.value; + let caret = editor.selectionEnd; + if (backward) { + let end = text.lastIndexOf("\n", caret); + while (caret > end && caret >= 0 && count--) + caret = text.lastIndexOf(char, caret - 1); + } + else { + let end = text.indexOf("\n", caret); + if (end == -1) + end = text.length; - for (let i = Editor.getEditor().selectionStart - 1; i >= 0; i--) { - if (text[i] == "\n") - break; - if (text[i] == ch) - count--; - if (count == 0) - return i; + while (caret < end && caret >= 0 && count--) + caret = text.indexOf(char, caret + 1); } - dactyl.beep(); - return -1; + if (count > 0) + caret = -1; + if (caret == -1) + dactyl.beep(); + return caret; }, /** @@ -777,7 +768,7 @@ var Editor = Module("editor", { mappings.add([modes.TEXT_EDIT, modes.VISUAL], ["f"], "Move to a character on the current line after the cursor", function ({ arg, count }) { - let pos = editor.findCharForward(arg, Math.max(count, 1)); + let pos = editor.findChar(arg, Math.max(count, 1)); if (pos >= 0) editor.moveToPosition(pos, true, modes.main == modes.VISUAL); }, @@ -786,7 +777,7 @@ var Editor = Module("editor", { mappings.add([modes.TEXT_EDIT, modes.VISUAL], ["F"], "Move to a character on the current line before the cursor", function ({ arg, count }) { - let pos = editor.findCharBackward(arg, Math.max(count, 1)); + let pos = editor.findChar(arg, Math.max(count, 1), true); if (pos >= 0) editor.moveToPosition(pos, false, modes.main == modes.VISUAL); }, @@ -795,7 +786,7 @@ var Editor = Module("editor", { mappings.add([modes.TEXT_EDIT, modes.VISUAL], ["t"], "Move before a character on the current line", function ({ arg, count }) { - let pos = editor.findCharForward(arg, Math.max(count, 1)); + let pos = editor.findChar(arg, Math.max(count, 1)); if (pos >= 0) editor.moveToPosition(pos - 1, true, modes.main == modes.VISUAL); }, @@ -804,7 +795,7 @@ var Editor = Module("editor", { mappings.add([modes.TEXT_EDIT, modes.VISUAL], ["T"], "Move before a character on the current line, backwards", function ({ arg, count }) { - let pos = editor.findCharBackward(arg, Math.max(count, 1)); + let pos = editor.findChar(arg, Math.max(count, 1), true); if (pos >= 0) editor.moveToPosition(pos + 1, false, modes.main == modes.VISUAL); }, |