Skip to content

Commit cb6c879

Browse files
yoichiroclaude
andcommitted
fix: Prevent blank lines from accumulating between keymaps array and postamble
The generator was adding an extra newline after "};" before appending the postamble, which already starts with a newline. Each Visual Editor round-trip (parse → generate) added one more blank line. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1e1a3b1 commit cb6c879

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/services/workbench/KeymapCGenerator.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,29 @@ void my_custom_function(void) {
185185
expect(reParsed!.preamble).toContain('#define MY_MACRO 42');
186186
expect(reParsed!.postamble).toContain('my_custom_function');
187187
});
188+
189+
it('does not accumulate blank lines between array and postamble across round-trips', () => {
190+
const original = `#include QMK_KEYBOARD_H
191+
192+
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
193+
[0] = LAYOUT(KC_A, KC_B)
194+
};
195+
196+
layer_state_t layer_state_set_user(layer_state_t state) {
197+
return state;
198+
}
199+
`;
200+
let content = original;
201+
for (let i = 0; i < 5; i++) {
202+
const parsed = parseKeymapC(content);
203+
expect(parsed).not.toBeNull();
204+
content = generateKeymapC(parsed!);
205+
}
206+
207+
const blankLinesBetween = content
208+
.split('};')[1]
209+
.split('layer_state_t')[0];
210+
expect(blankLinesBetween).toBe('\n\n');
211+
});
188212
});
189213
});

src/services/workbench/KeymapCGenerator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function generateKeymapC(
5353
result += '\n';
5454
});
5555

56-
result += '};\n';
56+
result += '};';
5757
result += parsed.postamble;
5858

5959
return result;

0 commit comments

Comments
 (0)