Add tab command to open a file in a new tab

This commit is contained in:
Zachary Yedidia
2016-07-24 16:29:03 -04:00
parent ddcebe4946
commit 431eb12c96
3 changed files with 30 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ var commandActions = map[string]func([]string){
"Replace": Replace,
"VSplit": VSplit,
"HSplit": HSplit,
"Tab": NewTab,
}
// InitCommands initializes the default commands
@@ -63,6 +64,7 @@ func DefaultCommands() map[string]string {
"replace": "Replace",
"vsplit": "VSplit",
"hsplit": "HSplit",
"tab": "Tab",
}
}
@@ -110,6 +112,30 @@ func HSplit(args []string) {
}
}
// Tab opens the given file in a new tab
func NewTab(args []string) {
if len(args) == 0 {
CurView().AddTab()
} else {
filename := args[0]
home, _ := homedir.Dir()
filename = strings.Replace(filename, "~", home, 1)
file, _ := ioutil.ReadFile(filename)
tab := NewTabFromView(NewView(NewBuffer(file, filename)))
tab.SetNum(len(tabs))
tabs = append(tabs, tab)
curTab++
if len(tabs) == 2 {
for _, t := range tabs {
for _, v := range t.views {
v.Resize(screen.Size())
}
}
}
}
}
// Set sets an option
func Set(args []string) {
// Set an option and we have to set it for every view

File diff suppressed because one or more lines are too long