Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ document review.
to. Sends go to the same place a document review's do (Herdr pane, Rex, Pi or the
clipboard, or the agent you choose when nothing named one; see [Choosing the agent](#choosing-the-agent)), and are kept in the feedback archive. `q` asks first when notes are unsent.
`m` opens the Review menu: `M` comment on the whole change, `R` resend all, `F` finish
review, `U` undo.
review, `U` undo. `U` also brings back the last note removed in this session, where it was.

`o` shows the whole file under the cursor as it is now, scrolled to the same line; `O`
shows it as it was before the change (the base), at the matching old line. The header says
Expand Down Expand Up @@ -302,8 +302,8 @@ The header shows the layout as a switch, `Split Unified` with the one in force
the line between the old and the new side to give one side more of the width, or press `(`
and `)`; a double click on the line makes the sides even again. Each side keeps at least 20
columns. `,` (or the header's `Settings` button) opens the diff settings: layout, split
ratio, wrap, line numbers, whitespace, tab width, changed text, colours and background, each
with its value. `↑`/`↓` pick one,
ratio, wrap, notes, line numbers, whitespace, tab width, changed text, colours and background,
each with its value. `↑`/`↓` pick one,
`←`/`→` change it, `enter` or `space` moves it on (and evens the split ratio), a click on a row
does the same, and `esc` closes the menu. Every change applies at once and is remembered for
the next review, however you made it (the menu, the switches, a key or a drag); the menu's
Expand All @@ -312,6 +312,24 @@ last row, **Reset to defaults**, forgets those choices and goes back to
the key hints first, then the `Wrap` switch, the `Settings` button and the `Review` button,
and keeps the layout switch longest (as `S U` when it must).

The settings' **Notes** row draws the notes in the diff, as a pull request's comments sit
in its diff: `panel` (the default) keeps them in the notes panel only, `inline` draws each in
a box under the last line it is about, and `both` does both. A box sits over its side of a
split diff (across both sides when that side is too narrow), several on one line stack in the
order they were made, and a note on the whole file sits under the file's heading. The box
shows the note's kind and lines, its author when it is not you, `sent` once sent, and up to
six lines of its text (a suggestion's code as `-`/`+` lines); `… enter for more` says there
is more. The cursor stops once on each box: `enter` or `e` opens the note in the comment box
over it, `delete` removes it (`U` brings it back), `c` or `s` there writes another note on
the same lines, under it, and a click on a box picks its note (in the panel too). A drag
selects code only, and boxes never move the line you are on: a note saved on the pane's last
row says `note saved · below, ↓ shows it`. A pane under 10 rows shows no boxes (`pane too
small for inline notes`). Notes on the whole change, and
notes whose lines the diff does not show now (outdated, in a hunk hidden with `W`, in a
filtered-out file), get no box: the footer counts them (`2 notes not shown inline · z`) and
the panel lists them. With `inline` the panel starts away whatever notes there are; `z`
opens it for the session. The whole-file view (`o`/`O`) keeps its notes in the panel.

The changed files are listed left of the diff as a folder tree. A chain of folders with
one folder each is one row (`crates/app/src/`), and the list is as wide as its names
need, up to two fifths of the screen. A name that does not fit is cut in the middle, so
Expand Down Expand Up @@ -592,6 +610,7 @@ file without the table opens diffs as before:
layout = "auto" # auto (split in a terminal 141 columns wide or more; default) | split | unified
split_ratio = 0.5 # the old side's share of a split row, 0.1 to 0.9; the new side gets the rest
wrap = false # wrap long lines instead of scrolling them sideways
notes = "panel" # panel (the notes panel only; default) | inline (boxes in the diff) | both
line_numbers = true # line numbers in the gutter; off keeps the +/- signs
theme = "auto" # the diff's colours: auto (follow [ui] theme, default) | dark | light
background = "terminal" # terminal (the terminal's own background, default) | theme (the diff theme's)
Expand Down
26 changes: 26 additions & 0 deletions crates/plannotator-tui-review/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,32 @@ impl ReviewStore {
Ok(removed)
}

/// Remove a note and hand it back with where it was, for [`Self::put_back`] to undo.
/// Its send history stays, so a note put back is as sent as it was.
pub fn take(&mut self, id: &str) -> Result<Option<(usize, CodeAnnotation)>> {
let Some(index) = self.record.annotations.iter().position(|n| n.id == id) else { return Ok(None) };
let mut taken = None;
self.commit(|record| {
taken = (index < record.annotations.len()).then(|| record.annotations.remove(index));
taken.is_some()
})?;
Ok(taken.map(|note| (index, note)))
}

/// Put a note [`Self::take`] removed back where it was, or last when fewer notes are left.
/// A note whose id is there again stays out. Returns whether it went back.
pub fn put_back(&mut self, index: usize, note: CodeAnnotation) -> Result<bool> {
if self.find(&note.id).is_some() {
return Ok(false);
}
self.commit(|record| {
let index = index.min(record.annotations.len());
record.annotations.insert(index, note);
true
})?;
Ok(true)
}

/// Apply resolutions (parallel to [`Self::annotations`], as
/// [`crate::Capture::resolve_all`] returns them) and save when a note moved or changed
/// state. Returns whether anything changed.
Expand Down
25 changes: 25 additions & 0 deletions crates/plannotator-tui-review/src/store/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,31 @@ fn a_send_is_never_dated_before_the_edits_it_covers() {
assert_eq!(parse_millis(&store.deliveries()[0].at), store.annotations()[0].plannotator_tui.updated_at);
}

#[test]
fn a_taken_note_goes_back_where_it_was_as_sent_as_it_was() {
let f = Fixture::new("take");
let mut store = f.load();
let ids = [add(&mut store, "a"), add(&mut store, "b"), add(&mut store, "c")];
let [a, b, c] = ids.clone();
store.record_delivery("agent", std::slice::from_ref(&b)).expect("records");
let (index, taken) = store.take(&b).expect("saves").expect("there");
assert_eq!((index, taken.id.as_str()), (1, b.as_str()));
assert!(store.take(&b).expect("saves").is_none(), "gone");
let mut store = f.load();
assert_eq!(store.annotations().len(), 2, "the removal was saved");
assert!(store.put_back(index, taken.clone()).expect("saves"));
let ids_now: Vec<&str> = store.annotations().iter().map(|n| n.id.as_str()).collect();
assert_eq!(ids_now, [a.as_str(), b.as_str(), c.as_str()]);
assert!(!store.is_pending(&store.annotations()[1]), "still sent");
assert!(!store.put_back(index, taken).expect("no-op"), "never twice");
assert_eq!(f.load().annotations().len(), 3, "and saved");
// Fewer notes left than its place: it goes last.
let (index, last) = store.take(&c).expect("saves").expect("there");
store.take(&a).expect("saves");
assert!(store.put_back(index, last).expect("saves"));
assert_eq!(store.annotations().last().map(|n| n.id.clone()), Some(c));
}

#[test]
fn finishing_archives_sent_notes_and_restoring_brings_them_back() {
let f = Fixture::new("archive");
Expand Down
2 changes: 1 addition & 1 deletion crates/plannotator-tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ signal-hook = "0.3"
# Default features off: `dev-tty` would switch crossterm, for this whole build, to reading
# /dev/tty, and `clipboard` is its own macOS clipboard; this app owns its input and copies.
# 0.2.4: the version the unpublished branch patched in at the workspace root carries.
diffs-rs = { version = "0.2.5", default-features = false }
diffs-rs = { version = "0.2.6", default-features = false }

[dev-dependencies]
rusqlite = { version = "0.31.0", features = ["bundled"] }
Expand Down
31 changes: 29 additions & 2 deletions crates/plannotator-tui/src/config/review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub(crate) struct ReviewConfig {
pub(crate) tab_width: TabWidth,
/// How the changed text inside a changed line is marked, by Pierre's names.
pub(crate) inline_changes: InlineChanges,
/// Where the notes show: the panel beside the diff, boxes in the diff under their lines,
/// or both.
pub(crate) notes: Notes,
}

impl ReviewConfig {
Expand All @@ -44,6 +47,7 @@ impl ReviewConfig {
whitespace: Whitespace::Show,
tab_width: TabWidth::DEFAULT,
inline_changes: InlineChanges::Word,
notes: Notes::Panel,
};
}

Expand Down Expand Up @@ -112,6 +116,19 @@ pub(crate) enum InlineChanges {
None,
}

/// `[review] notes`: where the code review shows its notes.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub(crate) enum Notes {
/// In the notes panel beside the diff, with a mark in the gutter.
#[default]
Panel,
/// In boxes in the diff under their lines; the panel opens only by hand.
Inline,
/// In boxes in the diff and in the panel.
Both,
}

/// `[review] tab_width`: the columns a tab advances to, from 1 to 16.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub(crate) struct TabWidth(u8);
Expand Down Expand Up @@ -239,6 +256,7 @@ mod tests {
whitespace: Whitespace::Show,
tab_width: TabWidth::new(4),
inline_changes: InlineChanges::Word,
notes: Notes::Panel,
}
);
}
Expand Down Expand Up @@ -280,7 +298,7 @@ mod tests {

#[test]
fn every_review_setting_is_read_and_roundtrips() {
let text = "[review]\nlayout = \"unified\"\nwrap = true\nline_numbers = false\ntheme = \"light\"\nbackground = \"theme\"\nsplit_ratio = 0.62\nwhitespace = \"ignore-all\"\ntab_width = 8\ninline_changes = \"word-alt\"\n";
let text = "[review]\nlayout = \"unified\"\nwrap = true\nline_numbers = false\ntheme = \"light\"\nbackground = \"theme\"\nsplit_ratio = 0.62\nwhitespace = \"ignore-all\"\ntab_width = 8\ninline_changes = \"word-alt\"\nnotes = \"both\"\n";
let config = Config::parse(text).expect("parses");
let review = config.review;
assert_eq!(review.layout, Layout::Unified);
Expand All @@ -291,11 +309,14 @@ mod tests {
assert_eq!(review.whitespace, Whitespace::IgnoreAll);
assert_eq!(review.tab_width.get(), 8);
assert_eq!(review.inline_changes, InlineChanges::WordAlt);
assert_eq!(review.notes, Notes::Both);
let shown = config.to_toml().expect("toml");
assert!(shown.contains("[review]\nlayout = \"unified\""), "{shown}");
assert!(shown.contains("split_ratio = 0.62\n"), "{shown}");
assert!(
shown.contains("whitespace = \"ignore-all\"\ntab_width = 8\ninline_changes = \"word-alt\"\n"),
shown.contains(
"whitespace = \"ignore-all\"\ntab_width = 8\ninline_changes = \"word-alt\"\nnotes = \"both\"\n"
),
"{shown}"
);
assert_eq!(Config::parse(&shown).expect("reparses"), config);
Expand All @@ -317,6 +338,10 @@ mod tests {
let config = Config::parse(&format!("[review]\ninline_changes = \"{name}\"\n")).expect("parses");
assert_eq!(config.review.inline_changes, value, "{name}");
}
for (name, value) in [("panel", Notes::Panel), ("inline", Notes::Inline), ("both", Notes::Both)] {
let config = Config::parse(&format!("[review]\nnotes = \"{name}\"\n")).expect("parses");
assert_eq!(config.review.notes, value, "{name}");
}
for width in 1..=16 {
let config = Config::parse(&format!("[review]\ntab_width = {width}\n")).expect("parses");
assert_eq!(config.review.tab_width.get(), width);
Expand All @@ -338,6 +363,8 @@ mod tests {
("[review]\nwhitespace = \"hide\"\n", "hide"),
("[review]\nwhitespace = true\n", "wanted string"),
("[review]\ninline_changes = \"words\"\n", "words"),
("[review]\nnotes = \"rail\"\n", "rail"),
("[review]\nnotes = true\n", "wanted string"),
] {
let err = Config::parse(text).expect_err("rejected");
assert!(err.to_string().contains(named), "{text:?}: {err}");
Expand Down
9 changes: 9 additions & 0 deletions crates/plannotator-tui/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,15 @@ impl Keymap {
self.keys(action).first().map(|key| key.hint()).unwrap_or_default()
}

/// The action's first key that no action of `context` takes, as the hints spell it;
/// empty when there is none.
#[cfg_attr(not(unix), allow(dead_code, reason = "only the code review, Unix-only, asks"))]
pub(crate) fn hint_besides(&self, action: Action, context: &[Action]) -> String {
let taken =
|key: &Key| context.iter().any(|&other| other != action && self.keys(other).contains(key));
self.keys(action).iter().find(|key| !taken(key)).map(|key| key.hint()).unwrap_or_default()
}

/// `key label` for a hint line, or nothing when the action is unbound, so an unbound
/// action leaves no bare label behind.
pub(crate) fn labelled(&self, action: Action, label: &str) -> Option<String> {
Expand Down
34 changes: 31 additions & 3 deletions crates/plannotator-tui/src/review/compose_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
//! shows them, else above the first, so the box covers none of them; in a split diff over
//! that side's pane, wherever the line between the sides was dragged. Lines taller than
//! the room keep the box at the end the person last moved to, the cursor's end.
//! - A file (`C`, editing a file note): under the file's heading, else at the top of the pane.
//! - A file (`C`, editing a file note): under the file's heading (and the file notes' boxes
//! there, lined up with them), else at the top of the pane.
//! - The whole change (`M`, editing its note), or lines no longer on screen: centred.
//! - Editing a note whose box the diff shows (`inline`): over the box, as wide as it. Notes'
//! boxes under the lines of a new one count as theirs: the box opens below them.
//!
//! The box only draws over the diff: opening, typing in and closing it never move the view
//! or the cursor. It grows with its text on the side it opened on and, out of room there,
Expand All @@ -23,7 +26,7 @@ use crate::ui::compose;
pub(super) const MAX_WIDTH: u16 = 84;
/// A split diff's side narrower than this is too narrow for the box, which then spans the
/// other side too.
const MIN_SIDE_WIDTH: u16 = 48;
pub(super) const MIN_SIDE_WIDTH: u16 = 48;
/// One row of text and its borders.
const MIN_HEIGHT: u16 = 3;
/// The room a side needs for the box to open there: three rows of text to grow into.
Expand Down Expand Up @@ -52,6 +55,8 @@ enum Anchor {
Lines(Lines),
File(String),
Centre,
/// A note's box in the diff, as last drawn.
Over(Rect),
}

impl Screen {
Expand All @@ -61,26 +66,48 @@ impl Screen {
let anchor = self.anchor(draft);
// Where the viewer drew the line between a split diff's sides, wherever it was dragged.
let middle = self.active_diff().filter(|diff| diff.split()).and_then(super::diff::Diff::split_line);
let boxes = self.notes_inline() && self.whole.is_none();
let (x, width) = match &anchor {
// Where the notes' boxes are drawn, the box lines up with them.
Anchor::Lines(lines)
if let Some(columns) = boxes.then(|| self.box_columns(pane, lines)).flatten() =>
{
columns
}
Anchor::Lines(lines) => columns(pane, middle, lines.side),
Anchor::File(path)
if let Some(columns) = boxes.then(|| self.heading_box_columns(pane, path)).flatten() =>
{
columns
}
Anchor::File(_) | Anchor::Centre => (pane.x, pane.width.min(MAX_WIDTH)),
Anchor::Over(rect) => (rect.x, rect.width),
};
let wrap = usize::from(width.saturating_sub(compose::CHROME));
let wanted = compose::height(&self.compose, wrap).min(pane.height);
if let Anchor::Over(rect) = anchor {
// From the box's top down, else as low as it fits.
let y = rect.y.min(pane.bottom().saturating_sub(wanted.max(ROOM.min(pane.height))));
return Rect { x, y, width, height: wanted.min(pane.bottom() - y) };
}
let diff = self.active_diff();
let rows = match &anchor {
Anchor::Lines(lines) => diff.and_then(|diff| diff.rows_showing(lines)).map(|(first, last)| {
let at_first = diff.and_then(|diff| diff.line_on(lines.side).ok().flatten());
let top = lines.first < lines.last
&& at_first.is_some_and(|(path, line)| path == lines.path && line == lines.first);
// Below the notes' boxes under the lines, never over them.
let last = if boxes { diff.map_or(last, |diff| diff.under_boxes(last)) } else { last };
(first, last, top)
}),
Anchor::File(path) => match diff.and_then(|diff| diff.heading_row(path)) {
// Below the file notes' boxes under the heading, never over them.
Some(row) if boxes => Some((row, diff.map_or(row, |diff| diff.under_boxes(row)), false)),
Some(row) => Some((row, row, false)),
// No heading on screen: at the top of the pane.
None => return Rect { x, y: pane.y, width, height: wanted },
},
Anchor::Centre => None,
Anchor::Centre | Anchor::Over(_) => None,
};
let Some((first, last, top)) = rows else {
let x = pane.x + (pane.width - width) / 2;
Expand All @@ -103,6 +130,7 @@ impl Screen {
}
Draft::File(path) => Anchor::File(path.clone()),
Draft::Change => Anchor::Centre,
Draft::Edit(id) if let Some(rect) = self.drawn_box(id) => Anchor::Over(rect),
Draft::Edit(id) => match self.store.annotations().iter().find(|note| note.id == *id) {
Some(note) if note.scope == NoteScope::File => Anchor::File(note.file_path.clone()),
Some(note) if note.scope == NoteScope::Line => Anchor::Lines(Lines {
Expand Down
10 changes: 9 additions & 1 deletion crates/plannotator-tui/src/review/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ use ratatui::crossterm::event::{Event, MouseEventKind};
use ratatui::layout::Rect;
use ratatui::style::Style;

mod insets;
mod place;
mod sections;
mod settings;
mod whitespace;

pub(super) use insets::Slot;
use sections::Sections;
use settings::{layout, options};

Expand Down Expand Up @@ -317,7 +319,13 @@ impl Diff {

/// The side the cursor is on.
pub(super) fn cursor_side(&self) -> Result<Option<Side>> {
Ok(self.engine.selected_source()?.map(|at| side_of(at.side)))
if let Some(at) = self.engine.selected_source()? {
return Ok(Some(side_of(at.side)));
}
// On a note's box: the side it is over.
let on_box =
self.engine.cursor_row().filter(|row| matches!(row.kind, engine::DiffRowKind::Inset { .. }));
Ok(on_box.map(|row| side_of(row.side)))
}

/// The cursor's line on `side`, with its file: `None` on a header, a gap, or a row that
Expand Down
Loading
Loading