Resizable columns (#34794)
This PR adds resizable columns to the keymap editor and the ability to double-click on a resizable column to set a column back to its default size. The table uses a column's width to calculate what position it should be laid out at. So `column[i]` x position is calculated by the summation of `column[..i]`. When resizing `column[i]`, `column[i+1]`’s size is adjusted to keep all columns’ relative positions the same. If `column[i+1]` is at its minimum size, we keep seeking to the right to find a column with space left to take. An improvement to resizing behavior and double-clicking could be made by checking both column ranges `0..i-1` and `i+1..COLS`, since only one range of columns is checked for resize capacity. Release Notes: - N/A --------- Co-authored-by: Anthony <anthony@zed.dev> Co-authored-by: Remco Smits <djsmits12@gmail.com>
This commit is contained in:
parent
1f4c9b9427
commit
326fe05b33
5 changed files with 449 additions and 49 deletions
|
@ -13,8 +13,8 @@ use gpui::{
|
|||
Action, Animation, AnimationExt, AppContext as _, AsyncApp, Axis, ClickEvent, Context,
|
||||
DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, FontWeight, Global, IsZero,
|
||||
KeyContext, Keystroke, Modifiers, ModifiersChangedEvent, MouseButton, Point, ScrollStrategy,
|
||||
ScrollWheelEvent, StyledText, Subscription, Task, TextStyleRefinement, WeakEntity, actions,
|
||||
anchored, deferred, div,
|
||||
ScrollWheelEvent, Stateful, StyledText, Subscription, Task, TextStyleRefinement, WeakEntity,
|
||||
actions, anchored, deferred, div,
|
||||
};
|
||||
use language::{Language, LanguageConfig, ToOffset as _};
|
||||
use notifications::status_toast::{StatusToast, ToastIcon};
|
||||
|
@ -36,7 +36,7 @@ use workspace::{
|
|||
|
||||
use crate::{
|
||||
keybindings::persistence::KEYBINDING_EDITORS,
|
||||
ui_components::table::{Table, TableInteractionState},
|
||||
ui_components::table::{ColumnWidths, ResizeBehavior, Table, TableInteractionState},
|
||||
};
|
||||
|
||||
const NO_ACTION_ARGUMENTS_TEXT: SharedString = SharedString::new_static("<no arguments>");
|
||||
|
@ -284,6 +284,7 @@ struct KeymapEditor {
|
|||
context_menu: Option<(Entity<ContextMenu>, Point<Pixels>, Subscription)>,
|
||||
previous_edit: Option<PreviousEdit>,
|
||||
humanized_action_names: HumanizedActionNameCache,
|
||||
current_widths: Entity<ColumnWidths<6>>,
|
||||
show_hover_menus: bool,
|
||||
/// In order for the JSON LSP to run in the actions arguments editor, we
|
||||
/// require a backing file In order to avoid issues (primarily log spam)
|
||||
|
@ -400,6 +401,7 @@ impl KeymapEditor {
|
|||
show_hover_menus: true,
|
||||
action_args_temp_dir: None,
|
||||
action_args_temp_dir_worktree: None,
|
||||
current_widths: cx.new(|cx| ColumnWidths::new(cx)),
|
||||
};
|
||||
|
||||
this.on_keymap_changed(window, cx);
|
||||
|
@ -1433,6 +1435,18 @@ impl Render for KeymapEditor {
|
|||
DefiniteLength::Fraction(0.45),
|
||||
DefiniteLength::Fraction(0.08),
|
||||
])
|
||||
.resizable_columns(
|
||||
[
|
||||
ResizeBehavior::None,
|
||||
ResizeBehavior::Resizable,
|
||||
ResizeBehavior::Resizable,
|
||||
ResizeBehavior::Resizable,
|
||||
ResizeBehavior::Resizable,
|
||||
ResizeBehavior::Resizable, // this column doesn't matter
|
||||
],
|
||||
&self.current_widths,
|
||||
cx,
|
||||
)
|
||||
.header(["", "Action", "Arguments", "Keystrokes", "Context", "Source"])
|
||||
.uniform_list(
|
||||
"keymap-editor-table",
|
||||
|
@ -1594,15 +1608,14 @@ impl Render for KeymapEditor {
|
|||
.collect()
|
||||
}),
|
||||
)
|
||||
.map_row(
|
||||
cx.processor(|this, (row_index, row): (usize, Div), _window, cx| {
|
||||
.map_row(cx.processor(
|
||||
|this, (row_index, row): (usize, Stateful<Div>), _window, cx| {
|
||||
let is_conflict = this.has_conflict(row_index);
|
||||
let is_selected = this.selected_index == Some(row_index);
|
||||
|
||||
let row_id = row_group_id(row_index);
|
||||
|
||||
let row = row
|
||||
.id(row_id.clone())
|
||||
.on_any_mouse_down(cx.listener(
|
||||
move |this,
|
||||
mouse_down_event: &gpui::MouseDownEvent,
|
||||
|
@ -1636,11 +1649,12 @@ impl Render for KeymapEditor {
|
|||
})
|
||||
.when(is_selected, |row| {
|
||||
row.border_color(cx.theme().colors().panel_focused_border)
|
||||
.border_2()
|
||||
});
|
||||
|
||||
row.into_any_element()
|
||||
}),
|
||||
),
|
||||
},
|
||||
)),
|
||||
)
|
||||
.on_scroll_wheel(cx.listener(|this, event: &ScrollWheelEvent, _, cx| {
|
||||
// This ensures that the menu is not dismissed in cases where scroll events
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue