Skip to content
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

Add ActivateLastTab command #610

Merged
merged 1 commit into from
Apr 2, 2021
Merged

Add ActivateLastTab command #610

merged 1 commit into from
Apr 2, 2021

Conversation

alexgartrell
Copy link
Contributor

@alexgartrell alexgartrell commented Apr 1, 2021

This replicates last-window in tmux. To pull this off, I
deliberately store the last tab whenever I'm activating a new one or
spawning a new one. I had to do this explicitly rather than hooking
set_active, because we end up setting the active tab briefly for some
common operations like moving a tab.

@bew
Copy link
Contributor

bew commented Apr 1, 2021

I'd like to suggest ActivateLastTab, because Previous looks like to opposite of Next,which is not right.

@alexgartrell alexgartrell changed the title Add ActivatePreviousTab command Add ActivateLastTab command Apr 1, 2021
@alexgartrell
Copy link
Contributor Author

@bew great point. It should have occurred to me when I reminded myself of how tmux did it :)

Copy link
Owner

@wez wez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!
Some suggestions inline!


Activate the last active tab index. If there is none, it will do
nothing. If the tabs get moved around, it will move to the last
tab index rather than the last tab itself.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that the desired behavior, or just simple to implement behavior?
If desired, then I'd suggest adding a brief example of what that means if the user reorganizes.

However, I think it isn't too much extra complexity to switch to the prior tab using its tabid with the inline suggestions!

@@ -10,6 +10,7 @@ pub struct Window {
id: WindowId,
tabs: Vec<Rc<Tab>>,
active: usize,
last_active: Option<usize>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
last_active: Option<usize>,
last_active: Option<TabId>,

pub fn set_active(&mut self, idx: usize) {
assert!(idx < self.tabs.len());
self.invalidated = true;
self.last_active = Some(self.active);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.last_active = Some(self.active);
self.last_active = self.get_by_idx(self.active).map(|tab| tab.tab_id());

@@ -124,9 +126,15 @@ impl Window {
self.active
}

#[inline]
pub fn get_last_active_idx(&self) -> Option<usize> {
self.last_active
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.last_active
self.last_active.map(|tab_id| self.idx_by_id(tab_id))

@alexgartrell
Copy link
Contributor Author

The issue is that move_tab removes and reinserts, so set_active gets called multiple times. Plus if you activate the same tab twice, it'll be its own "last_active." I'll see if I can figure out a way to get the ideal behavior that's not overly gross though.

This replicates `last-window` in tmux. To pull this off, I
deliberately store the last tab whenever I'm activating a new one or
spawning a new one. I had to do this explicitly rather than hooking
set_active, because we end up setting the active tab briefly for some
common operations like moving a tab.
@wez wez merged commit ee4b4b5 into wez:main Apr 2, 2021
wez added a commit that referenced this pull request Apr 2, 2021
@wez
Copy link
Owner

wez commented Apr 2, 2021

Thanks for this! I tweaked it a little because it felt like I could easily forget to save the tab if I changed some code later, and I found a single omission in the Tab Navigator.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants