BlueGit

ict rusty-teams

fix(format): table edits only in More options inside a table

- hide disabled Insert/Delete column or row items, drop empty groups
- no More button when nothing is left

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-04 · 3 weeks ago

Hash
44662f54c1d518eb542334c26fc6e33691e74c83
Parent
b5c0f7e6
1 file changed +41 −4
crates/app/src/views/format_toolbar.rs +41 −4
@@ -263,6 +263,13 @@ impl FormatButton {
263 263 tooltip.split(" (").next().unwrap_or(tooltip)
264 264 }
265 265
266 fn edits_table(self) -> bool {
267 matches!(
268 self,
269 FormatButton::TableInsertLine | FormatButton::TableRemoveLine
270 )
271 }
272
266 273 /// Opens a picker or menu below itself instead of acting at once.
267 274 pub fn opens_popup(self) -> bool {
268 275 matches!(
@@ -523,7 +530,7 @@ pub fn render_format_bar(
523 530 overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,
524 531 ) -> Div {
525 532 let row = groups_row(&fit.visible, state, on_press.clone(), overlay);
526 if fit.overflow.is_empty() {
533 if menu_groups(&fit.overflow, state).is_empty() {
527 534 return row;
528 535 }
529 536 row.child(button(
@@ -542,7 +549,7 @@ pub fn render_overflow_menu(
542 549 overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,
543 550 ) -> Div {
544 551 let mut menu = v_flex().w(px(MENU_WIDTH)).py(px(MENU_PADDING));
545 for (index, group) in groups.iter().enumerate() {
552 for (index, group) in menu_groups(groups, state).iter().enumerate() {
546 553 if index > 0 {
547 554 menu = menu.child(
548 555 div()
@@ -564,6 +571,23 @@ pub fn render_overflow_menu(
564 571 menu
565 572 }
566 573
574 fn menu_groups(
575 groups: &[Vec<FormatButton>],
576 state: &dyn Fn(FormatButton) -> ButtonState,
577 ) -> Vec<Vec<FormatButton>> {
578 groups
579 .iter()
580 .map(|group| {
581 group
582 .iter()
583 .copied()
584 .filter(|format| !format.edits_table() || state(*format).enabled)
585 .collect::<Vec<_>>()
586 })
587 .filter(|group| !group.is_empty())
588 .collect()
589 }
590
567 591 fn menu_row(
568 592 format: FormatButton,
569 593 state: ButtonState,
@@ -730,8 +754,9 @@ mod tests {
730 754 use gpui_kit::px;
731 755
732 756 use super::{
733 ARROW_MARGIN, BAR_GROUPS, BUTTON, FormatButton, SELECTION_GROUPS, bar_width, fit_groups,
734 groups_width, place, toggle_symbol, toggle_tooltip,
757 ARROW_MARGIN, BAR_GROUPS, BUTTON, ButtonState, FormatButton, FormatState,
758 SELECTION_GROUPS, bar_width, fit_groups, groups_width, menu_groups, place, toggle_symbol,
759 toggle_tooltip,
735 760 };
736 761
737 762
@@ -847,6 +872,18 @@ mod tests {
847 872 assert_eq!(fit.overflow[0], vec![FormatButton::Subscript]);
848 873 }
849 874
875 #[test]
876 fn outside_a_table_the_menu_drops_the_table_edits_and_their_group() {
877 let fit = fit_groups(groups_width(&BAR_GROUPS) - 1., &BAR_GROUPS);
878 let outside = |format: FormatButton| match format {
879 FormatButton::TableInsertLine | FormatButton::TableRemoveLine => ButtonState::disabled(),
880 _ => ButtonState::enabled(FormatState::Off),
881 };
882 assert!(menu_groups(&fit.overflow, &outside).is_empty());
883 let inside = |_| ButtonState::enabled(FormatState::Off);
884 assert_eq!(menu_groups(&fit.overflow, &inside), fit.overflow);
885 }
886
850 887 #[test]
851 888 fn a_tiny_bar_keeps_only_more_options() {
852 889 let fit = fit_groups(BUTTON, &BAR_GROUPS);
@@ -263,6 +263,13 @@ impl FormatButton {
263 tooltip.split(" (").next().unwrap_or(tooltip)
263 tooltip.split(" (").next().unwrap_or(tooltip)
264 }
264 }
265
265
266 fn edits_table(self) -> bool {
267 matches!(
268 self,
269 FormatButton::TableInsertLine | FormatButton::TableRemoveLine
270 )
271 }
272
266 /// Opens a picker or menu below itself instead of acting at once.
273 /// Opens a picker or menu below itself instead of acting at once.
267 pub fn opens_popup(self) -> bool {
274 pub fn opens_popup(self) -> bool {
268 matches!(
275 matches!(
@@ -523,7 +530,7 @@ pub fn render_format_bar(
523 overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,
530 overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,
524) -> Div {
531) -> Div {
525 let row = groups_row(&fit.visible, state, on_press.clone(), overlay);
532 let row = groups_row(&fit.visible, state, on_press.clone(), overlay);
526 if fit.overflow.is_empty() {
533 if menu_groups(&fit.overflow, state).is_empty() {
527 return row;
534 return row;
528 }
535 }
529 row.child(button(
536 row.child(button(
@@ -542,7 +549,7 @@ pub fn render_overflow_menu(
542 overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,
549 overlay: &mut dyn FnMut(FormatButton) -> Option<AnyElement>,
543) -> Div {
550) -> Div {
544 let mut menu = v_flex().w(px(MENU_WIDTH)).py(px(MENU_PADDING));
551 let mut menu = v_flex().w(px(MENU_WIDTH)).py(px(MENU_PADDING));
545 for (index, group) in groups.iter().enumerate() {
552 for (index, group) in menu_groups(groups, state).iter().enumerate() {
546 if index > 0 {
553 if index > 0 {
547 menu = menu.child(
554 menu = menu.child(
548 div()
555 div()
@@ -564,6 +571,23 @@ pub fn render_overflow_menu(
564 menu
571 menu
565}
572}
566
573
574fn menu_groups(
575 groups: &[Vec<FormatButton>],
576 state: &dyn Fn(FormatButton) -> ButtonState,
577) -> Vec<Vec<FormatButton>> {
578 groups
579 .iter()
580 .map(|group| {
581 group
582 .iter()
583 .copied()
584 .filter(|format| !format.edits_table() || state(*format).enabled)
585 .collect::<Vec<_>>()
586 })
587 .filter(|group| !group.is_empty())
588 .collect()
589}
590
567fn menu_row(
591fn menu_row(
568 format: FormatButton,
592 format: FormatButton,
569 state: ButtonState,
593 state: ButtonState,
@@ -730,8 +754,9 @@ mod tests {
730 use gpui_kit::px;
754 use gpui_kit::px;
731
755
732 use super::{
756 use super::{
733 ARROW_MARGIN, BAR_GROUPS, BUTTON, FormatButton, SELECTION_GROUPS, bar_width, fit_groups,
757 ARROW_MARGIN, BAR_GROUPS, BUTTON, ButtonState, FormatButton, FormatState,
734 groups_width, place, toggle_symbol, toggle_tooltip,
758 SELECTION_GROUPS, bar_width, fit_groups, groups_width, menu_groups, place, toggle_symbol,
759 toggle_tooltip,
735 };
760 };
736
761
737
762
@@ -847,6 +872,18 @@ mod tests {
847 assert_eq!(fit.overflow[0], vec![FormatButton::Subscript]);
872 assert_eq!(fit.overflow[0], vec![FormatButton::Subscript]);
848 }
873 }
849
874
875 #[test]
876 fn outside_a_table_the_menu_drops_the_table_edits_and_their_group() {
877 let fit = fit_groups(groups_width(&BAR_GROUPS) - 1., &BAR_GROUPS);
878 let outside = |format: FormatButton| match format {
879 FormatButton::TableInsertLine | FormatButton::TableRemoveLine => ButtonState::disabled(),
880 _ => ButtonState::enabled(FormatState::Off),
881 };
882 assert!(menu_groups(&fit.overflow, &outside).is_empty());
883 let inside = |_| ButtonState::enabled(FormatState::Off);
884 assert_eq!(menu_groups(&fit.overflow, &inside), fit.overflow);
885 }
886
850 #[test]
887 #[test]
851 fn a_tiny_bar_keeps_only_more_options() {
888 fn a_tiny_bar_keeps_only_more_options() {
852 let fit = fit_groups(BUTTON, &BAR_GROUPS);
889 let fit = fit_groups(BUTTON, &BAR_GROUPS);