Skip to content

Commit

Permalink
don't modify CM if new text is the same v2
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Aug 4, 2024
1 parent 819d61b commit f0457a0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions edit/moz-section-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function MozSectionWidget(cm, finder = MozSectionFinder(cm)) {
*/
async '.add-applies-to'(elItem, func) {
const pos = func.item.find(1);
cm.replaceRange(`, ${func._.type}("")`, pos, pos);
cm.replaceRange(`, ${func.str.type}("")`, pos, pos);
await new Promise(setTimeout);
$('input', elItem.nextElementSibling).focus();
},
Expand All @@ -99,19 +99,17 @@ function MozSectionWidget(cm, finder = MozSectionFinder(cm)) {
const func = getFuncFor(el);
const pos = func[part].find();
const {value} = el;
if (part === 'type' && value !== func._.type) {
func._.type = func.item[KEY].dataset.type = value;
if (value === func.str[part]) return;
func.str[part] = value;
if (part === 'type') {
func.item[KEY].dataset.type = value;
editor.toggleRegexp(func.value[KEY], value);
}
if (part === 'value' && value === func._.value) {
return;
}
if (part === 'value' && func === getFuncsFor(el)[0]) {
} else if (func === getFuncsFor(el)[0]) {
const sec = getSectionFor(el);
sec.tocEntry.target = value;
if (!sec.tocEntry.label) editor.updateToc([sec]);
}
cm.replaceRange(toDoubleslash(value), pos.from, pos.to);
cm.replaceRange(toDoubleslash(value), pos.from, pos.to, finder.IGNORE_ORIGIN);
},
onclick(event) {
const {target} = event;
Expand Down Expand Up @@ -364,7 +362,7 @@ function MozSectionWidget(cm, finder = MozSectionFinder(cm)) {
const elVal = $(C_VALUE, el);
/** @namespace MarkedFunc */
const res = el[KEY] = {
_: func,
str: {type, value},
item: markFuncPart(start, end, old.item, el),
type: markFuncPart(start, typeEnd, old.type, $(C_TYPE, el), type, toLowerCase),
value: markFuncPart(valuePos, valueEnd, old.value, elVal, value, fromDoubleslash),
Expand Down

0 comments on commit f0457a0

Please sign in to comment.