-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow stacking the picker preview vertically #7783
Open
doy
wants to merge
1
commit into
helix-editor:master
Choose a base branch
from
doy:vertical-picker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+52
−20
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -56,7 +56,10 @@ use self::handlers::{DynamicQueryChange, DynamicQueryHandler, PreviewHighlightHa | |||
|
||||
pub const ID: &str = "picker"; | ||||
|
||||
pub const MIN_AREA_WIDTH_FOR_PREVIEW: u16 = 72; | ||||
pub const MIN_AREA_WIDTH_FOR_PREVIEW: u16 = 40; | ||||
pub const MIN_AREA_HEIGHT_FOR_PREVIEW: u16 = 9; | ||||
pub const MAX_AREA_WIDTH_FOR_PREVIEW: u16 = 80; | ||||
pub const MAX_AREA_HEIGHT_FOR_PREVIEW: u16 = 24; | ||||
/// Biggest file size to preview in bytes | ||||
pub const MAX_FILE_SIZE_FOR_PREVIEW: u64 = 10 * 1024 * 1024; | ||||
|
||||
|
@@ -934,28 +937,57 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> { | |||
|
||||
impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I, D> { | ||||
fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { | ||||
// +---------+ +---------+ | ||||
// |prompt | |preview | | ||||
// +---------+ | | | ||||
// |picker | | | | ||||
// | | | | | ||||
// +---------+ +---------+ | ||||
|
||||
let render_preview = | ||||
self.show_preview && self.file_fn.is_some() && area.width > MIN_AREA_WIDTH_FOR_PREVIEW; | ||||
|
||||
let picker_width = if render_preview { | ||||
area.width / 2 | ||||
let (show_preview, vertical) = if area.width / 2 >= MIN_AREA_WIDTH_FOR_PREVIEW | ||||
&& area.height / 2 >= MIN_AREA_HEIGHT_FOR_PREVIEW | ||||
{ | ||||
if area.width < area.height { | ||||
(self.show_preview, true) | ||||
} else { | ||||
(self.show_preview, false) | ||||
} | ||||
} else if area.width >= MIN_AREA_WIDTH_FOR_PREVIEW | ||||
&& area.height / 2 >= MIN_AREA_HEIGHT_FOR_PREVIEW | ||||
{ | ||||
(self.show_preview, true) | ||||
} else if area.width / 2 >= MIN_AREA_WIDTH_FOR_PREVIEW | ||||
&& area.height >= MIN_AREA_HEIGHT_FOR_PREVIEW | ||||
{ | ||||
(self.show_preview, false) | ||||
} else { | ||||
area.width | ||||
(false, false) | ||||
}; | ||||
|
||||
let picker_area = area.with_width(picker_width); | ||||
self.render_picker(picker_area, surface, cx); | ||||
|
||||
if render_preview { | ||||
let preview_area = area.clip_left(picker_width); | ||||
self.render_preview(preview_area, surface, cx); | ||||
if show_preview && self.file_fn.is_some() { | ||||
if vertical { | ||||
// +---------------------+ | ||||
// |prompt | | ||||
// +---------------------+ | ||||
// |picker | | ||||
// | | | ||||
// +---------------------+ | ||||
// |preview | | ||||
// | | | ||||
// +---------------------+ | ||||
let preview_height = (area.height / 2).min(MAX_AREA_HEIGHT_FOR_PREVIEW); | ||||
let picker_height = area.height - preview_height; | ||||
|
||||
self.render_picker(area.with_height(picker_height), surface, cx); | ||||
self.render_preview(area.clip_top(picker_height), surface, cx); | ||||
} else { | ||||
// +---------+ +---------+ | ||||
// |prompt | |preview | | ||||
// +---------+ | | | ||||
// |picker | | | | ||||
// | | | | | ||||
// +---------+ +---------+ | ||||
let preview_width = (area.width / 2).min(MAX_AREA_WIDTH_FOR_PREVIEW); | ||||
let picker_width = area.width - preview_width; | ||||
|
||||
self.render_picker(area.with_width(picker_width), surface, cx); | ||||
self.render_preview(area.clip_left(picker_width), surface, cx); | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
} else { | ||||
self.render_picker(area, surface, cx); | ||||
} | ||||
} | ||||
|
||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9 seems a little low, I don't think we should not below 15 here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one of the main goals here is to have it able to show the preview in an 80x24 terminal. would it be better to drop the min width down to 36? (it's worth noting that the interpretation of these constants is different in the pr than previously - the existing code tests against the full width/height, but in this pr it is testing against the width that would be used by just the preview)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see I don't have time to test this out at the moment and din\t look at the new code in detail zet so I thaught it had the same meaning as before. I think the old bound was fine so if the definition just changed then its probably ok, I will take a look at that one I have more time.
I just meanr rhar 9 rows for picker and preview would have been a little low (that would have been like 1 or two matches shown at most)