Skip to content

Fix origin-mode cursor positioning#6

Open
jchristn wants to merge 2 commits into
tomlm:mainfrom
jchristn:fix/scroll-region-origin-mode
Open

Fix origin-mode cursor positioning#6
jchristn wants to merge 2 commits into
tomlm:mainfrom
jchristn:fix/scroll-region-origin-mode

Conversation

@jchristn

Copy link
Copy Markdown

Summary

This fixes DEC origin-mode cursor positioning with scroll regions:

  • DECSTBM / CSI t;b r now moves the cursor to home after setting the scroll region.
  • CUP / HVP (CSI row;col H / f) now treat row coordinates as relative to the scroll region when DECOM / origin mode is enabled.
  • VPA / CSI row d now applies the same origin-mode row translation.
  • enabling/disabling origin mode still homes the cursor, using the top margin when origin mode is enabled.

Why

Terminal UIs that reserve a bottom prompt/status row commonly set a scroll region for the output area and use origin-relative cursor addressing. Without these semantics, content can be written to the wrong absolute rows and preserved into scrollback incorrectly.

This is a core emulator behavior fix only. It intentionally does not include any host-rendering, PTY, ConPTY, or Termrig-specific compatibility shims.

Validation

  • dotnet test src\XTerm.NET.slnx --no-restore
  • Result: 589 passed, 0 failed

The test run still reports the existing compiler warnings about EscapeSequenceParser.Dcs and Terminal.HyperlinkChanged; this PR did not introduce new warnings.

@jchristn jchristn marked this pull request as ready for review June 1, 2026 01:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes DEC origin-mode cursor positioning semantics when a scroll region is active, aligning CUP/HVP, VPA, and DECSTBM behavior with expected VT/xterm semantics and adding regression tests to prevent future regressions.

Changes:

  • Added a shared origin-mode row translation helper and applied it to CUP/HVP and VPA.
  • Updated DECSTBM handling to home the cursor after setting the scroll region, and adjusted origin-mode enable/disable homing behavior.
  • Added regression tests covering origin-relative addressing and cursor homing with scroll regions; added a FIXES.md note describing the behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/XTerm.NET/InputHandler.cs Implements origin-mode row translation and cursor homing changes for scroll regions and origin mode toggles.
src/XTerm.NET.Tests/InputHandlerTests.cs Adds regression tests for origin-relative CUP/HVP, origin-relative VPA, and scroll-region cursor homing.
src/XTerm.NET.Tests/ModeHandlingTests.cs Adds regression test ensuring enabling origin mode homes to the top margin when a scroll region is set.
FIXES.md Documents the behavioral fixes and provides minimal reproductions and validation notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1280 to +1288
private int GetAbsoluteCursorRow(int row)
{
if (_terminal.OriginMode)
{
return Math.Clamp(_buffer.ScrollTop + row, _buffer.ScrollTop, _buffer.ScrollBottom);
}

return Math.Clamp(row, 0, _terminal.Rows - 1);
}
Comment thread FIXES.md
Comment on lines +5 to +6
This branch fixes DEC origin-mode cursor positioning with scroll regions. These changes are core terminal emulator behavior and are not specific to Termrig, Avalonia, ConPTY, or any host renderer.

Comment thread FIXES.md
Comment on lines +39 to +41
var terminal = new Terminal(new TerminalOptions { Cols = 20, Rows = 5 });
var handler = new InputHandler(terminal);
terminal.Buffer.SetCursor(10, 10);
Comment thread FIXES.md
Comment on lines +98 to +112
## Validation

Run from this repository root:

```powershell
dotnet test src/XTerm.NET.slnx --no-restore
```

Result on this branch:

```text
Passed: 589
Failed: 0
Skipped: 0
```
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.

2 participants