"ShellMode": (*View).ShellMode,
"CommandMode": (*View).CommandMode,
"Quit": (*View).Quit,
+ "AddTab": (*View).AddTab,
+ "PreviousTab": (*View).PreviousTab,
+ "NextTab": (*View).NextTab,
}
var bindingKeys = map[string]tcell.Key{
"CtrlD": "DuplicateLine",
"CtrlV": "Paste",
"CtrlA": "SelectAll",
+ "CtrlT": "AddTab",
+ "CtrlRightSq": "PreviousTab",
+ "CtrlBackslash": "NextTab",
"Home": "Start",
"End": "End",
"PageUp": "CursorPageUp",
}
// If this is an empty buffer, ask for a filename
if v.Buf.Path == "" {
- filename, canceled := messenger.Prompt("Filename: ", "Save")
+ filename, canceled := messenger.Prompt("Filename: ", "Save", NoCompletion)
if !canceled {
v.Buf.Path = filename
v.Buf.Name = filename
}
messenger.Reset()
messenger.Clear()
+ messenger.Message("Saved " + v.Buf.Path)
} else {
messenger.Error(err.Error())
}
// OpenFile opens a new file in the buffer
func (v *View) OpenFile() bool {
if v.CanClose("Continue? (yes, no, save) ") {
- filename, canceled := messenger.Prompt("File to open: ", "Open")
+ filename, canceled := messenger.Prompt("File to open: ", "Open", FileCompletion)
if canceled {
- return true
+ return false
}
home, _ := homedir.Dir()
filename = strings.Replace(filename, "~", home, 1)
if err != nil {
messenger.Error(err.Error())
- return true
+ return false
}
buf := NewBuffer(file, filename)
v.OpenBuffer(buf)
+ return true
}
- return true
+ return false
}
// Start moves the viewport to the start of the buffer
// JumpLine jumps to a line and moves the view accordingly.
func (v *View) JumpLine() bool {
// Prompt for line number
- linestring, canceled := messenger.Prompt("Jump to line # ", "LineNumber")
+ linestring, canceled := messenger.Prompt("Jump to line # ", "LineNumber", NoCompletion)
if canceled {
return false
}
// ShellMode opens a terminal to run a shell command
func (v *View) ShellMode() bool {
- input, canceled := messenger.Prompt("$ ", "Shell")
+ input, canceled := messenger.Prompt("$ ", "Shell", NoCompletion)
if !canceled {
// The true here is for openTerm to make the command interactive
HandleShellCommand(input, true)
// CommandMode lets the user enter a command
func (v *View) CommandMode() bool {
- input, canceled := messenger.Prompt("> ", "Command")
+ input, canceled := messenger.Prompt("> ", "Command", NoCompletion)
if !canceled {
HandleCommand(input)
}
return v.ToggleHelp()
}
// Make sure not to quit if there are unsaved changes
- if views[mainView].CanClose("Quit anyway? (yes, no, save) ") {
- views[mainView].CloseBuffer()
- screen.Fini()
- os.Exit(0)
+ if v.CanClose("Quit anyway? (yes, no, save) ") {
+ v.CloseBuffer()
+ if len(tabs) > 1 {
+ if len(tabs[v.TabNum].views) == 1 {
+ tabs = tabs[:v.TabNum+copy(tabs[v.TabNum:], tabs[v.TabNum+1:])]
+ for i, t := range tabs {
+ t.SetNum(i)
+ }
+ if curTab >= len(tabs) {
+ curTab--
+ }
+ if curTab == 0 {
+ CurView().Resize(screen.Size())
+ CurView().matches = Match(CurView())
+ }
+ }
+ } else {
+ screen.Fini()
+ os.Exit(0)
+ }
+ }
+ return false
+}
+
+func (v *View) AddTab() bool {
+ tab := NewTabFromView(NewView(NewBuffer([]byte{}, "")))
+ 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())
+ }
+ }
+ }
+ return true
+}
+
+func (v *View) PreviousTab() bool {
+ if curTab > 0 {
+ curTab--
+ }
+ return false
+}
+
+func (v *View) NextTab() bool {
+ if curTab < len(tabs)-1 {
+ curTab++
}
return false
}