-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinsert.go
More file actions
114 lines (93 loc) · 1.78 KB
/
insert.go
File metadata and controls
114 lines (93 loc) · 1.78 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package wig
import (
"strings"
"github.com/gdamore/tcell/v2"
)
func HandleInsertKey(ctx Context, ev *tcell.EventKey) {
cur := ContextCursorGet(ctx)
line := CursorLine(ctx.Buf, cur)
ch := ev.Rune()
if ev.Key() == tcell.KeyCtrlJ {
ev = tcell.NewEventKey(tcell.KeyEnter, 0, tcell.ModNone)
}
{
if ctx.Buf.Mode() != MODE_INSERT {
return
}
if ev.Modifiers()&tcell.ModCtrl != 0 {
return
}
if ev.Modifiers()&tcell.ModAlt != 0 {
return
}
if ev.Modifiers()&tcell.ModMeta != 0 {
return
}
}
if ev.Key() == tcell.KeyEnter {
ch = '\n'
}
{
if ch == '\t' {
if Tabstopped(ctx) {
TabstopNext(ctx)
return
}
if strings.TrimSpace(line.Value.String()) == "" {
goto insertChar
}
if cur.Char >= len(line.Value.String())-1 {
if ctx.Editor.AutocompleteTrigger(ctx) {
return
}
}
goto insertChar
return
}
}
insertChar:
if ch == 0 {
return
}
if ch == '\t' {
indentInsert(ctx)
return
}
if ev.Key() == tcell.KeyBackspace || ev.Key() == tcell.KeyBackspace2 {
start := *cur
start.Char--
if start.Char < 0 {
if line.Prev() == nil {
return
}
cur.Line--
CmdGotoLineEnd(ctx)
// delete \n on prev line
TextDelete(ctx.Buf, &Selection{
Start: Cursor{Line: start.Line - 1, Char: len(line.Prev().Value) - 1},
End: Cursor{Line: start.Line - 1, Char: len(line.Prev().Value)},
})
return
}
TextDelete(ctx.Buf, &Selection{
Start: start,
End: *cur,
})
if cur.Char > 0 {
cur.Char--
}
return
}
SelectionDelete(ctx)
TextInsert(ctx.Buf, line, cur.Char, string(ch))
if ev.Key() == tcell.KeyEnter {
CmdCursorLineDown(ctx)
CmdCursorBeginningOfTheLine(ctx)
indent(ctx)
return
}
if cur.Char < len(line.Value) {
cur.Char++
cur.PreserveCharPosition = cur.Char
}
}