mirror of
https://github.com/Hopiu/micro.git
synced 2026-04-25 08:34:44 +00:00
Add tab command to open a file in a new tab
This commit is contained in:
parent
ddcebe4946
commit
431eb12c96
3 changed files with 30 additions and 2 deletions
|
|
@ -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
|
|
@ -141,6 +141,8 @@ Here are the possible commands that you can use.
|
|||
* `hsplit filename`: same as `vsplit` but opens a horizontal split instead of
|
||||
a vertical split
|
||||
|
||||
* `tab filename`: opens the given file in a new tab.
|
||||
|
||||
### Options
|
||||
|
||||
Micro stores all of the user configuration in its configuration directory.
|
||||
|
|
|
|||
Loading…
Reference in a new issue