terminal: Add scrollbar (#23256)
Closes #4798 This PR implements a scrollbar for the terminal by turning `ScrollableHandle` into a trait, allowing us to implement a custom scroll handle, `TerminalScrollHandle`. It works by converting terminal lines into pixels that `ScrollableHandle` understands. When `ScrollableHandle` provides a changed offset (e.g., when you drag the scrollbar), we convert this pixel offset back into the number of lines to scroll and update the terminal content accordingly. While the current version works as expected, I believe the scrollbar's offset updates could potentially be turned into an event. This event could then be subscribed to in `TerminalView`, not needing to update the terminal's offset in the `render` method as it might have performance implications. Further ideas on this are welcome. Preview: https://github.com/user-attachments/assets/560f0aac-4544-4007-8f0b-8833386f608f Todo: - [x] Experiment with custom scrollbar responding to terminal mouse scroll - [x] Refactor existing scrollbar handle into a trait - [x] Update terminal to use the scrollbar trait instead of a custom scrollbar implementation - [x] Figure out how scrollbar events like mouse drag should notify the terminal to update its state - [x] Code clean up - [x] Scrollbar hide setting for terminal Release Notes: - Added scrollbar to the terminal
This commit is contained in:
parent
728a874b1e
commit
8c92da45a9
7 changed files with 412 additions and 91 deletions
|
@ -47,6 +47,40 @@ pub struct TerminalSettings {
|
|||
pub detect_venv: VenvSettings,
|
||||
pub max_scroll_history_lines: Option<usize>,
|
||||
pub toolbar: Toolbar,
|
||||
pub scrollbar: ScrollbarSettings,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
pub struct ScrollbarSettings {
|
||||
/// When to show the scrollbar in the terminal.
|
||||
///
|
||||
/// Default: inherits editor scrollbar settings
|
||||
pub show: Option<ShowScrollbar>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
pub struct ScrollbarSettingsContent {
|
||||
/// When to show the scrollbar in the terminal.
|
||||
///
|
||||
/// Default: inherits editor scrollbar settings
|
||||
pub show: Option<Option<ShowScrollbar>>,
|
||||
}
|
||||
|
||||
/// When to show the scrollbar in the terminal.
|
||||
///
|
||||
/// Default: auto
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ShowScrollbar {
|
||||
/// Show the scrollbar if there's important information or
|
||||
/// follow the system's configured behavior.
|
||||
Auto,
|
||||
/// Match the system's configured behavior.
|
||||
System,
|
||||
/// Always show the scrollbar.
|
||||
Always,
|
||||
/// Never show the scrollbar.
|
||||
Never,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||
|
@ -187,6 +221,8 @@ pub struct TerminalSettingsContent {
|
|||
pub max_scroll_history_lines: Option<usize>,
|
||||
/// Toolbar related settings
|
||||
pub toolbar: Option<ToolbarContent>,
|
||||
/// Scrollbar-related settings
|
||||
pub scrollbar: Option<ScrollbarSettingsContent>,
|
||||
}
|
||||
|
||||
impl settings::Settings for TerminalSettings {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue