mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-04-04 16:03:32 +02:00
Sanify editor.expandAbbreviation. Support undo.
This commit is contained in:
@@ -162,12 +162,15 @@ var Editor = Module("editor", {
|
|||||||
if (node == range.endContainer)
|
if (node == range.endContainer)
|
||||||
end = range.endOffset;
|
end = range.endOffset;
|
||||||
|
|
||||||
if (start != 0 || end != text.length)
|
if (start == 0 && end == text.length)
|
||||||
|
text = munger(text);
|
||||||
|
else
|
||||||
text = text.slice(0, start)
|
text = text.slice(0, start)
|
||||||
+ munger(text.slice(start, end))
|
+ munger(text.slice(start, end))
|
||||||
+ text.slice(end);
|
+ text.slice(end);
|
||||||
else
|
|
||||||
text = munger(text);
|
if (text == node.textContent)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (editor instanceof Ci.nsIPlaintextEditor) {
|
if (editor instanceof Ci.nsIPlaintextEditor) {
|
||||||
this.selectionRange = RangeFind.nodeContents(node);
|
this.selectionRange = RangeFind.nodeContents(node);
|
||||||
@@ -370,19 +373,16 @@ var Editor = Module("editor", {
|
|||||||
*/
|
*/
|
||||||
expandAbbreviation: function (mode) {
|
expandAbbreviation: function (mode) {
|
||||||
let elem = this.element;
|
let elem = this.element;
|
||||||
if (!DOM(elem).isInput && elem.value)
|
|
||||||
|
let range = this.selectionRange.cloneRange();
|
||||||
|
if (!range.collapsed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let text = elem.value;
|
Editor.extendRange(range, false, /\S/);
|
||||||
let start = elem.selectionStart;
|
let abbrev = abbreviations.match(mode, String(range));
|
||||||
let end = elem.selectionEnd;
|
|
||||||
let abbrev = abbreviations.match(mode, text.substring(0, start).replace(/.*\s/g, ""));
|
|
||||||
if (abbrev) {
|
if (abbrev) {
|
||||||
let len = abbrev.lhs.length;
|
range.setStart(range.startContainer, range.endOffset - abbrev.lhs.length);
|
||||||
let rhs = abbrev.expand(elem);
|
this.mungeRange(range, function () abbrev.expand(elem), true);
|
||||||
elem.value = text.substring(0, start - len) + rhs + text.substring(start);
|
|
||||||
elem.selectionStart = start - len + rhs.length;
|
|
||||||
elem.selectionEnd = end - len + rhs.length;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
Reference in New Issue
Block a user