Skip to content

textarea: Delete on the last character also removes the following newline #1071

Open

Description

@kimjooyoon

Describe the bug
In textarea, pressing Delete on the last character of a non-final line removes both that character and the following newline. For example, deleting b from ab\ncd produces acd instead of a\ncd.

Reproduced on current main c3bde0d166c2ca607d9864493453fd77bdcae7e4, Go 1.26.0, macOS arm64. No terminal or interactive input is needed.

To reproduce
Run in a module using the revision above:

package main

import (
    "fmt"
    tea "charm.land/bubbletea/v2"
    "charm.land/bubbles/v2/textarea"
)

func main() {
    m := textarea.New()
    m.Focus()
    m.SetValue("ab\ncd")
    m.CursorUp()
    m.SetCursorColumn(1)
    m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyDelete})
    fmt.Printf("%q\n", m.Value())
}

Actual: "acd". Expected: "a\ncd".

DeleteCharacterForward deletes the rune, then checks whether the cursor is at the new line end and merges the next line too. Checking for an existing line end before deleting avoids performing both operations on one keypress. Delete pressed at an existing line end should still join the lines.

I have a three-line reorder and an eight-case regression covering ASCII, a one-character line, a wide character, and line-boundary controls. The public API reproducer was executed before and after the change.

AI disclosure: this report, patch and tests were prepared by a Codex agent. The behavior and fix were tested locally; no upstream acceptance or full cross-platform validation is claimed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions