Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ide/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() : []],
Expand Down
25 changes: 12 additions & 13 deletions src/ide/views/editors.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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()),
Expand Down
Loading