-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
implementing picker preview scrolling #4189
Closed
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e55a754
implementing picker preview scrolling
Manosmer 68f8716
fixed reset scroll on move_by, reorganized key_event matching
Manosmer 05d14b3
changed keybindings to alt+u alt+d
Manosmer 6f75057
better code design for preview management, fixed scrolling up on nonz…
Manosmer 3d08447
fixed preview scroll resets only on file change
Manosmer a0101d6
preview scrolls only if show_preview = true
Manosmer 12d4539
updated keybindings
Manosmer 77d7f37
rearrange the order of imports
Manosmer 377d131
merge upstream changes and resolving conflicts
Manosmer b28ac5f
fix lint test with "cargo fmt --all"
Manosmer 831575f
Merge branch 'master' into preview-scroll
Manosmer d2a5b28
Merge branch 'master' into preview-scroll
Manosmer dc054ec
added scrollbar for preview scrolling
Manosmer d0fde28
Merge branch 'master' into preview-scroll
Manosmer 2501166
cargo fmt
Manosmer 03e2970
fix: scroll reset on diagnostic picker
Manosmer 616c919
Merge branch 'master' into preview-scroll
Manosmer 23189b9
removed unnecessary log::info
Manosmer 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 |
---|---|---|
|
@@ -204,6 +204,8 @@ impl<T: Item + 'static> Component for FilePicker<T> { | |
let inner = inner.inner(&margin); | ||
block.render(preview_area, surface); | ||
|
||
let mut preview_scroll_offset = self.picker.preview_scroll_offset; | ||
|
||
if let Some((path, range)) = self.current_file(cx.editor) { | ||
let preview = self.get_preview(&path, cx.editor); | ||
let doc = match preview.document() { | ||
|
@@ -226,7 +228,8 @@ impl<T: Item + 'static> Component for FilePicker<T> { | |
}) | ||
.unwrap_or(0); | ||
|
||
let offset = Position::new(first_line, 0); | ||
preview_scroll_offset = preview_scroll_offset.min(doc.text().len_lines()); | ||
let offset = Position::new(first_line + preview_scroll_offset, 0); | ||
|
||
let highlights = | ||
EditorView::doc_syntax_highlights(doc, offset, area.height, &cx.editor.theme); | ||
|
@@ -258,6 +261,9 @@ impl<T: Item + 'static> Component for FilePicker<T> { | |
); | ||
} | ||
} | ||
|
||
// Limits the preview scroll between 0 and doc's len_lines() in case it moves past the line number | ||
self.picker.preview_scroll_offset = preview_scroll_offset; | ||
} | ||
|
||
fn handle_event(&mut self, event: &Event, ctx: &mut Context) -> EventResult { | ||
|
@@ -297,6 +303,7 @@ pub struct Picker<T: Item> { | |
// pattern: String, | ||
prompt: Prompt, | ||
previous_pattern: String, | ||
preview_scroll_offset: usize, | ||
/// Whether to truncate the start (default true) | ||
pub truncate_start: bool, | ||
/// Whether to show the preview panel (default true) | ||
|
@@ -327,6 +334,7 @@ impl<T: Item> Picker<T> { | |
cursor: 0, | ||
prompt, | ||
previous_pattern: String::new(), | ||
preview_scroll_offset: 0, | ||
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. Offset should reset on 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. You are absolutely right, my bad |
||
truncate_start: true, | ||
show_preview: true, | ||
callback_fn: Box::new(callback_fn), | ||
|
@@ -434,6 +442,18 @@ impl<T: Item> Picker<T> { | |
} | ||
} | ||
|
||
// Move the picker file preview by a number of lines, either down (`Forward`) or up (`Backward`) | ||
pub fn move_preview_by(&mut self, amount: usize, direction: Direction) { | ||
self.preview_scroll_offset = match direction { | ||
Direction::Forward => { | ||
self.preview_scroll_offset.saturating_add(amount) | ||
}, | ||
Direction::Backward => { | ||
self.preview_scroll_offset.saturating_sub(amount) | ||
}, | ||
}; | ||
} | ||
|
||
/// Move the cursor down by exactly one page. After the last page comes the first page. | ||
pub fn page_up(&mut self) { | ||
self.move_by(self.completion_height as usize, Direction::Backward); | ||
|
@@ -509,6 +529,12 @@ impl<T: Item + 'static> Component for Picker<T> { | |
shift!(Tab) | key!(Up) | ctrl!('p') => { | ||
self.move_by(1, Direction::Backward); | ||
} | ||
shift!(Up) => { | ||
self.move_preview_by(cx.editor.config().scroll_lines.unsigned_abs(), Direction::Backward); | ||
} | ||
shift!(Down) => { | ||
self.move_preview_by(cx.editor.config().scroll_lines.unsigned_abs(), Direction::Forward); | ||
} | ||
key!(Tab) | key!(Down) | ctrl!('n') => { | ||
self.move_by(1, Direction::Forward); | ||
} | ||
|
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.
Rather than in the render loop, shouldn't we do this in
move_preview_by
?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.
move_preview_by()
is implemented in Picker and I needed thelen_lines()
of the current file in order to limit the scroll. I could transfer that functionality to aFilePicker::move_preview_by()
function and handle the preview scroll events inFilePicker::handle_event()
, instead of doing all that in Picker