-
-
Notifications
You must be signed in to change notification settings - Fork 483
Expand file tree
/
Copy pathvim.go
More file actions
57 lines (45 loc) · 851 Bytes
/
vim.go
File metadata and controls
57 lines (45 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"strconv"
tea "github.com/charmbracelet/bubbletea"
. "github.com/antonmedv/fx/internal/jsonx"
)
func (m *model) runCommand(s string) (tea.Model, tea.Cmd) {
num, err := strconv.Atoi(s)
if err == nil {
gotoLine(m, num)
return m, nil
} else if s == "q" {
return m, tea.Quit
}
return m, nil
}
func gotoLine(m *model, num int) {
m.selectNode(findNode(m, num))
m.commandInput.SetValue("")
m.recordHistory()
}
func findNode(m *model, line int) *Node {
if line >= m.totalLines {
return m.top.Bottom()
}
if line <= 1 {
return m.top
}
node := m.top
for {
if node.ChunkEnd != nil {
node = node.ChunkEnd.Next
} else if node.Collapsed != nil {
node = node.Collapsed
} else {
node = node.Next
}
if node == nil {
return nil
}
if node.LineNumber == line {
return node
}
}
}