Skip to content

Commit

Permalink
don't modify CM if new text is the same
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Aug 3, 2024
1 parent 2ec0b03 commit 819d61b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 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.typeText}("")`, pos, pos);
cm.replaceRange(`, ${func._.type}("")`, pos, pos);
await new Promise(setTimeout);
$('input', elItem.nextElementSibling).focus();
},
Expand All @@ -99,16 +99,19 @@ function MozSectionWidget(cm, finder = MozSectionFinder(cm)) {
const func = getFuncFor(el);
const pos = func[part].find();
const {value} = el;
if (part === 'type' && value !== func.typeText) {
func.typeText = func.item[KEY].dataset.type = value;
if (part === 'type' && value !== func._.type) {
func._.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]) {
const sec = getSectionFor(el);
sec.tocEntry.target = value;
if (!sec.tocEntry.label) editor.updateToc([sec]);
}
cm.replaceRange(toDoubleslash(value), pos.from, pos.to, finder.IGNORE_ORIGIN);
cm.replaceRange(toDoubleslash(value), pos.from, pos.to);
},
onclick(event) {
const {target} = event;
Expand Down Expand Up @@ -361,7 +364,7 @@ function MozSectionWidget(cm, finder = MozSectionFinder(cm)) {
const elVal = $(C_VALUE, el);
/** @namespace MarkedFunc */
const res = el[KEY] = {
typeText: type,
_: func,
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 Expand Up @@ -447,4 +450,5 @@ function MozSectionWidget(cm, finder = MozSectionFinder(cm)) {
function setProp(obj, name, value) {
return Object.defineProperty(obj, name, {value, configurable: true});
}

}
2 changes: 1 addition & 1 deletion edit/source-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ async function SourceEditor() {
const sameCode = editor.isSame(newStyle);
if (sameCode) {
savedGeneration = cm.changeGeneration();
dirty.clear('sourceGeneration');
editor.useSavedStyle(newStyle);
dirty.clear('sourceGeneration');
dirty.clear('enabled');
updateLivePreview();
return;
Expand Down

0 comments on commit 819d61b

Please sign in to comment.