-
Notifications
You must be signed in to change notification settings - Fork 0
/
region_indent_mode.go
73 lines (65 loc) · 1.54 KB
/
region_indent_mode.go
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
package main
import (
"github.com/nsf/termbox-go"
)
type region_indent_mode struct {
stub_overlay_mode
godit *godit
}
func init_region_indent_mode(godit *godit, dir int) region_indent_mode {
v := godit.active.leaf
r := region_indent_mode{godit: godit}
beg, end := v.line_region()
if dir > 0 {
v.on_vcommand(vcommand_indent_region, 0)
end.boffset++
} else if dir < 0 {
v.on_vcommand(vcommand_deindent_region, 0)
}
v.set_tags(view_tag{
beg_line: beg.line_num,
beg_offset: beg.boffset,
end_line: end.line_num,
end_offset: end.boffset,
fg: termbox.ColorDefault,
bg: termbox.ColorBlue,
})
v.dirty = dirty_everything
godit.set_status("(Type > or < to indent/deindent respectively)")
return r
}
func (r region_indent_mode) exit() {
v := r.godit.active.leaf
v.set_tags()
v.dirty = dirty_everything
}
func (r region_indent_mode) on_key(ev *termbox.Event) {
g := r.godit
v := g.active.leaf
beg, end := v.line_region()
if ev.Mod == 0 {
switch ev.Ch {
case '>':
v.on_vcommand(vcommand_indent_region, 0)
g.set_status("(Type > or < to indent/deindent respectively)")
end.boffset++
goto update_tag
case '<':
v.on_vcommand(vcommand_deindent_region, 0)
g.set_status("(Type > or < to indent/deindent respectively)")
goto update_tag
}
}
g.set_overlay_mode(nil)
g.on_key(ev)
return
update_tag:
v.set_tags(view_tag{
beg_line: beg.line_num,
beg_offset: beg.boffset,
end_line: end.line_num,
end_offset: end.boffset,
fg: termbox.ColorDefault,
bg: termbox.ColorBlue,
})
}