Add width setting for the file finder (#18682)
This PR adds the ability to adjust the width of the file finder popup. I found when searching my projects the default width was not always wide enough and there was no option to change it. It allows values `small`, `medium` (default), `large`, `xlarge`, and `full` Release Notes: - Added a setting to adjust the width of the file finder modal Example Setting: ```json "file_finder": { "modal_width": "medium" }, ``` Screenshots can be found in the comments below.
This commit is contained in:
parent
2d3476530e
commit
31566cb5a0
4 changed files with 78 additions and 3 deletions
|
@ -14,7 +14,7 @@ use file_finder_settings::FileFinderSettings;
|
|||
use file_icons::FileIcons;
|
||||
use fuzzy::{CharBag, PathMatch, PathMatchCandidate};
|
||||
use gpui::{
|
||||
actions, rems, Action, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle,
|
||||
actions, Action, AnyElement, AppContext, DismissEvent, EventEmitter, FocusHandle,
|
||||
FocusableView, KeyContext, Model, Modifiers, ModifiersChangedEvent, ParentElement, Render,
|
||||
Styled, Task, View, ViewContext, VisualContext, WeakView,
|
||||
};
|
||||
|
@ -257,9 +257,14 @@ impl FocusableView for FileFinder {
|
|||
impl Render for FileFinder {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let key_context = self.picker.read(cx).delegate.key_context(cx);
|
||||
|
||||
let window_max_width: Pixels = cx.viewport_size().width;
|
||||
let modal_choice = FileFinderSettings::get_global(cx).modal_width;
|
||||
let width = modal_choice.calc_width(window_max_width);
|
||||
|
||||
v_flex()
|
||||
.key_context(key_context)
|
||||
.w(rems(34.))
|
||||
.w(width)
|
||||
.on_modifiers_changed(cx.listener(Self::handle_modifiers_changed))
|
||||
.on_action(cx.listener(Self::handle_select_prev))
|
||||
.on_action(cx.listener(Self::handle_open_menu))
|
||||
|
|
|
@ -2,10 +2,13 @@ use anyhow::Result;
|
|||
use schemars::JsonSchema;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsSources};
|
||||
use std::cmp;
|
||||
use ui::Pixels;
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||
pub struct FileFinderSettings {
|
||||
pub file_icons: bool,
|
||||
pub modal_width: FileFinderWidth,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
|
||||
|
@ -14,6 +17,10 @@ pub struct FileFinderSettingsContent {
|
|||
///
|
||||
/// Default: true
|
||||
pub file_icons: Option<bool>,
|
||||
/// The width of the file finder modal.
|
||||
///
|
||||
/// Default: "medium"
|
||||
pub modal_width: Option<FileFinderWidth>,
|
||||
}
|
||||
|
||||
impl Settings for FileFinderSettings {
|
||||
|
@ -25,3 +32,44 @@ impl Settings for FileFinderSettings {
|
|||
sources.json_merge()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum FileFinderWidth {
|
||||
Small,
|
||||
#[default]
|
||||
Medium,
|
||||
Large,
|
||||
XLarge,
|
||||
Full,
|
||||
}
|
||||
|
||||
impl FileFinderWidth {
|
||||
const MIN_MODAL_WIDTH_PX: f32 = 384.;
|
||||
|
||||
pub fn padding_px(&self) -> Pixels {
|
||||
let padding_val = match self {
|
||||
FileFinderWidth::Small => 1280.,
|
||||
FileFinderWidth::Medium => 1024.,
|
||||
FileFinderWidth::Large => 768.,
|
||||
FileFinderWidth::XLarge => 512.,
|
||||
FileFinderWidth::Full => 0.,
|
||||
};
|
||||
|
||||
Pixels(padding_val)
|
||||
}
|
||||
|
||||
pub fn calc_width(&self, window_width: Pixels) -> Pixels {
|
||||
if self == &FileFinderWidth::Full {
|
||||
return window_width;
|
||||
}
|
||||
|
||||
let min_modal_width_px = Pixels(FileFinderWidth::MIN_MODAL_WIDTH_PX);
|
||||
|
||||
let padding_px = self.padding_px();
|
||||
let width_val = window_width - padding_px;
|
||||
let finder_width = cmp::max(min_modal_width_px, width_val);
|
||||
|
||||
finder_width
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue