opentui icon indicating copy to clipboard operation
opentui copied to clipboard

deleteToLineStart() does nothing when cursor is at column 0

Open fredsh2k opened this issue 7 months ago • 3 comments

Description

EditBufferRenderable.deleteToLineStart() only deletes when cursor.col > 0. When the cursor is already at column 0 (e.g. after a previous delete-to-line-start cleared the line content), pressing Ctrl+U again does nothing. It should join with the previous line by removing the newline character, similar to how deleteCharBackward() works at column 0.

Current behavior

line 1
line 2
|line 3    <- cursor at col 0, row 2

Pressing Ctrl+U → nothing happens (stuck).

Expected behavior

Pressing Ctrl+U at col 0 should delete the newline before the cursor, joining with the previous line:

line 1
line 2|line 3    <- cursor now at end of "line 2"

Root cause

In EditBufferRenderable.deleteToLineStart():

deleteToLineStart() {
    const cursor = this.editorView.getCursor();
    if (cursor.col > 0) {  // <-- skips when col === 0
        this.editBuffer.deleteRange(cursor.row, 0, cursor.row, cursor.col);
    }
    this.requestRender();
    return true;
}

The cursor.col > 0 guard prevents any action when the cursor is at the start of a line. When col === 0 and row > 0, it should delete the newline to join with the previous line.

fredsh2k avatar Apr 09 '26 09:04 fredsh2k

It should join with the previous line by removing the newline character

This is a behavior change. What do you think @kommander?

Ctrl+U at col 0 moves to the prev line.

simonklee avatar Apr 10 '26 12:04 simonklee

@simonklee that PR makes sense to me and looks fine.

kommander avatar Apr 10 '26 14:04 kommander

Yeh, i tested it and it works fine. it was mostly about the behavior, if we want that.

simonklee avatar Apr 10 '26 15:04 simonklee