Skip to content

Commit

Permalink
🐛 [2.1.71] Fix multi-line value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Feb 19, 2025
1 parent 8d28bf4 commit 6762e96
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

The following enhancements and changes have been made to ***Auto Build Marlin***.

## 2.1.71
- Fix handling of multi-line value replacement

## 2.1.70
- Improve Config Editor layout
- Update Config Editors for external edits
Expand Down
16 changes: 15 additions & 1 deletion abm/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class ConfigEditorProvider {

if (wasDirty != doc.isDirty) {
wasDirty = doc.isDirty;
abm.log(`Document dirty: ${wasDirty}`);
abm.log(`${wasDirty ? "" : "(Saved?) "}Document dirty:${wasDirty} closed:${doc.isClosed}`);
}

const changes = e.contentChanges;
Expand Down Expand Up @@ -275,6 +275,7 @@ class ConfigEditorProvider {
return;
}

// Init the new text as the existing text of the line
let newtext = text;

// Update the value of non-switch options
Expand All @@ -286,6 +287,7 @@ class ConfigEditorProvider {
}
}

// Update un/commenting of #define, as needed
if (changes.enabled)
newtext = newtext.replace(/^(\s*)\/\/+\s*(#define)(\s{1,3})?(\s*)/, '$1$2 $4');
else
Expand All @@ -302,8 +304,20 @@ class ConfigEditorProvider {
const inplace = edit === null;
if (inplace) edit = new vscode.WorkspaceEdit();

// Replace the line with the new text
edit.replace(document.uri, range, newtext);

// Pad a multi-line value with blank lines to keep line numbers from shifting
let multiline = (myschema.bysid[changes.sid].line_end ?? changes.line) - changes.line;
if (multiline > 0) {
let clrline = line;
while (multiline--) {
++clrline;
const range = new vscode.Range(clrline, 0, clrline, Number.MAX_VALUE);
edit.replace(document.uri, range, "");
}
}

if (inplace) ws.applyEdit(edit);
}

Expand Down
3 changes: 2 additions & 1 deletion abm/js/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,8 @@ class ConfigSchema {
'orig': { enabled },
};

if (val !== '') { define_info.value = val; define_info.orig.value = val; }
if (line_end !== line_start) define_info.line_end = line_end;
if (val !== '') define_info.value = define_info.orig.value = val;
if (value_type !== '') define_info.type = value_type;
if (options) define_info.options = options;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "auto-build",
"displayName": "Auto Build Marlin",
"description": "Provides an interface to configure, build, and upload Marlin Firmware.",
"version": "2.1.70",
"version": "2.1.71",
"preview": false,
"publisher": "marlinfirmware",
"icon": "icon.png",
Expand Down

0 comments on commit 6762e96

Please sign in to comment.