"ShellMode": (*View).ShellMode,
"CommandMode": (*View).CommandMode,
"Quit": (*View).Quit,
- "LastView": (*View).LastView,
- "NextView": (*View).NextView,
+ "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 false
}
return false
}
-func (v *View) openInNewView(buf *Buffer) {
- views = append(views, NewView(buf))
- mainView++
- views[mainView].Num = mainView
-}
-
// Start moves the viewport to the start of the buffer
func (v *View) Start() bool {
v.Topline = 0
// 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()
- if len(views) > 1 {
- views = views[:v.Num+copy(views[v.Num:], views[v.Num+1:])]
- for i, v := range views {
- v.Num = i
- }
- if v.Num <= mainView {
- if !(v.Num == mainView && mainView == 0) {
- mainView--
+ 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 {
return false
}
-func (v *View) LastView() bool {
- if mainView > 0 {
- mainView--
+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) NextView() bool {
- if mainView < len(views)-1 {
- mainView++
+func (v *View) PreviousTab() bool {
+ if curTab > 0 {
+ curTab--
}
- return true
+ return false
+}
+
+func (v *View) NextTab() bool {
+ if curTab < len(tabs)-1 {
+ curTab++
+ }
+ return false
}
// None is no action