feat: improve textbox editor behaviour

This commit is contained in:
2026-07-31 15:36:23 +02:00
parent b24669e604
commit e36b00f741
15 changed files with 504 additions and 154 deletions

View File

@@ -306,6 +306,8 @@ func (e *textEditor) handleVisualKey(key tea.KeyMsg, multiline bool, wrapWidth i
e.yankSelection(wrapWidth)
case keyMatches(k, e.keys.Vim.Delete):
e.deleteSelection(wrapWidth)
case keyMatches(k, e.keys.Vim.ReplaceCharacter):
e.substituteSelection(wrapWidth)
case keyMatches(k, e.keys.Vim.Paste):
e.pasteClipboard(true, wrapWidth)
default:
@@ -407,6 +409,20 @@ func (e *textEditor) deleteSelection(wrapWidth int) {
e.stopVisual()
}
func (e *textEditor) substituteSelection(wrapWidth int) {
start, end, ok := e.selectionBounds(wrapWidth)
if !ok {
e.stopVisual()
return
}
runes := []rune(e.Text)
e.Text = string(append(runes[:start], runes[end:]...))
e.Cursor = start
e.Mode = textEditorInsert
e.visualLine = false
e.clearPending()
}
func (e *textEditor) pasteClipboard(replaceSelection bool, wrapWidth int) {
if e.clipboard == nil {
e.clipboard = systemTextClipboard{}