-
-
Notifications
You must be signed in to change notification settings - Fork 665
Add Go to line feature for the blame view #2262
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
Open
andrea-berling
wants to merge
27
commits into
gitui-org:master
Choose a base branch
from
andrea-berling:master
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.
Open
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5f29d2f
Add Go to line feature for the blame view
andrea-berling 9c526de
Fix make check errors
andrea-berling 55da5d9
Move goto_line_popup up the components list for proper event handling
andrea-berling 6bdab9d
Preserve BlameProcess in BlamePopup when jumping lines
andrea-berling 20ed1d2
Load blame from the last blame file instead of context
andrea-berling e1291f0
Add a BlameRequest enum for re-using blame data in Goto line
andrea-berling 4855ca6
Add input validation to Go to line popup
andrea-berling be182ae
Merge remote-tracking branch 'upstream/master'
andrea-berling 56732c2
Fix up negative indexing and add changelog entry
andrea-berling 3c8afa1
Merge remote-tracking branch 'upstream/master'
andrea-berling dc65a8d
Merge remote-tracking branch 'upstream/master'
andrea-berling bea05c2
Prevent GotoLine popup from opening before blame load and fix typo
andrea-berling df83ef0
Merge remote-tracking branch 'upstream/master'
andrea-berling 583eb7c
Add hints for the Go To Line popup
andrea-berling edb8e7b
Merge remote-tracking branch 'upstream/master'
andrea-berling 2287164
Merge branch 'master' into master
extrawurst 58cc56f
Merge remote-tracking branch 'upstream/master'
andrea-berling c4ad1aa
Merge remote-tracking branch 'origin/master'
andrea-berling 89f4fbb
Merge remote-tracking branch 'upstream/master'
andrea-berling e3fe1a8
Merge remote-tracking branch 'upstream/master'
andrea-berling fb2563d
fix(changelog): clean up some merge mixups in the changelog
andrea-berling ec4b1ef
refactor(go_to_line): rename "Go to line" into "Go to"
andrea-berling e95c394
refactor(popup): make goto line a non-stackable popup
andrea-berling f26b25e
refactor: remove unused Debug derives
andrea-berling aa80843
refactor: remove unnecessary pub specifiers
andrea-berling 092431f
Merge remote-tracking branch 'upstream/master'
andrea-berling 81e6515
refactor: simplify `GotoLinePopup`
andrea-berling 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| use crate::{ | ||
| app::Environment, | ||
| components::{ | ||
| visibility_blocking, CommandBlocking, CommandInfo, Component, | ||
| DrawableComponent, EventState, | ||
| }, | ||
| keys::{key_match, SharedKeyConfig}, | ||
| queue::{InternalEvent, Queue}, | ||
| strings, | ||
| ui::{self, style::SharedTheme}, | ||
| }; | ||
|
|
||
| use ratatui::{ | ||
| layout::Rect, | ||
| style::{Color, Style}, | ||
| widgets::{Block, Clear, Paragraph}, | ||
| Frame, | ||
| }; | ||
|
|
||
| use anyhow::Result; | ||
|
|
||
| use crossterm::event::{Event, KeyCode}; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct GotoLineContext { | ||
andrea-berling marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pub max_line: usize, | ||
| } | ||
|
|
||
| pub struct GotoLinePopup { | ||
| visible: bool, | ||
| input: String, | ||
| line_number: usize, | ||
| key_config: SharedKeyConfig, | ||
| queue: Queue, | ||
| theme: SharedTheme, | ||
| invalid_input: bool, | ||
| context: GotoLineContext, | ||
| } | ||
|
|
||
| impl GotoLinePopup { | ||
| pub fn new(env: &Environment) -> Self { | ||
| Self { | ||
| visible: false, | ||
| input: String::new(), | ||
| key_config: env.key_config.clone(), | ||
| queue: env.queue.clone(), | ||
| theme: env.theme.clone(), | ||
| invalid_input: false, | ||
| context: GotoLineContext { max_line: 0 }, | ||
| line_number: 0, | ||
| } | ||
| } | ||
|
|
||
| pub fn open(&mut self, context: GotoLineContext) { | ||
| self.visible = true; | ||
| self.context = context; | ||
| } | ||
| } | ||
|
|
||
| impl Component for GotoLinePopup { | ||
| /// | ||
| fn commands( | ||
| &self, | ||
| out: &mut Vec<CommandInfo>, | ||
| force_all: bool, | ||
| ) -> CommandBlocking { | ||
| if self.is_visible() || force_all { | ||
| out.push( | ||
| CommandInfo::new( | ||
| strings::commands::close_popup(&self.key_config), | ||
| true, | ||
| true, | ||
| ) | ||
| .order(1), | ||
| ); | ||
| out.push( | ||
| CommandInfo::new( | ||
| strings::commands::goto_line(&self.key_config), | ||
| true, | ||
| true, | ||
| ) | ||
| .order(1), | ||
| ); | ||
| } | ||
|
|
||
| visibility_blocking(self) | ||
| } | ||
|
|
||
| fn is_visible(&self) -> bool { | ||
| self.visible | ||
| } | ||
|
|
||
| /// | ||
| fn event(&mut self, event: &Event) -> Result<EventState> { | ||
| if self.is_visible() { | ||
| if let Event::Key(key) = event { | ||
| if key_match(key, self.key_config.keys.exit_popup) { | ||
| self.visible = false; | ||
| self.input.clear(); | ||
| } else if let KeyCode::Char(c) = key.code { | ||
| if c.is_ascii_digit() || c == '-' { | ||
| self.input.push(c); | ||
| } | ||
| } else if key.code == KeyCode::Backspace { | ||
| self.input.pop(); | ||
| } else if key_match(key, self.key_config.keys.enter) { | ||
| self.visible = false; | ||
| if self.invalid_input { | ||
| self.queue.push(InternalEvent::ShowErrorMsg( | ||
| format!("Invalid input: only numbers between -{} and {} (included) are allowed (-1 denotes the last line, -2 denotes the second to last line, and so on)",self.context.max_line + 1, self.context.max_line)) | ||
| , | ||
| ); | ||
| } else if !self.input.is_empty() { | ||
| self.queue.push(InternalEvent::GotoLine( | ||
| self.line_number, | ||
| )); | ||
| } | ||
| self.input.clear(); | ||
| self.invalid_input = false; | ||
| } | ||
| } | ||
| match self.input.parse::<isize>() { | ||
| Ok(input) => { | ||
| let mut max_value_allowed_abs = | ||
| self.context.max_line; | ||
| // negative indices are 1 based | ||
| if input < 0 { | ||
| max_value_allowed_abs += 1; | ||
| } | ||
| let input_abs = input.unsigned_abs(); | ||
| if input_abs > max_value_allowed_abs { | ||
| self.invalid_input = true; | ||
| } else { | ||
| self.invalid_input = false; | ||
| self.line_number = if input >= 0 { | ||
| input_abs | ||
| } else { | ||
| max_value_allowed_abs - input_abs | ||
| } | ||
| } | ||
| } | ||
| Err(_) => { | ||
| if !self.input.is_empty() { | ||
| self.invalid_input = true; | ||
| } | ||
| } | ||
| } | ||
| return Ok(EventState::Consumed); | ||
| } | ||
| Ok(EventState::NotConsumed) | ||
| } | ||
| } | ||
|
|
||
| impl DrawableComponent for GotoLinePopup { | ||
| fn draw(&self, f: &mut Frame, area: Rect) -> Result<()> { | ||
| if self.is_visible() { | ||
| let style = if self.invalid_input { | ||
| Style::default().fg(Color::Red) | ||
| } else { | ||
| self.theme.text(true, false) | ||
| }; | ||
| let input = Paragraph::new(self.input.as_str()) | ||
| .style(style) | ||
| .block(Block::bordered().title("Go to")); | ||
|
|
||
| let input_area = ui::centered_rect_absolute(15, 3, area); | ||
| f.render_widget(Clear, input_area); | ||
| f.render_widget(input, input_area); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.