Add the ability to close splits and change splits using the mouse

This commits adds split navigation with the mouse and the ability to
close splits. You can now also open a file directly with the hsplit
and vsplit commands.
This commit is contained in:
Zachary Yedidia
2016-07-01 18:12:37 -04:00
parent d2b11c2f98
commit 4a15a1d3c8
4 changed files with 112 additions and 13 deletions

View File

@@ -2,11 +2,14 @@ package main
import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"os/signal"
"regexp"
"strings"
"github.com/mitchellh/go-homedir"
)
var commands map[string]func([]string)
@@ -63,11 +66,48 @@ func DefaultCommands() map[string]string {
}
}
// VSplit opens a vertical split with file given in the first argument
// If no file is given, it opens an empty buffer in a new split
func VSplit(args []string) {
CurView().VSplit()
if len(args) == 0 {
CurView().VSplit(NewBuffer([]byte{}, ""))
} else {
filename := args[0]
home, _ := homedir.Dir()
filename = strings.Replace(filename, "~", home, 1)
file, err := ioutil.ReadFile(filename)
var buf *Buffer
if err != nil {
// File does not exist -- create an empty buffer with that name
buf = NewBuffer([]byte{}, filename)
} else {
buf = NewBuffer(file, filename)
}
CurView().VSplit(buf)
}
}
// HSplit opens a horizontal split with file given in the first argument
// If no file is given, it opens an empty buffer in a new split
func HSplit(args []string) {
CurView().HSplit()
if len(args) == 0 {
CurView().HSplit(NewBuffer([]byte{}, ""))
} else {
filename := args[0]
home, _ := homedir.Dir()
filename = strings.Replace(filename, "~", home, 1)
file, err := ioutil.ReadFile(filename)
var buf *Buffer
if err != nil {
// File does not exist -- create an empty buffer with that name
buf = NewBuffer([]byte{}, filename)
} else {
buf = NewBuffer(file, filename)
}
CurView().HSplit(buf)
}
}
// Set sets an option