Quick first try at vertical splits

This commit is contained in:
Zachary Yedidia
2016-06-15 18:38:37 -04:00
parent cb238db307
commit 9b9ae89e59
2 changed files with 21 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ var commandActions = map[string]func([]string){
"Quit": Quit,
"Save": Save,
"Replace": Replace,
"VSplit": VSplit,
}
// InitCommands initializes the default commands
@@ -56,9 +57,14 @@ func DefaultCommands() map[string]string {
"quit": "Quit",
"save": "Save",
"replace": "Replace",
"vsplit": "VSplit",
}
}
func VSplit(args []string) {
CurView().VSplit()
}
// Set sets an option
func Set(args []string) {
// Set an option and we have to set it for every view

View File

@@ -218,6 +218,20 @@ func (v *View) ReOpen() {
}
}
func (v *View) VSplit() bool {
v.widthPercent /= 2
v.Resize(screen.Size())
newView := NewViewWidthHeight(NewBuffer([]byte{}, ""), v.widthPercent, v.heightPercent)
newView.TabNum = v.TabNum
newView.x = v.x + v.width
tab := tabs[v.TabNum]
tab.curView++
newView.Num = len(tab.views)
tab.views = append(tab.views, newView)
return false
}
// Relocate moves the view window so that the cursor is in view
// This is useful if the user has scrolled far away, and then starts typing
func (v *View) Relocate() bool {
@@ -340,7 +354,7 @@ func (v *View) HandleEvent(event tcell.Event) {
v.freshClip = false
case *tcell.EventMouse:
x, y := e.Position()
x -= v.lineNumOffset - v.leftCol
x -= v.lineNumOffset - v.leftCol + v.x
y += v.Topline - v.y
// Don't relocate for mouse events
relocate = false