Fix yn callback bug

This commit is contained in:
Zachary Yedidia
2019-01-15 00:24:53 -05:00
parent 4a5b759f16
commit 538f0117bc
6 changed files with 41 additions and 30 deletions

View 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()

View 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)
}
}
}

View 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]

View 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 {