refactor: use term/input

This commit is contained in:
Ayman Bagabas
2024-03-06 13:56:40 -05:00
parent e3823b2f22
commit c6d2541152
6 changed files with 49 additions and 39 deletions
+9 -5
View File
@@ -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))
+5 -5
View File
@@ -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 {