diff --git a/cmd/micro/command.go b/cmd/micro/command.go index 6b1fc8ad..cc37bae3 100644 --- a/cmd/micro/command.go +++ b/cmd/micro/command.go @@ -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 diff --git a/cmd/micro/view.go b/cmd/micro/view.go index a3b4b176..e0bc2eed 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -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