]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/bindings.go
Fix replace cursor relocation
[micro.git] / cmd / micro / bindings.go
index 9b1af052e99a2c7d6b2eb1b4eb65467bd003b789..56a9503a9de4c0e5c5450c984976ab7fc7347c68 100644 (file)
@@ -73,8 +73,9 @@ var bindingActions = map[string]func(*View) bool{
        "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{
@@ -382,6 +383,9 @@ func DefaultBindings() map[string]string {
                "CtrlD":          "DuplicateLine",
                "CtrlV":          "Paste",
                "CtrlA":          "SelectAll",
+               "CtrlT":          "AddTab",
+               "CtrlRightSq":    "PreviousTab",
+               "CtrlBackslash":  "NextTab",
                "Home":           "Start",
                "End":            "End",
                "PageUp":         "CursorPageUp",
@@ -727,7 +731,7 @@ func (v *View) Save() bool {
        }
        // 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
@@ -748,6 +752,7 @@ func (v *View) Save() bool {
                        }
                        messenger.Reset()
                        messenger.Clear()
+                       messenger.Message("Saved " + v.Buf.Path)
                } else {
                        messenger.Error(err.Error())
                }
@@ -902,7 +907,7 @@ func (v *View) SelectAll() bool {
 // 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
                }
@@ -921,12 +926,6 @@ func (v *View) OpenFile() bool {
        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
@@ -1020,7 +1019,7 @@ func (v *View) ToggleRuler() bool {
 // 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
        }
@@ -1063,7 +1062,7 @@ func (v *View) ToggleHelp() bool {
 
 // 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)
@@ -1073,7 +1072,7 @@ func (v *View) ShellMode() bool {
 
 // 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)
        }
@@ -1089,16 +1088,20 @@ func (v *View) Quit() bool {
                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 {
@@ -1109,18 +1112,33 @@ func (v *View) Quit() bool {
        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