-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Enhance Tab Bar #3795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Enhance Tab Bar #3795
Changes from 1 commit
4d3eb56
5718281
7ab907b
bbaf523
22ef9e9
b70df27
5d5326c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,55 @@ func (t *TabList) HandleEvent(event tcell.Event) { | |
|
|
||
| if i := t.LocFromVisual(buffer.Loc{mx, my}); i == -1 { | ||
| t.List[t.Active()].CurPane().AddTab() | ||
| } else { | ||
| anyModified := false | ||
| for _, p := range t.List[i].Panes { | ||
| if bp, ok := p.(*BufPane); ok { | ||
| if bp.Buf.Modified() { | ||
| anyModified = true | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| removeTab := func() { | ||
| panes := append([]Pane(nil), t.List[i].Panes...) | ||
| for _, p := range panes { | ||
| switch t := p.(type) { | ||
| case *BufPane: | ||
| t.ForceQuit() | ||
| case *RawPane: | ||
| t.Quit() | ||
| case *TermPane: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are closing the terminal pane without prompting the user. Whereas the user might run anything at all in this terminal, for example another instance of micro, with some unsaved changes, lol. I don't really like the fact that we support this embedded terminal functionality (which is doomed to never be on par with proper terminals), and I never used it myself, but apparently a lot of users do use it (as they often report bugs about this or that terminal functionality not working in it)... |
||
| t.Quit() | ||
| } | ||
| } | ||
|
Comment on lines
+205
to
+214
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is the best approach. Perhaps we could add |
||
| } | ||
|
|
||
| a := t.Active() | ||
| if anyModified { | ||
| t.SetActive(i) | ||
| InfoBar.YNPrompt("Discard unsaved changes? (y,n,esc)", func(yes, canceled bool) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user may middle-click the tab name accidentally and may not be aware that it closes the tab, so the user may not know why this prompt is being shown and which exact unsaved changes (in which buffers) are going to be discarded. So we'd better make it more clear, at least something like "Discard unsaved changed in this tab?"? |
||
| if !canceled { | ||
| if yes { | ||
| removeTab() | ||
| if i <= a { | ||
| a-- | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This causes a crash when closing a tab which is the first tab in the tab bar and which is currently active. And besides that, when closing an active tab, it is more intuitive to activate the tab after it, not the tab before it (except the case when there is no tab after it)? So, change |
||
| } | ||
| } | ||
| t.SetActive(a) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We return to the original active tab if the user pressed |
||
| } | ||
| }) | ||
| t.release = true | ||
| t.tbClick = false | ||
| t.tabDrag = false | ||
|
Comment on lines
+231
to
+233
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we call |
||
| } else { | ||
| removeTab() | ||
| if i <= a { | ||
| t.SetActive(a - 1) | ||
| } | ||
| } | ||
| return | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
| } | ||
| case tcell.WheelUp: | ||
| t.Scroll(4) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This produces false negatives if the same buffer is also opened in another pane in another tab (so closing this tab would not cause losing unsaved changes in this buffer).
The similar problem was addressed in #3559 + #3719 by adding
Shared()which checks if the buffer is opened in more than one pane. Unfortunately we cannot just reuseShared()here, since we need to distinguish the case when all the panes with this buffer are in the tab we are closing (then we need to prompt the user) and the case when at least one such pane is in a different tab (then we don't need to prompt the user).