From 682c02af7fba2f7739774de61e0268edc4e028b6 Mon Sep 17 00:00:00 2001 From: Fred Sauer Date: Sat, 28 Mar 2026 11:23:06 -0700 Subject: [PATCH 1/2] Fix asm indention on ENTER Match previous lines' whitespace --- src/ide/views/editors.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/ide/views/editors.ts b/src/ide/views/editors.ts index cecd5394..52123593 100644 --- a/src/ide/views/editors.ts +++ b/src/ide/views/editors.ts @@ -1,7 +1,7 @@ import { defaultKeymap, history, historyKeymap, indentSelection, isolateHistory, redo, undo } from "@codemirror/commands"; import { cpp } from "@codemirror/lang-cpp"; import { markdown } from "@codemirror/lang-markdown"; -import { bracketMatching, foldGutter, indentOnInput, indentService, indentUnit } from "@codemirror/language"; +import { bracketMatching, foldGutter, indentOnInput } from "@codemirror/language"; import { highlightSelectionMatches, search, searchKeymap } from "@codemirror/search"; import { EditorState, Extension } from "@codemirror/state"; import { crosshairCursor, drawSelection, dropCursor, EditorView, highlightActiveLine, highlightActiveLineGutter, keymap, lineNumbers, rectangularSelection, ViewUpdate } from "@codemirror/view"; @@ -144,19 +144,18 @@ export class SourceEditor implements ProjectView { doc: text, extensions: [ - // Non-asm: 2-space indent (placed before settings so it takes precedence over tabSize-based indentUnit) - isAsm ? [] : indentUnit.of(" "), - // Asm: copy previous line's indentation since asm parsers lack proper indent rules - isAsm ? indentService.of((context, pos) => { - let lineNum = context.state.doc.lineAt(pos).number; - if (lineNum >= 0) { - let prevLine = context.state.doc.line(lineNum); - if (prevLine.text.trim()) { - return context.lineIndent(prevLine.from); - } + isAsm ? keymap.of([{ + key: "Enter", + run: (view) => { + const pos = view.state.selection.main.head; + const line = view.state.doc.lineAt(pos); + const indent = line.text.match(/^[ \t]*/)[0].slice(0, pos - line.from); + // Copy leading whitespace from previous line (tabs or spaces) + view.dispatch(view.state.replaceSelection("\n" + indent), + { scrollIntoView: true, userEvent: "input" }); + return true; } - return 0; - }) : [], + }]) : [], // Keybindings from settings must appear before default keymap. ...settingsExtensions(loadSettings()), From ecc69f652f42ad4f076665fffe08cbd1795394a4 Mon Sep 17 00:00:00 2001 From: Fred Sauer Date: Sat, 28 Mar 2026 11:23:37 -0700 Subject: [PATCH 2/2] Fix C indentation use of tabs/spaces setting --- src/ide/settings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ide/settings.ts b/src/ide/settings.ts index 7fede98c..66b3b145 100644 --- a/src/ide/settings.ts +++ b/src/ide/settings.ts @@ -53,7 +53,7 @@ export function saveSettings(settings: EditorSettings) { } const compartmentValues: [Compartment, (s: EditorSettings) => Extension][] = [ - [tabSizeCompartment, s => [EditorState.tabSize.of(s.tabSize), indentUnit.of(" ".repeat(s.tabSize))]], + [tabSizeCompartment, s => [EditorState.tabSize.of(s.tabSize), indentUnit.of(s.tabsToSpaces ? " ".repeat(s.tabSize) : "\t")]], [tabsToSpacesCompartment, s => keymap.of(s.tabsToSpaces ? smartIndentKeymap : insertTabKeymap)], [highlightSpecialCharsCompartment, s => s.highlightSpecialChars ? highlightSpecialChars() : []], [highlightWhitespaceCompartment, s => s.highlightWhitespace ? highlightWhitespace() : []],