Skip to content

Commit 36c0068

Browse files
vipexvJosephTLyons
andauthored
pane: Ignore max tabs on terminal pane (#40740)
Closes #39901 I'm unsure as to which direction the team wants to go with this, but this is the behavior of VSCode which is what this feature is based off so i'm going with this. Changes: 1. Introduced a new argument to the `new` method on the Pane called `ignore_max_tabs` that forces the `max_tabs` to None if it's true. 2. Added a new test `test_bypass_max_tabs_limit`. Release Notes: - Fixed: `max_tabs` Setting affecting the terminal pane. --------- Co-authored-by: Joseph T. Lyons <[email protected]>
1 parent a2c4281 commit 36c0068

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

crates/debugger_ui/src/session/running.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ pub(crate) fn new_debugger_pane(
386386
Default::default(),
387387
None,
388388
NoAction.boxed_clone(),
389+
true,
389390
window,
390391
cx,
391392
);

crates/terminal_view/src/terminal_panel.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ pub fn new_terminal_pane(
11031103
Default::default(),
11041104
None,
11051105
NewTerminal.boxed_clone(),
1106+
false,
11061107
window,
11071108
cx,
11081109
);
@@ -1752,6 +1753,8 @@ impl Render for InlineAssistTabBarButton {
17521753

17531754
#[cfg(test)]
17541755
mod tests {
1756+
use std::num::NonZero;
1757+
17551758
use super::*;
17561759
use gpui::{TestAppContext, UpdateGlobal as _};
17571760
use pretty_assertions::assert_eq;
@@ -1808,6 +1811,46 @@ mod tests {
18081811
.unwrap();
18091812
}
18101813

1814+
#[gpui::test]
1815+
async fn test_bypass_max_tabs_limit(cx: &mut TestAppContext) {
1816+
init_test(cx);
1817+
1818+
let fs = FakeFs::new(cx.executor());
1819+
let project = Project::test(fs, [], cx).await;
1820+
let workspace = cx.add_window(|window, cx| Workspace::test_new(project, window, cx));
1821+
1822+
let (window_handle, terminal_panel) = workspace
1823+
.update(cx, |workspace, window, cx| {
1824+
let window_handle = window.window_handle();
1825+
let terminal_panel = cx.new(|cx| TerminalPanel::new(workspace, window, cx));
1826+
(window_handle, terminal_panel)
1827+
})
1828+
.unwrap();
1829+
1830+
set_max_tabs(cx, Some(3));
1831+
1832+
for _ in 0..5 {
1833+
let task = window_handle
1834+
.update(cx, |_, window, cx| {
1835+
terminal_panel.update(cx, |panel, cx| {
1836+
panel.add_terminal_shell(None, RevealStrategy::Always, window, cx)
1837+
})
1838+
})
1839+
.unwrap();
1840+
task.await.unwrap();
1841+
}
1842+
1843+
cx.run_until_parked();
1844+
1845+
let item_count =
1846+
terminal_panel.read_with(cx, |panel, cx| panel.active_pane.read(cx).items_len());
1847+
1848+
assert_eq!(
1849+
item_count, 5,
1850+
"Terminal panel should bypass max_tabs limit and have all 5 terminals"
1851+
);
1852+
}
1853+
18111854
// A complex Unix command won't be properly parsed by the Windows terminal hence omit the test there.
18121855
#[cfg(unix)]
18131856
#[gpui::test]
@@ -1922,6 +1965,14 @@ mod tests {
19221965
.unwrap();
19231966
}
19241967

1968+
fn set_max_tabs(cx: &mut TestAppContext, value: Option<usize>) {
1969+
cx.update_global(|store: &mut SettingsStore, cx| {
1970+
store.update_user_settings(cx, |settings| {
1971+
settings.workspace.max_tabs = value.map(|v| NonZero::new(v).unwrap())
1972+
});
1973+
});
1974+
}
1975+
19251976
pub fn init_test(cx: &mut TestAppContext) {
19261977
cx.update(|cx| {
19271978
let store = SettingsStore::test(cx);

crates/workspace/src/pane.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ pub struct Pane {
376376
render_tab_bar: Rc<dyn Fn(&mut Pane, &mut Window, &mut Context<Pane>) -> AnyElement>,
377377
show_tab_bar_buttons: bool,
378378
max_tabs: Option<NonZeroUsize>,
379+
use_max_tabs: bool,
379380
_subscriptions: Vec<Subscription>,
380381
tab_bar_scroll_handle: ScrollHandle,
381382
/// This is set to true if a user scroll has occurred more recently than a system scroll
@@ -473,10 +474,16 @@ impl Pane {
473474
next_timestamp: Arc<AtomicUsize>,
474475
can_drop_predicate: Option<Arc<dyn Fn(&dyn Any, &mut Window, &mut App) -> bool + 'static>>,
475476
double_click_dispatch_action: Box<dyn Action>,
477+
use_max_tabs: bool,
476478
window: &mut Window,
477479
cx: &mut Context<Self>,
478480
) -> Self {
479481
let focus_handle = cx.focus_handle();
482+
let max_tabs = if use_max_tabs {
483+
WorkspaceSettings::get_global(cx).max_tabs
484+
} else {
485+
None
486+
};
480487

481488
let subscriptions = vec![
482489
cx.on_focus(&focus_handle, window, Pane::focus_in),
@@ -498,7 +505,8 @@ impl Pane {
498505
zoomed: false,
499506
active_item_index: 0,
500507
preview_item_id: None,
501-
max_tabs: WorkspaceSettings::get_global(cx).max_tabs,
508+
max_tabs,
509+
use_max_tabs,
502510
last_focus_handle_by_item: Default::default(),
503511
nav_history: NavHistory(Arc::new(Mutex::new(NavHistoryState {
504512
mode: NavigationMode::Normal,
@@ -706,7 +714,7 @@ impl Pane {
706714
self.preview_item_id = None;
707715
}
708716

709-
if new_max_tabs != self.max_tabs {
717+
if self.use_max_tabs && new_max_tabs != self.max_tabs {
710718
self.max_tabs = new_max_tabs;
711719
self.close_items_on_settings_change(window, cx);
712720
}

crates/workspace/src/workspace.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ impl Workspace {
13311331
pane_history_timestamp.clone(),
13321332
None,
13331333
NewFile.boxed_clone(),
1334+
true,
13341335
window,
13351336
cx,
13361337
);
@@ -3235,6 +3236,7 @@ impl Workspace {
32353236
self.pane_history_timestamp.clone(),
32363237
None,
32373238
NewFile.boxed_clone(),
3239+
true,
32383240
window,
32393241
cx,
32403242
);

0 commit comments

Comments
 (0)