Skip to content

feat(editor): add language-aware autoindent - #184

Merged
fcoury merged 1 commit into
mainfrom
feature/language-aware-autoindent
Aug 13, 2026
Merged

feat(editor): add language-aware autoindent#184
fcoury merged 1 commit into
mainfrom
feature/language-aware-autoindent

Conversation

@fcoury

@fcoury fcoury commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Why

Red previously copied the current line's whitespace when opening or splitting lines, without considering the active language. In Python, that left users manually indenting suites and continuations, dedenting branch and stop statements, and removing automatic indentation one character at a time.

What Changed

  • Add a language-specific indentation provider and a Python implementation for suites, bracket and backslash continuations, closing brackets, branch headers, and stop statements while ignoring comments and strings.
  • Apply indentation on Enter, o, and O, and reindent Python branch headers as their trigger text is completed.
  • Track untouched generated indentation so blank whitespace is removed on Escape or cursor movement and carried correctly across another Enter.
  • Make Backspace move to the previous soft tab stop within leading whitespace and Tab advance to the next stop using display columns.
  • Keep indentation changes inside editor transactions so text edits, cursor state, undo/redo, and change notifications stay synchronized.

How to Test

  1. Open a Python buffer, type def something(x):, and press Enter. Expect the next line to begin at four columns. Type return x and press Enter again; expect the new line to dedent to column zero.
  2. Open a line containing values = [, use o, and expect an eight-column hanging indent. Press Backspace twice and expect the cursor to move first to column four and then column zero.
  3. Press Enter after value = "note:" or value = 1 # note:. Expect no extra indentation. Open an automatically indented blank line and press Escape; expect no trailing whitespace to remain.
  4. Run cargo test python_enter_indents_a_suite_and_dedents_after_return and cargo test backspace_uses_soft_tab_stops_inside_leading_indentation; expect both targeted regressions to pass.

@fcoury
fcoury force-pushed the feature/language-aware-autoindent branch from 7152afe to 62fc1e2 Compare August 13, 2026 03:35
@fcoury
fcoury merged commit e72f7d2 into main Aug 13, 2026
16 checks passed
@fcoury
fcoury deleted the feature/language-aware-autoindent branch August 13, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant