brain: Stabilize the hunk comment viewport
865bba9ea30df44b3ac388d614dbf59cbc0f4a00
Keep isolated hunks fully bright and reveal their final rows on first render so the comment editor starts directly below the relevant code. Assisted-by: Codex:gpt-5.6-sol
1 parent
469fcb79
crates/brain/src/session.rs
+3 -2
| 6 | 6 | use std::sync::mpsc::{self, Receiver, RecvTimeoutError, Sender}; |
|
| 7 | 7 | use std::time::Duration; |
|
| 8 | 8 | ||
| 9 | 9 | use rustik_diff::{ |
|
| 10 | 10 | ContextChange, DiffAction, DiffDocument, DiffFocus, DiffOptions, DiffState, DiffViewer, |
|
| 11 | - | FileDiff, FileTreeMode, HighlightOutput, HighlightRequest, Highlighter, ReviewProgress, |
|
| 12 | - | ViewChange, spawn_highlighter, |
|
| 11 | + | FileDiff, FileTreeMode, HighlightOutput, HighlightRequest, Highlighter, HunkFocus, |
|
| 12 | + | ReviewProgress, ViewChange, spawn_highlighter, |
|
| 13 | 13 | }; |
|
| 14 | 14 | use rustik_repo::{DiffStat, git}; |
|
| 15 | 15 | use rustik_tui::{ |
|
| 16 | 16 | Backend as TuiBackend, Column, Constraint, Control, Event, Key, Line, List, ListState, Mouse, |
|
| 17 | 17 | MouseButton, Rect, ScrollView, Style, Table, TableOptions, Terminal, |
| 1080 | 1080 | return Ok(()); |
|
| 1081 | 1081 | } |
|
| 1082 | 1082 | self.parked = None; |
|
| 1083 | 1083 | let mut options = self.options.clone(); |
|
| 1084 | 1084 | options.file_tree = FileTreeMode::Hidden; |
|
| 1085 | + | options.hunk_focus = HunkFocus::Plain; |
|
| 1085 | 1086 | ||
| 1086 | 1087 | let loaded = self.current()?; |
|
| 1087 | 1088 | let Some((file, focused)) = loaded.document.files.iter().find_map(|file| { |
|
| 1088 | 1089 | let focused = file.hunks.iter().find(|candidate| candidate.id == hunk)?; |
|
| 1089 | 1090 | Some((file, focused)) |
a.rs
+0 -0
crates/brain/src/session/hunk.rs
+11 -3
| 1 | 1 | //! Hunk comment editor view. |
|
| 2 | 2 | ||
| 3 | - | use rustik_diff::{DiffViewer, HunkId}; |
|
| 3 | + | use rustik_diff::{DiffAction, DiffViewer, HunkId}; |
|
| 4 | 4 | use rustik_tui::{ |
|
| 5 | - | Buffer, Color, Constraint, Line, Rect, RenderResult, Size, StatefulWidget, Style, TextField, |
|
| 6 | - | TextInput, Widget, |
|
| 5 | + | Buffer, Color, Constraint, Line, Rect, RenderResult, Scroll, Size, StatefulWidget, Style, |
|
| 6 | + | TextField, TextInput, Widget, |
|
| 7 | 7 | }; |
|
| 8 | 8 | ||
| 9 | 9 | use super::status::{ |
|
| 10 | 10 | COMMENT_CARD_CHROME_COLS, COMMENT_CARD_CHROME_ROWS, COMMENT_CARD_ROWS, comment_age, |
|
| 11 | 11 | comment_card_lines, comment_editor_lines, |
| 54 | 54 | pub(super) viewer: DiffViewer, |
|
| 55 | 55 | /// Author shown for newly authored draft comments. |
|
| 56 | 56 | author: String, |
|
| 57 | 57 | /// Current comment mode. |
|
| 58 | 58 | mode: HunkMode, |
|
| 59 | + | /// Whether the first render still needs to reveal the hunk's final rows. |
|
| 60 | + | scroll_to_bottom: bool, |
|
| 59 | 61 | } |
|
| 60 | 62 | ||
| 61 | 63 | impl HunkView { |
|
| 62 | 64 | /// Creates a hunk comment view. |
|
| 63 | 65 | pub(super) fn new(hunk: HunkId, viewer: DiffViewer, author: String) -> Self { |
|
| 64 | 66 | Self { |
|
| 65 | 67 | hunk, |
|
| 66 | 68 | viewer, |
|
| 67 | 69 | author, |
|
| 68 | 70 | mode: HunkMode::Browsing { selected: 0 }, |
|
| 71 | + | scroll_to_bottom: true, |
|
| 69 | 72 | } |
|
| 70 | 73 | } |
|
| 71 | 74 | ||
| 72 | 75 | /// Returns whether the view is editing a comment. |
|
| 73 | 76 | pub(super) fn is_editing(&self) -> bool { |
| 295 | 298 | return RenderResult::default(); |
|
| 296 | 299 | } |
|
| 297 | 300 | self.clamp_selection(comments.len()); |
|
| 298 | 301 | let (hunk_area, comments_area) = self.areas(area, self.comment_rows(comments.len())); |
|
| 299 | 302 | let mut result = RenderResult::default(); |
|
| 303 | + | if self.scroll_to_bottom { |
|
| 304 | + | self.viewer |
|
| 305 | + | .apply(DiffAction::Scroll(Scroll::Bottom), hunk_area); |
|
| 306 | + | self.scroll_to_bottom = false; |
|
| 307 | + | } |
|
| 300 | 308 | ||
| 301 | 309 | self.viewer.render(hunk_area, buf); |
|
| 302 | 310 | ||
| 303 | 311 | let (lines, editor_row) = self.comment_lines(comments, comments_area.cols); |
|
| 304 | 312 | Line::renders( |
a.txt
+0 -0