]> git.lizzy.rs Git - micro.git/commitdiff
Fix yn callback bug
authorZachary Yedidia <zyedidia@gmail.com>
Tue, 15 Jan 2019 05:24:53 +0000 (00:24 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Wed, 25 Dec 2019 22:05:10 +0000 (17:05 -0500)
cmd/micro/action/actions.go
cmd/micro/action/command.go
cmd/micro/action/infohandler.go
cmd/micro/action/termhandler.go
cmd/micro/buffer/buffer.go
cmd/micro/info/infobuffer.go

index a4e6e2501a070b9a6c079c1899dbe264228ab40a..e41ad051f968158aa100c889707dec8e3df01587 100644 (file)
@@ -351,11 +351,6 @@ func (h *BufHandler) SelectToEnd() bool {
 
 // InsertNewline inserts a newline plus possible some whitespace if autoindent is on
 func (h *BufHandler) InsertNewline() bool {
-       if h.Buf.Type == buffer.BTInfo {
-               InfoBar.DonePrompt(false)
-               return false
-       }
-
        // Insert a newline
        if h.Cursor.HasSelection() {
                h.Cursor.DeleteSelection()
index e72c46871972646ce43ffd9b560c8454d69d46a2..ef4762df95b4d9be9d2d01d90db27c40f3493d28 100644 (file)
@@ -559,9 +559,7 @@ func (h *BufHandler) TermCmd(args []string) {
                args = []string{sh}
        }
 
-       term := func(i int) {
-               // If there is only one open file we make a new tab instead of overwriting it
-               newtab := len(MainTab().Panes) == 1 && len(Tabs.List) == 1
+       term := func(i int, newtab bool) {
 
                t := new(shell.Terminal)
                t.Start(args, false, true)
@@ -580,19 +578,27 @@ func (h *BufHandler) TermCmd(args []string) {
                MainTab().SetActive(i)
        }
 
+       // If there is only one open file we make a new tab instead of overwriting it
+       newtab := len(MainTab().Panes) == 1 && len(Tabs.List) == 1
+
+       if newtab {
+               term(0, true)
+               return
+       }
+
        for i, p := range ps {
                if p.ID() == h.ID() {
                        if h.Buf.Modified() {
                                InfoBar.YNPrompt("Save changes to "+h.Buf.GetName()+" before closing? (y,n,esc)", func(yes, canceled bool) {
                                        if !canceled && !yes {
-                                               term(i)
+                                               term(i, false)
                                        } else if !canceled && yes {
                                                h.Save()
-                                               term(i)
+                                               term(i, false)
                                        }
                                })
                        } else {
-                               term(i)
+                               term(i, false)
                        }
                }
        }
index 337393bfc28114d338859710d001b4b35f722da4..2840e22c1702a74b4061aa36fbe19708222241a4 100644 (file)
@@ -33,18 +33,19 @@ func (h *InfoHandler) HandleEvent(event tcell.Event) {
                }
 
                done := h.DoKeyEvent(ke)
-               if !done && e.Key() == tcell.KeyRune {
+               if e.Key() == tcell.KeyRune && h.HasYN {
                        if e.Rune() == 'y' && h.HasYN {
                                h.YNResp = true
                                h.DonePrompt(false)
                        } else if e.Rune() == 'n' && h.HasYN {
                                h.YNResp = false
                                h.DonePrompt(false)
-                       } else if !h.HasYN {
-                               h.DoRuneInsert(e.Rune())
-                               done = true
                        }
                }
+               if e.Key() == tcell.KeyRune && !done && !h.HasYN {
+                       h.DoRuneInsert(e.Rune())
+                       done = true
+               }
                if done && h.HasPrompt && !h.HasYN {
                        resp := strings.TrimSpace(string(h.LineBytes(0)))
                        hist := h.History[h.PromptType]
index 0d19c551c35b9f94c4a61e34a17f3fc0dd77c490..388377ab3120690f803430e3710eae33c4bd3d1a 100644 (file)
@@ -23,6 +23,7 @@ func NewTermHandler(x, y, w, h int, t *shell.Terminal, id uint64) *TermHandler {
        th := new(TermHandler)
        th.Terminal = t
        th.id = id
+       th.mouseReleased = true
        th.Window = display.NewTermWindow(x, y, w, h, t)
        return th
 }
@@ -81,7 +82,7 @@ func (t *TermHandler) HandleEvent(event tcell.Event) {
                x, y := e.Position()
                v := t.GetView()
                x -= v.X
-               y += v.Y
+               y -= v.Y
 
                if e.Buttons() == tcell.Button1 {
                        if !t.mouseReleased {
index e9faf019445c5e9ef91fd5fe4228ee96f1628571..e87e5e498cfc0e3e999775c5a7fb856afdb1ecbc 100644 (file)
@@ -427,11 +427,13 @@ func (b *Buffer) IndentString(tabsize int) []byte {
 // SetCursors resets this buffer's cursors to a new list
 func (b *Buffer) SetCursors(c []*Cursor) {
        b.cursors = c
+       b.EventHandler.cursors = b.cursors
 }
 
 // AddCursor adds a new cursor to the list
 func (b *Buffer) AddCursor(c *Cursor) {
        b.cursors = append(b.cursors, c)
+       b.EventHandler.cursors = b.cursors
        b.UpdateCursors()
 }
 
@@ -486,6 +488,7 @@ func (b *Buffer) MergeCursors() {
        if b.curCursor >= len(b.cursors) {
                b.curCursor = len(b.cursors) - 1
        }
+       b.EventHandler.cursors = b.cursors
 }
 
 // UpdateCursors updates all the cursors indicies
index 58c8e428c65a6af7c2dbfda813b20b3ac9f56626..b22c8a5286c0c7a1cfa026813d14749900ce9f63 100644 (file)
@@ -133,25 +133,30 @@ func (i *InfoBuf) DonePrompt(canceled bool) {
        i.HasPrompt = false
        i.HasYN = false
        i.HasGutter = false
-       if i.PromptCallback != nil && !hadYN {
-               if canceled {
-                       i.PromptCallback("", true)
-                       h := i.History[i.PromptType]
-                       i.History[i.PromptType] = h[:len(h)-1]
-               } else {
-                       resp := strings.TrimSpace(string(i.LineBytes(0)))
-                       i.PromptCallback(resp, false)
-                       h := i.History[i.PromptType]
-                       h[len(h)-1] = resp
+       if !hadYN {
+               if i.PromptCallback != nil {
+                       if canceled {
+                               i.PromptCallback("", true)
+                               h := i.History[i.PromptType]
+                               i.History[i.PromptType] = h[:len(h)-1]
+                       } else {
+                               resp := strings.TrimSpace(string(i.LineBytes(0)))
+                               i.PromptCallback(resp, false)
+                               h := i.History[i.PromptType]
+                               h[len(h)-1] = resp
+                       }
+                       i.PromptCallback = nil
+                       i.EventCallback = nil
                }
+               if i.EventCallback != nil {
+                       i.EventCallback = nil
+               }
+               i.Replace(i.Start(), i.End(), []byte{})
        }
        if i.YNCallback != nil && hadYN {
                i.YNCallback(i.YNResp, canceled)
+               i.YNCallback = nil
        }
-       i.PromptCallback = nil
-       i.EventCallback = nil
-       i.YNCallback = nil
-       i.Replace(i.Start(), i.End(), []byte{})
 }
 
 // Reset resets the infobuffer's msg and info