diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-12-08 17:17:42 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-12-08 17:17:42 +0200 |
| commit | 55f4ca9cd9f0c37fbbad9d38a8b6f8a23be33628 (patch) | |
| tree | 98b49bb061d2008926456dab3dcebe6850ae5510 /internal/client/ui/viminput/viminput.go | |
| parent | 2bee024fb12d1210b0194f9431e0f170ba0f5126 (diff) | |
Backspace and enter support for viminput
Diffstat (limited to 'internal/client/ui/viminput/viminput.go')
| -rw-r--r-- | internal/client/ui/viminput/viminput.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go index e3ebd0c..f45c472 100644 --- a/internal/client/ui/viminput/viminput.go +++ b/internal/client/ui/viminput/viminput.go @@ -254,6 +254,39 @@ func (m *Model) handleInsertModeKeys(key tea.KeyMsg) tea.Cmd { return nil } + if key.Type == tea.KeyBackspace { + line := m.lines[m.cursorLine] + if m.cursorColumn == 0 && m.cursorLine != 0 { + lineBefore := m.lines[m.cursorLine-1] + cursorColumn := len(lineBefore) + + m.lines = slices.Delete(m.lines, m.cursorLine, m.cursorLine+1) + m.lines[m.cursorLine-1] = append(lineBefore, line...) + + m.SetCursorLine(m.cursorLine - 1) + m.SetCursorColumn(cursorColumn) + } else if len(line) != 0 { + m.lines[m.cursorLine] = slices.Delete(line, m.cursorColumn-1, m.cursorColumn) + m.SetCursorColumn(m.cursorColumn - 1) + } + return nil + } + + if key.Type == tea.KeyEnter { + line := m.lines[m.cursorLine] + after := line[m.cursorColumn:] + m.lines[m.cursorLine] = line[:m.cursorColumn] + + var newline []rune + newline = append(newline, after...) + m.lines = slices.Insert(m.lines, m.cursorLine+1, newline) + + m.SetCursorLine(m.cursorLine + 1) + m.SetCursorColumn(0) + + return nil + } + keyStr := key.String() length := len(keyStr) if length == 1 && 32 <= keyStr[0] && keyStr[0] <= 126 { |
