Skip to content

fix(textarea): navigate and delete whole graphemes - #1067

Open
rupayon123 wants to merge 2 commits into
charmbracelet:mainfrom
rupayon123:contrib/textarea-grapheme-clusters-20261002
Open

rupayon123 wants to merge 2 commits into
charmbracelet:mainfrom
rupayon123:contrib/textarea-grapheme-clusters-20261002

Conversation

@rupayon123

@rupayon123 rupayon123 commented Oct 3, 2026 •

Copy link
Copy Markdown

Refs #1061.

The textarea preserves rune-index positions while using grapheme boundaries for character navigation and forward deletion. SetCursorColumn snaps an interior position to the grapheme start, and vertical movement normalizes the final cursor position. Backspace retains one-code-point deletion so Thai and Hindi marks can be corrected without erasing their consonant. Forward word operations now advance across whole graphemes to avoid getting stuck after cursor snapping.

Validation (Go 1.26.0): three new regressions reproduced interior SetCursorColumn, vertical cursor and consonant-deleting backspace failures before the repair. The repaired textarea suite and full go test ./... suite pass, as do go vet ./... and git diff --check. Added word-navigation/deletion coverage for Hindi, Thai, combining accents and emoji. The earlier Thai backspace assertion was corrected to the requested code-point semantics; it no longer requires deleting the whole cluster.

Local golangci-lint is unavailable; remote lint and the test matrix on the new head remain to be verified. No interactive terminal/mouse or native-language usability test was performed.

@andrinoff andrinoff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your contribution!

Comment thread textarea/textarea.go
m.SetCursorColumn(m.col - 1)
}
start, _ := graphemeAt(m.value[m.row], m.col-1)
m.value[m.row] = append(m.value[m.row][:start], m.value[m.row][m.col:]...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The cursor can still land in the middle of a cluster (moving up/down between lines, clicking, or SetCursorColumn)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

129c18e snaps SetCursorColumn to the cluster start and normalizes the cursor after vertical movement. I reproduced both failures before the change and added regressions. Forward word operations also advance by grapheme so the new snapping cannot leave them stuck. The full Go 1.26.0 test suite and go vet pass; interactive mouse/terminal behavior has not been tested.

Comment thread textarea/textarea.go Outdated
if m.col > 0 {
m.SetCursorColumn(m.col - 1)
}
start, _ := graphemeAt(m.value[m.row], m.col-1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Backspace now deletes the whole cluster, so in Thai or Hindi one press wipes a consonant and all its marks. This is very important

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I restored one-code-point Backspace in 129c18e. The Thai and Hindi regressions now check that removing a mark preserves the consonant. Forward Delete still removes a full grapheme. I also corrected the earlier Thai test that incorrectly expected Backspace to erase the whole cluster. The full test suite passes.

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