Skip to content

Commit b0f7395

Browse files
committed
Ensure asm tab stops are valid on save
Filter and sort asm tab stops to be monotonicly increasing [1..MAX_COLS].
1 parent bcd2cab commit b0f7395

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/ide/settings.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { current_project, getModeForPath, isAsmMode, projectWindows } from "./ui
66
import { isMobileDevice } from "./views/baseviews";
77
import { debugHighlightTagsTooltip } from "./views/debug";
88
import { SourceEditor } from "./views/editors";
9-
import { tabExtension } from "./views/tabs";
9+
import { MAX_COLS, tabExtension } from "./views/tabs";
1010

1111
const MIN_TAB_SIZE = 1;
1212
const MAX_TAB_SIZE = 40;
@@ -179,9 +179,17 @@ export function openSettings() {
179179
callback: () => {
180180
settings.tabSize = Math.min(MAX_TAB_SIZE, Math.max(MIN_TAB_SIZE, parseInt($('#setting_tabSize').val() as string) || MIN_TAB_SIZE));
181181
settings.tabsToSpaces = $('#setting_tabInsertsSpaces').is(':checked');
182-
settings.asmTabStops.opcodes = parseInt($('#setting_asmOpcodes').val() as string) || undefined;
183-
settings.asmTabStops.operands = parseInt($('#setting_asmOperands').val() as string) || undefined;
184-
settings.asmTabStops.comments = parseInt($('#setting_asmComments').val() as string) || undefined;
182+
183+
// Ensure asm tab stops are monotonicly increasing and in range [1..MAX_COLS].
184+
const asmTabStops = [
185+
parseInt($('#setting_asmOpcodes').val() as string) || undefined,
186+
parseInt($('#setting_asmOperands').val() as string) || undefined,
187+
parseInt($('#setting_asmComments').val() as string) || undefined,
188+
].filter(n => n > 0 && n <= MAX_COLS).sort((a, b) => a - b);
189+
settings.asmTabStops.opcodes = asmTabStops[0];
190+
settings.asmTabStops.operands = asmTabStops[1];
191+
settings.asmTabStops.comments = asmTabStops[2];
192+
185193
settings.showLineNumbers = $('#setting_showLineNumbers').is(':checked');
186194
settings.highlightSpecialChars = $('#setting_highlightSpecialChars').is(':checked');
187195
settings.highlightTrailingWhitespace = $('#setting_highlightTrailingWhitespace').is(':checked');

0 commit comments

Comments
 (0)