summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--internal/client/ui/viminput/helpers.go20
-rw-r--r--internal/client/ui/viminput/viminput.go57
4 files changed, 72 insertions, 9 deletions
diff --git a/go.mod b/go.mod
index 434d636..82d9319 100644
--- a/go.mod
+++ b/go.mod
@@ -9,6 +9,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.24
github.com/stretchr/testify v1.9.0
github.com/vmihailenco/msgpack/v5 v5.4.1
+ github.com/davecgh/go-spew v1.1.1
)
require (
@@ -16,7 +17,6 @@ require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.2.3
github.com/charmbracelet/x/term v0.2.0 // indirect
- github.com/davecgh/go-spew v1.1.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
diff --git a/go.sum b/go.sum
index 4c8270a..9700776 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,3 @@
-github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
-github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
diff --git a/internal/client/ui/viminput/helpers.go b/internal/client/ui/viminput/helpers.go
new file mode 100644
index 0000000..c3dcdb1
--- /dev/null
+++ b/internal/client/ui/viminput/helpers.go
@@ -0,0 +1,20 @@
+package viminput
+
+import "unicode"
+
+func IsKeyword(r rune) bool {
+ alphaLower := 'a' <= r && r <= 'z'
+ alphaUpper := 'A' <= r && r <= 'Z'
+ numeric := '0' <= r && r <= '9'
+ return alphaLower || alphaUpper || numeric || r == '_'
+}
+
+func IsGrouped(r1, r2 rune) bool {
+ if IsKeyword(r1) {
+ return IsKeyword(r2)
+ }
+ if unicode.IsSpace(r1) {
+ return unicode.IsSpace(r2)
+ }
+ return !IsKeyword(r2) && !unicode.IsSpace(r2)
+}
diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go
index 3f733b6..7bba0a4 100644
--- a/internal/client/ui/viminput/viminput.go
+++ b/internal/client/ui/viminput/viminput.go
@@ -146,7 +146,11 @@ func (m *Model) Line(lnum int) []rune {
}
func (m *Model) SetCursorColumn(col int) {
- m.cursorColumn = max(col, 0)
+ if len(m.lines[m.CursorLine()]) == 0 {
+ m.cursorColumn = 0
+ } else {
+ m.cursorColumn = max(col, 0)
+ }
m.goalColumn = -1
}
@@ -195,9 +199,7 @@ func (m *Model) handleNormalModeKeys(key tea.KeyMsg) tea.Cmd {
m.mode = InsertMode
case "a":
m.mode = InsertMode
- if len(m.lines[m.CursorLine()]) != 0 {
- m.SetCursorColumn(m.CursorColumn() + 1)
- }
+ m.SetCursorColumn(m.CursorColumn() + 1)
case "I":
m.SetCursorColumn(0)
m.mode = InsertMode
@@ -233,14 +235,53 @@ func (m *Model) handleNormalModeKeys(key tea.KeyMsg) tea.Cmd {
}
case "x":
line := m.lines[m.CursorLine()]
- end := len(line) - 1
- if end+1 != 0 {
+ if len(line) != 0 {
+ end := len(line) - 1
copy(line[m.CursorColumn():], line[m.CursorColumn()+1:])
m.lines[m.CursorLine()] = line[:end]
if m.CursorColumn() == end {
m.SetCursorColumn(m.CursorColumn() - 1)
}
}
+ case "D":
+ line := m.lines[m.CursorLine()]
+ if len(line) != 0 {
+ m.lines[m.CursorLine()] = line[:m.CursorColumn()]
+ m.SetCursorColumn(m.CursorColumn() - 1)
+ }
+ case "o":
+ m.lines = slices.Insert(m.lines, m.CursorLine()+1, []rune(""))
+ m.SetCursorLine(m.CursorLine() + 1)
+ m.SetCursorColumn(0)
+ m.mode = InsertMode
+ case "O":
+ m.lines = slices.Insert(m.lines, m.CursorLine(), []rune(""))
+ m.SetCursorColumn(0)
+ m.mode = InsertMode
+ case "E":
+ // for {
+ // line := m.lines[m.CursorLine()]
+ // m.SetCursorColumn(m.CursorColumn() + 1)
+ // for m.CursorColumn() == len(line) {
+ // cursorLine := m.CursorLine() + 1
+ // m.SetCursorLine(cursorLine)
+ // m.SetCursorColumn(0)
+ // if cursorLine == len(m.lines) {
+ // return nil
+ // }
+ // }
+ // if !unicode.IsSpace(m.RuneAtCursor()) {
+ // break
+ // }
+ // }
+ // for !unicode.IsSpace(m.RuneAtCursor()) {
+ // line := m.lines[m.CursorLine()]
+ // m.SetCursorColumn(m.CursorColumn() + 1)
+ // if m.CursorColumn() == len(line) {
+ // break
+ // }
+ // }
+ // m.SetCursorColumn(m.CursorColumn() - 1)
}
return nil
}
@@ -262,3 +303,7 @@ func (m *Model) handleInsertModeKeys(key tea.KeyMsg) tea.Cmd {
return nil
}
+
+func (m *Model) RuneAtCursor() rune {
+ return m.lines[m.CursorLine()][m.CursorColumn()]
+}