From 12850179d53e4e32507f63a17e33d59b81dddbd0 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Wed, 10 Nov 2010 23:49:12 +1100 Subject: [PATCH] Make editor.expandAbbreviation a little more readable. --HG-- extra : rebase_source : 49d92eb99a1b5a52db7d24696341148f822b773c --- common/content/editor.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/common/content/editor.js b/common/content/editor.js index 73960e85..90e52443 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -350,23 +350,22 @@ const Editor = Module("editor", { * Expands an abbreviation in the currently active textbox. * * @param {string} mode The mode filter. - * @see #addAbbreviation + * @see Abbreviation#expand */ expandAbbreviation: function (mode) { - let textbox = Editor.getEditor(); - if (!(textbox && textbox.value)) + let editor = Editor.getEditor(); + if (!(editor && editor.value)) return; - let text = textbox.value; - let currStart = textbox.selectionStart; - let currEnd = textbox.selectionEnd; - let abbrev = abbreviations.match(mode, text.substring(0, currStart).replace(/.*\s/g, "")); + let text = editor.value; + let start = editor.selectionStart; + let end = editor.selectionEnd; + let abbrev = abbreviations.match(mode, text.substring(0, start).replace(/.*\s/g, "")); if (abbrev) { let len = abbrev.lhs.length; - let abbrText = abbrev.expand(textbox); - text = text.substring(0, currStart - len) + abbrText + text.substring(currStart); - textbox.value = text; - textbox.selectionStart = currStart - len + abbrText.length; - textbox.selectionEnd = currEnd - len + abbrText.length; + let rhs = abbrev.expand(editor); + editor.value = text.substring(0, start - len) + rhs + text.substring(start); + editor.selectionStart = start - len + rhs.length; + editor.selectionEnd = end - len + rhs.length; } }, }, {