mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
refactor: use term/input
This commit is contained in:
@@ -29,8 +29,10 @@ const (
|
||||
)
|
||||
|
||||
// Internal messages for clipboard operations.
|
||||
type pasteMsg string
|
||||
type pasteErrMsg struct{ error }
|
||||
type (
|
||||
pasteMsg string
|
||||
pasteErrMsg struct{ error }
|
||||
)
|
||||
|
||||
// KeyMap is the key bindings for different actions within the textarea.
|
||||
type KeyMap struct {
|
||||
@@ -605,8 +607,7 @@ func (m *Model) transposeLeft() {
|
||||
if m.col >= len(m.value[m.row]) {
|
||||
m.SetCursor(m.col - 1)
|
||||
}
|
||||
m.value[m.row][m.col-1], m.value[m.row][m.col] =
|
||||
m.value[m.row][m.col], m.value[m.row][m.col-1]
|
||||
m.value[m.row][m.col-1], m.value[m.row][m.col] = m.value[m.row][m.col], m.value[m.row][m.col-1]
|
||||
if m.col < len(m.value[m.row]) {
|
||||
m.SetCursor(m.col + 1)
|
||||
}
|
||||
@@ -1026,9 +1027,12 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||
m.transposeLeft()
|
||||
|
||||
default:
|
||||
m.insertRunesFromUserInput(msg.Runes)
|
||||
m.insertRunesFromUserInput([]rune{msg.Rune})
|
||||
}
|
||||
|
||||
case tea.PasteMsg:
|
||||
m.insertRunesFromUserInput([]rune(msg))
|
||||
|
||||
case pasteMsg:
|
||||
m.insertRunesFromUserInput([]rune(msg))
|
||||
|
||||
|
||||
@@ -328,7 +328,7 @@ func TestVerticalNavigationKeepsCursorHorizontalPosition(t *testing.T) {
|
||||
t.Fatal("Expected cursor to be on the fourth character because there are two double width runes on the first line.")
|
||||
}
|
||||
|
||||
downMsg := tea.KeyMsg{Type: tea.KeyDown, Alt: false, Runes: []rune{}}
|
||||
downMsg := tea.KeyMsg{Sym: tea.KeyDown}
|
||||
textarea, _ = textarea.Update(downMsg)
|
||||
|
||||
lineInfo = textarea.LineInfo()
|
||||
@@ -367,7 +367,7 @@ func TestVerticalNavigationShouldRememberPositionWhileTraversing(t *testing.T) {
|
||||
}
|
||||
|
||||
// Let's go up.
|
||||
upMsg := tea.KeyMsg{Type: tea.KeyUp, Alt: false, Runes: []rune{}}
|
||||
upMsg := tea.KeyMsg{Sym: tea.KeyUp}
|
||||
textarea, _ = textarea.Update(upMsg)
|
||||
|
||||
// We should be at the end of the second line.
|
||||
@@ -386,7 +386,7 @@ func TestVerticalNavigationShouldRememberPositionWhileTraversing(t *testing.T) {
|
||||
}
|
||||
|
||||
// Let's go down, twice.
|
||||
downMsg := tea.KeyMsg{Type: tea.KeyDown, Alt: false, Runes: []rune{}}
|
||||
downMsg := tea.KeyMsg{Sym: tea.KeyDown}
|
||||
textarea, _ = textarea.Update(downMsg)
|
||||
textarea, _ = textarea.Update(downMsg)
|
||||
|
||||
@@ -402,7 +402,7 @@ func TestVerticalNavigationShouldRememberPositionWhileTraversing(t *testing.T) {
|
||||
// work.
|
||||
|
||||
textarea, _ = textarea.Update(upMsg)
|
||||
leftMsg := tea.KeyMsg{Type: tea.KeyLeft, Alt: false, Runes: []rune{}}
|
||||
leftMsg := tea.KeyMsg{Sym: tea.KeyLeft}
|
||||
textarea, _ = textarea.Update(leftMsg)
|
||||
|
||||
if textarea.col != 4 || textarea.row != 1 {
|
||||
@@ -640,7 +640,7 @@ func newTextArea() Model {
|
||||
}
|
||||
|
||||
func keyPress(key rune) tea.Msg {
|
||||
return tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{key}, Alt: false}
|
||||
return tea.KeyMsg{Rune: key}
|
||||
}
|
||||
|
||||
func stripString(str string) string {
|
||||
|
||||
Reference in New Issue
Block a user