feat: improve textbox editor behaviour
This commit is contained in:
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user