1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 18:27:57 +01:00

Make editor.expandAbbreviation a little more readable.

--HG--
extra : rebase_source : 49d92eb99a1b5a52db7d24696341148f822b773c
This commit is contained in:
Doug Kearns
2010-11-10 23:49:12 +11:00
parent a284543f45
commit 12850179d5

View File

@@ -350,23 +350,22 @@ const Editor = Module("editor", {
* Expands an abbreviation in the currently active textbox. * Expands an abbreviation in the currently active textbox.
* *
* @param {string} mode The mode filter. * @param {string} mode The mode filter.
* @see #addAbbreviation * @see Abbreviation#expand
*/ */
expandAbbreviation: function (mode) { expandAbbreviation: function (mode) {
let textbox = Editor.getEditor(); let editor = Editor.getEditor();
if (!(textbox && textbox.value)) if (!(editor && editor.value))
return; return;
let text = textbox.value; let text = editor.value;
let currStart = textbox.selectionStart; let start = editor.selectionStart;
let currEnd = textbox.selectionEnd; let end = editor.selectionEnd;
let abbrev = abbreviations.match(mode, text.substring(0, currStart).replace(/.*\s/g, "")); let abbrev = abbreviations.match(mode, text.substring(0, start).replace(/.*\s/g, ""));
if (abbrev) { if (abbrev) {
let len = abbrev.lhs.length; let len = abbrev.lhs.length;
let abbrText = abbrev.expand(textbox); let rhs = abbrev.expand(editor);
text = text.substring(0, currStart - len) + abbrText + text.substring(currStart); editor.value = text.substring(0, start - len) + rhs + text.substring(start);
textbox.value = text; editor.selectionStart = start - len + rhs.length;
textbox.selectionStart = currStart - len + abbrText.length; editor.selectionEnd = end - len + rhs.length;
textbox.selectionEnd = currEnd - len + abbrText.length;
} }
}, },
}, { }, {