mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
## Why A single-line jump doesn't show where a referenced block of code ends. ## What changed Recognize file ranges such as `src/search.ts:42-44` and `src/search.ts#L42-L44` in Markdown links and bare prose. Opening a range in the sidebar jumps to its start and highlights every line through its end, including wrapped rows and blank lines. If the link specifies a starting column, mark it too. Pressing `Esc` can clear the highlight, and it stays cleared across reloads. Keep each wrapped link as one keyboard navigation stop, even when fragments from different links share a table row. Preserve hidden range destinations when copying Markdown. ## Testing Add coverage for malformed and out-of-bounds ranges, mouse and keyboard navigation across wrapped links, Markdown copying, and highlight rendering across terminal palettes. GitOrigin-RevId: 1171533053e92a61de01f90f248c58b059b3ae32
684 lines
26 KiB
Rust
684 lines
26 KiB
Rust
//! Transcript gestures leave ordinary typing and composer editing with the existing input path.
|
|
//! Stationary link clicks open on release; dragging or scrolling keeps the gesture in selection.
|
|
//! Shift-click extends the existing selection from its original text unit.
|
|
//! Optional automatic copying happens only when a nonempty mouse selection is released.
|
|
//! Automatic copies optionally clear the selection; explicit copies always clear it after
|
|
//! confirmed delivery.
|
|
//! Wheel input accumulates fractional rows and discards the remainder when direction reverses.
|
|
|
|
use crate::key_hint::KeyBindingListExt;
|
|
use codex_protocol::ThreadId;
|
|
use crossterm::event::KeyCode;
|
|
use crossterm::event::KeyEvent;
|
|
use crossterm::event::KeyEventKind;
|
|
use crossterm::event::KeyModifiers;
|
|
use crossterm::event::MouseButton;
|
|
use crossterm::event::MouseEvent;
|
|
use crossterm::event::MouseEventKind;
|
|
use ratatui::layout::Position as ScreenPosition;
|
|
|
|
use super::*;
|
|
use crate::markdown_render::FileLink;
|
|
use crate::terminal_hyperlinks::ReaderLink;
|
|
|
|
pub(crate) enum ViewAction {
|
|
Changed,
|
|
ExitSelectMode,
|
|
Copy(String),
|
|
CopyOnSelect(String),
|
|
PrimarySelection(String),
|
|
CopyAndFollow(String),
|
|
OpenAgent(ThreadId),
|
|
OpenLink(String),
|
|
OpenDocument(FileLink),
|
|
}
|
|
|
|
impl From<ReaderLink> for ViewAction {
|
|
fn from(link: ReaderLink) -> Self {
|
|
match link {
|
|
ReaderLink::Agent(id) => Self::OpenAgent(id),
|
|
ReaderLink::External(url) => Self::OpenLink(url),
|
|
ReaderLink::Document(link) => Self::OpenDocument(link),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
|
enum MouseMode<'a> {
|
|
Interactive,
|
|
Selection(Option<(ThreadId, &'a str)>),
|
|
}
|
|
|
|
/// Transcript jumps shared with input routing so legacy terminals preserve their Alt modifier.
|
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
|
pub(crate) enum JumpTarget {
|
|
Beginning,
|
|
Latest,
|
|
}
|
|
|
|
impl JumpTarget {
|
|
/// Include the Alt alternative for terminals that do not send Ctrl+Home/End.
|
|
pub(crate) fn hint_label(self) -> String {
|
|
let (control, alternate) = match self {
|
|
Self::Beginning => (KeyCode::Home, KeyCode::Char('<')),
|
|
Self::Latest => (KeyCode::End, KeyCode::Char('>')),
|
|
};
|
|
let alternate = crate::key_hint::alt(alternate).display_label();
|
|
format!(
|
|
"{alternate}/{}",
|
|
crate::key_hint::ctrl(control).display_label()
|
|
)
|
|
}
|
|
|
|
pub(crate) fn from_key(key: KeyEvent) -> Option<Self> {
|
|
if key.kind == KeyEventKind::Release {
|
|
return None;
|
|
}
|
|
match (key.code, key.modifiers) {
|
|
(KeyCode::Home, KeyModifiers::CONTROL) => Some(Self::Beginning),
|
|
(KeyCode::End, KeyModifiers::CONTROL) => Some(Self::Latest),
|
|
// Zellij can omit the shifted alternate character from enhanced key events.
|
|
(KeyCode::Char(','), modifiers)
|
|
if modifiers == (KeyModifiers::ALT | KeyModifiers::SHIFT) =>
|
|
{
|
|
Some(Self::Beginning)
|
|
}
|
|
(KeyCode::Char('.'), modifiers)
|
|
if modifiers == (KeyModifiers::ALT | KeyModifiers::SHIFT) =>
|
|
{
|
|
Some(Self::Latest)
|
|
}
|
|
// Terminals differ on whether shifted punctuation retains the Shift modifier.
|
|
(KeyCode::Char('<'), modifiers)
|
|
if modifiers.difference(KeyModifiers::SHIFT) == KeyModifiers::ALT =>
|
|
{
|
|
Some(Self::Beginning)
|
|
}
|
|
(KeyCode::Char('>'), modifiers)
|
|
if modifiers.difference(KeyModifiers::SHIFT) == KeyModifiers::ALT =>
|
|
{
|
|
Some(Self::Latest)
|
|
}
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TranscriptView {
|
|
/// Automatic copies may deselect but still publish PRIMARY, so retain their source.
|
|
pub(crate) fn selection_copy(&self, action: &ViewAction) -> SelectionCopy {
|
|
match action {
|
|
ViewAction::CopyOnSelect(_) => SelectionCopy::on_select(
|
|
/*clipboard*/ true,
|
|
self.primary_selection,
|
|
self.copy_on_select_clear_selection,
|
|
),
|
|
ViewAction::PrimarySelection(_) => SelectionCopy::on_select(
|
|
/*clipboard*/ false, /*primary*/ true, /*clear_selection*/ false,
|
|
),
|
|
ViewAction::Changed
|
|
| ViewAction::ExitSelectMode
|
|
| ViewAction::Copy(_)
|
|
| ViewAction::CopyAndFollow(_)
|
|
| ViewAction::OpenAgent(_)
|
|
| ViewAction::OpenDocument(_)
|
|
| ViewAction::OpenLink(_) => SelectionCopy::EXPLICIT,
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
pub(crate) fn link_at(&self, column: u16, row: u16) -> Option<String> {
|
|
self.reader_link_at(column, row)
|
|
.map(ReaderLink::into_destination)
|
|
}
|
|
|
|
/// Resolve links in the last rendered transcript, sharing geometry with click activation.
|
|
pub(crate) fn reader_link_at(&self, column: u16, row: u16) -> Option<ReaderLink> {
|
|
let (_, link) = self.raw_link_at(ScreenPosition::new(column, row))?;
|
|
if self.agent_links.is_some()
|
|
&& let Some(agent) = link.agent_id()
|
|
{
|
|
return Some(ReaderLink::Agent(agent));
|
|
}
|
|
link.reader_destination(self.document_links)
|
|
.or_else(|| link.interaction_destination().map(ReaderLink::External))
|
|
}
|
|
|
|
pub(crate) fn cycle_document_link(
|
|
&mut self,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
selected: Option<usize>,
|
|
forward: bool,
|
|
) -> Option<usize> {
|
|
let layout = self.layout(cells, /*index*/ 0)?;
|
|
let links = layout.document_links();
|
|
let count = links.len();
|
|
if count == 0 {
|
|
return None;
|
|
}
|
|
let index = match selected {
|
|
Some(index) if forward => (index + 1) % count,
|
|
Some(index) => (index + count - 1) % count,
|
|
None if forward => 0,
|
|
None => count - 1,
|
|
};
|
|
let offset = links[index].0.first()?.start;
|
|
let row = layout.row_for_offset(offset);
|
|
if !self
|
|
.visible
|
|
.iter()
|
|
.any(|visible| visible.index == 0 && visible.row == row)
|
|
{
|
|
self.jump_to_offset(cells, offset);
|
|
}
|
|
Some(index)
|
|
}
|
|
|
|
pub(crate) fn document_link(
|
|
&mut self,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
index: usize,
|
|
) -> Option<ReaderLink> {
|
|
self.layout(cells, /*index*/ 0)?
|
|
.document_links()
|
|
.into_iter()
|
|
.nth(index)
|
|
.map(|(_, link)| link)
|
|
}
|
|
|
|
pub(crate) fn paint_document_link(
|
|
&mut self,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
index: usize,
|
|
buf: &mut ratatui::buffer::Buffer,
|
|
) {
|
|
let Some(layout) = self.layout(cells, /*index*/ 0) else {
|
|
return;
|
|
};
|
|
let Some((ranges, _)) = layout.document_links().into_iter().nth(index) else {
|
|
return;
|
|
};
|
|
for (y, visible) in (self.area.top()..self.area.bottom()).zip(&self.visible) {
|
|
if visible.index == 0 {
|
|
let area = Rect::new(self.area.x, y, self.area.width, /*height*/ 1);
|
|
for range in &ranges {
|
|
visible
|
|
.layout
|
|
.highlight(range.clone(), area, buf, visible.row);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) fn navigate_pager(
|
|
&mut self,
|
|
key: KeyEvent,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
keymap: &crate::keymap::PagerKeymap,
|
|
) -> bool {
|
|
if keymap.jump_top.is_pressed(key) {
|
|
self.jump_to_beginning(cells);
|
|
return true;
|
|
}
|
|
if keymap.jump_bottom.is_pressed(key) {
|
|
self.jump_to_latest();
|
|
return true;
|
|
}
|
|
let page = self.area.height.max(/*other*/ 1) as isize;
|
|
let half = (page + 1) / 2;
|
|
let delta = [
|
|
(&keymap.scroll_up, -1),
|
|
(&keymap.scroll_down, 1),
|
|
(&keymap.page_up, -page),
|
|
(&keymap.page_down, page),
|
|
(&keymap.half_page_up, -half),
|
|
(&keymap.half_page_down, half),
|
|
]
|
|
.into_iter()
|
|
.find_map(|(bindings, delta)| bindings.is_pressed(key).then_some(delta));
|
|
let Some(delta) = delta else {
|
|
return false;
|
|
};
|
|
self.scroll(cells, delta);
|
|
true
|
|
}
|
|
|
|
/// Keep selection and Find control keys ahead of configurable chord prefixes.
|
|
pub(crate) fn owns_interaction_key(&self, key: KeyEvent) -> bool {
|
|
if key.kind == KeyEventKind::Release {
|
|
return false;
|
|
}
|
|
let (code, modifiers) = crate::key_hint::normalize_key_parts(key.code, key.modifiers);
|
|
if (code == KeyCode::Char(' ') && modifiers == KeyModifiers::CONTROL)
|
|
|| JumpTarget::from_key(key).is_some()
|
|
{
|
|
return true;
|
|
}
|
|
if self.copy_mode.is_some() {
|
|
return true;
|
|
}
|
|
if self.is_select_mode() {
|
|
return true;
|
|
}
|
|
if self.selection.is_some() {
|
|
return crate::text_selection::is_copy_key(key)
|
|
|| code == KeyCode::Esc
|
|
|| (code == KeyCode::Enter && modifiers == KeyModifiers::NONE)
|
|
|| (matches!(modifiers, KeyModifiers::NONE | KeyModifiers::SHIFT)
|
|
&& matches!(
|
|
code,
|
|
KeyCode::Left | KeyCode::Right | KeyCode::Up | KeyCode::Down
|
|
))
|
|
|| (modifiers == KeyModifiers::NONE
|
|
&& matches!(code, KeyCode::PageUp | KeyCode::PageDown));
|
|
}
|
|
self.search.is_active()
|
|
&& (code == KeyCode::Esc
|
|
|| (code == KeyCode::Enter
|
|
&& (self.is_search_editing() || modifiers == KeyModifiers::NONE))
|
|
|| (modifiers == KeyModifiers::NONE
|
|
&& matches!(code, KeyCode::PageUp | KeyCode::PageDown))
|
|
|| (modifiers == KeyModifiers::CONTROL
|
|
&& matches!(code, KeyCode::Char('c' | 'n' | 'p'))))
|
|
}
|
|
|
|
pub(crate) fn handle_key(
|
|
&mut self,
|
|
key: KeyEvent,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
) -> Option<ViewAction> {
|
|
if key.kind == KeyEventKind::Release {
|
|
return None;
|
|
}
|
|
if let Some(action) = self.handle_copy_mode_key(key, cells) {
|
|
return Some(action);
|
|
}
|
|
if self.is_select_mode() {
|
|
if self.is_search_editing() {
|
|
let (code, modifiers) =
|
|
crate::key_hint::normalize_key_parts(key.code, key.modifiers);
|
|
let accepting = code == KeyCode::Enter && modifiers == KeyModifiers::NONE;
|
|
let cancelling = code == KeyCode::Esc
|
|
|| (code == KeyCode::Char('c') && modifiers == KeyModifiers::CONTROL);
|
|
if self.handle_search_key(key, cells) {
|
|
if accepting && self.search.is_reading() {
|
|
self.accept_search_into_select_mode(cells);
|
|
} else if cancelling {
|
|
self.restore_select_search_origin(cells);
|
|
}
|
|
return Some(ViewAction::Changed);
|
|
}
|
|
}
|
|
return self
|
|
.handle_select_mode_key(key, cells)
|
|
.or(Some(ViewAction::Changed));
|
|
}
|
|
if let Some(action) = self.handle_disclosure_key(key, cells) {
|
|
return Some(action);
|
|
}
|
|
if self.selection.is_some() {
|
|
if let Some(action) = self.handle_selection_key(key, cells) {
|
|
return Some(action);
|
|
}
|
|
self.end_selection(cells);
|
|
}
|
|
let (code, modifiers) = crate::key_hint::normalize_key_parts(key.code, key.modifiers);
|
|
if modifiers == KeyModifiers::CONTROL && code == KeyCode::Char(' ') {
|
|
self.begin_selection(cells, self.area.x, self.area.y, /*clicks*/ 1);
|
|
if let Some(selection) = &mut self.selection {
|
|
// Ctrl+Space extends a half-open source range with the arrow keys.
|
|
// Start at the logical boundary even if the leftmost glyph is RTL.
|
|
if let Some(first) = self.visible.first()
|
|
&& first.layout.visual_hit(first.row, /*column*/ 0).is_some()
|
|
{
|
|
let mut anchor = selection.start;
|
|
anchor.offset = first.layout.position_at(first.row, /*column*/ 0);
|
|
selection.set_keyboard_range(anchor, anchor);
|
|
}
|
|
selection.dragging = false;
|
|
selection.resume_on_empty = false;
|
|
}
|
|
return Some(ViewAction::Changed);
|
|
}
|
|
if self.handle_search_key(key, cells) {
|
|
return Some(ViewAction::Changed);
|
|
}
|
|
self.handle_scroll_key(key, cells)
|
|
}
|
|
|
|
pub(crate) fn handle_mouse(
|
|
&mut self,
|
|
event: MouseEvent,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
) -> Option<ViewAction> {
|
|
if self.select_mode.is_some() {
|
|
return self.handle_selection_mouse(event, cells, /*patch_approval*/ None);
|
|
}
|
|
self.handle_mouse_with_mode(event, cells, MouseMode::Interactive)
|
|
}
|
|
|
|
/// Modals allow transcript disclosure, while select mode keeps clicks for text selection.
|
|
pub(crate) fn handle_selection_mouse(
|
|
&mut self,
|
|
event: MouseEvent,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
patch_approval: Option<(ThreadId, &str)>,
|
|
) -> Option<ViewAction> {
|
|
let endpoint_changed = matches!(
|
|
event.kind,
|
|
MouseEventKind::Down(MouseButton::Left)
|
|
| MouseEventKind::Drag(MouseButton::Left)
|
|
| MouseEventKind::Up(MouseButton::Left)
|
|
);
|
|
let before = self.selection.as_ref().map(|selection| {
|
|
(
|
|
selection.start,
|
|
selection.end,
|
|
selection.unit(),
|
|
selection.has_table_scope(),
|
|
selection.mouse_endpoints,
|
|
)
|
|
});
|
|
let action =
|
|
self.handle_mouse_with_mode(event, cells, MouseMode::Selection(patch_approval));
|
|
let after = self.selection.as_ref().map(|selection| {
|
|
(
|
|
selection.start,
|
|
selection.end,
|
|
selection.unit(),
|
|
selection.has_table_scope(),
|
|
selection.mouse_endpoints,
|
|
)
|
|
});
|
|
if endpoint_changed && before != after {
|
|
if self.has_selection_range() {
|
|
self.disclosure.resume_after_approval = None;
|
|
}
|
|
self.adopt_select_mouse_range();
|
|
}
|
|
action
|
|
}
|
|
|
|
fn handle_mouse_with_mode(
|
|
&mut self,
|
|
event: MouseEvent,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
mode: MouseMode<'_>,
|
|
) -> Option<ViewAction> {
|
|
if mode == MouseMode::Interactive
|
|
&& let Some(action) = self.handle_follow_control_mouse(event)
|
|
{
|
|
return Some(action);
|
|
}
|
|
let point = ScreenPosition::new(event.column, event.row);
|
|
if mode == MouseMode::Interactive
|
|
&& event.kind == MouseEventKind::Down(MouseButton::Left)
|
|
&& event.modifiers.is_empty()
|
|
&& let Some((area, key)) = self.prompt_header_target
|
|
&& area.contains(point)
|
|
{
|
|
self.last_click = None;
|
|
if let Some(index) = cells.iter().position(|cell| EntryKey::cell(cell) == key) {
|
|
self.end_selection(cells);
|
|
self.cancel_search();
|
|
self.clear_activity_focus();
|
|
self.jump_to_entry(cells, index);
|
|
}
|
|
return Some(ViewAction::Changed);
|
|
}
|
|
if mode == MouseMode::Interactive
|
|
&& event.kind == MouseEventKind::Down(MouseButton::Left)
|
|
&& event
|
|
.modifiers
|
|
.intersects(KeyModifiers::CONTROL | KeyModifiers::SUPER)
|
|
&& let Some((area, tip)) = &self.composer_tip
|
|
&& area.contains(point)
|
|
{
|
|
let column = usize::from(event.column - area.x);
|
|
return tip
|
|
.hyperlinks
|
|
.iter()
|
|
.find(|link| link.columns.contains(&column))?
|
|
.interaction_destination()
|
|
.map(ViewAction::OpenLink);
|
|
}
|
|
let inside = self.area.contains(point);
|
|
let dragging = self
|
|
.selection
|
|
.as_ref()
|
|
.is_some_and(|selection| selection.dragging);
|
|
if !inside && !dragging {
|
|
return None;
|
|
}
|
|
// Wheel navigation supersedes the last drag position. A real drag event can resume it.
|
|
if matches!(
|
|
event.kind,
|
|
MouseEventKind::ScrollUp | MouseEventKind::ScrollDown
|
|
) && let Some(selection) = &mut self.selection
|
|
{
|
|
selection.pointer = None;
|
|
}
|
|
match event.kind {
|
|
MouseEventKind::ScrollUp | MouseEventKind::ScrollDown => {
|
|
let direction = if event.kind == MouseEventKind::ScrollUp {
|
|
-1.0
|
|
} else {
|
|
1.0
|
|
};
|
|
if self.pending_mouse_scroll.signum() != direction {
|
|
self.pending_mouse_scroll = 0.0;
|
|
}
|
|
self.pending_mouse_scroll += direction * self.mouse_scroll_speed;
|
|
// Decimal speeds can land just short of a whole row after repeated addition.
|
|
let rounded = self.pending_mouse_scroll.round();
|
|
if rounded != 0.0 && (self.pending_mouse_scroll - rounded).abs() < 1e-9 {
|
|
self.pending_mouse_scroll = rounded;
|
|
}
|
|
let rows = self.pending_mouse_scroll as isize;
|
|
self.pending_mouse_scroll = self.pending_mouse_scroll.fract();
|
|
if rows != 0 {
|
|
self.scroll(cells, rows);
|
|
}
|
|
}
|
|
MouseEventKind::Down(MouseButton::Right) if inside => {
|
|
return self
|
|
.selected_text(cells)
|
|
.filter(|text| !text.is_empty())
|
|
.map(ViewAction::Copy);
|
|
}
|
|
MouseEventKind::Down(MouseButton::Left) => {
|
|
return self.pointer_down(event, cells, mode);
|
|
}
|
|
MouseEventKind::Drag(MouseButton::Left) if dragging => {
|
|
// A drag ends the click sequence even when the next press is at the same spot.
|
|
self.last_click = None;
|
|
self.extend_selection(event.column, event.row);
|
|
}
|
|
MouseEventKind::Up(MouseButton::Left) if dragging => {
|
|
// Open only a stationary click. Dragging back to the origin is still selection,
|
|
// and wheel scrolling clears the pointer even when it cannot move the viewport.
|
|
let link = if mode == MouseMode::Interactive {
|
|
self.selection.as_mut().and_then(|selection| {
|
|
(inside
|
|
&& !selection.moved
|
|
&& selection.pointer
|
|
== Some(ScreenPosition::new(event.column, event.row))
|
|
&& event.modifiers.is_empty())
|
|
.then(|| selection.pressed_link.take())
|
|
.flatten()
|
|
})
|
|
} else {
|
|
None
|
|
};
|
|
let link = link.filter(|destination| {
|
|
self.reader_link_at(event.column, event.row).as_ref() == Some(destination)
|
|
});
|
|
if self
|
|
.selection
|
|
.as_ref()
|
|
.is_some_and(|selection| selection.moved && selection.pointer.is_some())
|
|
{
|
|
self.extend_selection(event.column, event.row);
|
|
}
|
|
self.end_drag();
|
|
let selected = self.selected_text(cells);
|
|
if selected.is_none() {
|
|
self.end_selection(cells);
|
|
}
|
|
if let Some(link) = link {
|
|
return Some(link.into());
|
|
}
|
|
if let Some(text) = selected.filter(|text| !text.is_empty()) {
|
|
if self.copy_on_select {
|
|
return Some(ViewAction::CopyOnSelect(text));
|
|
}
|
|
if self.primary_selection {
|
|
return Some(ViewAction::PrimarySelection(text));
|
|
}
|
|
}
|
|
}
|
|
_ => return None,
|
|
}
|
|
Some(ViewAction::Changed)
|
|
}
|
|
|
|
pub(crate) fn handle_selection_key(
|
|
&mut self,
|
|
key: KeyEvent,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
) -> Option<ViewAction> {
|
|
if crate::text_selection::is_copy_key(key)
|
|
|| (key.modifiers == KeyModifiers::NONE && key.code == KeyCode::Enter)
|
|
{
|
|
return Some(
|
|
self.selected_text(cells)
|
|
.filter(|text| !text.is_empty())
|
|
.map_or(ViewAction::Changed, |text| {
|
|
if key.code == KeyCode::Enter {
|
|
ViewAction::CopyAndFollow(text)
|
|
} else {
|
|
ViewAction::Copy(text)
|
|
}
|
|
}),
|
|
);
|
|
}
|
|
if key.code == KeyCode::Esc {
|
|
self.end_selection(cells);
|
|
return Some(ViewAction::Changed);
|
|
}
|
|
if matches!(key.modifiers, KeyModifiers::NONE | KeyModifiers::SHIFT)
|
|
&& self.selection_key(cells, key.code)
|
|
{
|
|
return Some(ViewAction::Changed);
|
|
}
|
|
self.handle_scroll_key(key, cells)
|
|
}
|
|
|
|
pub(super) fn handle_scroll_key(
|
|
&mut self,
|
|
key: KeyEvent,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
) -> Option<ViewAction> {
|
|
let jump = JumpTarget::from_key(key);
|
|
match (key.code, key.modifiers) {
|
|
(KeyCode::PageUp | KeyCode::PageDown, KeyModifiers::NONE) => {
|
|
// Share page-key configuration without taking the pager's typing shortcuts.
|
|
// Full pages retain the main view's existing one-row overlap.
|
|
let keymap = &self.disclosure.keymap.pager;
|
|
let height = self.area.height.max(/*other*/ 1) as isize;
|
|
let page = (height - 1).max(/*other*/ 1);
|
|
let half = (height + 1) / 2;
|
|
let delta = [
|
|
(&keymap.scroll_up, -1),
|
|
(&keymap.scroll_down, 1),
|
|
(&keymap.page_up, -page),
|
|
(&keymap.page_down, page),
|
|
(&keymap.half_page_up, -half),
|
|
(&keymap.half_page_down, half),
|
|
]
|
|
.into_iter()
|
|
.find_map(|(bindings, delta)| bindings.is_pressed(key).then_some(delta))?;
|
|
self.scroll(cells, delta);
|
|
}
|
|
(KeyCode::Esc, KeyModifiers::NONE) if self.can_return_to_latest() => {
|
|
self.jump_to_latest();
|
|
}
|
|
_ if jump == Some(JumpTarget::Beginning) => {
|
|
self.jump_to_beginning(cells);
|
|
}
|
|
_ if jump == Some(JumpTarget::Latest) => self.jump_to_latest(),
|
|
_ => return None,
|
|
}
|
|
Some(ViewAction::Changed)
|
|
}
|
|
|
|
fn pointer_down(
|
|
&mut self,
|
|
event: MouseEvent,
|
|
cells: &[Arc<dyn HistoryCell>],
|
|
mode: MouseMode<'_>,
|
|
) -> Option<ViewAction> {
|
|
let was_following = self.is_following();
|
|
if event.modifiers.is_empty() && self.toggle_disclosure_at(cells, event.column, event.row) {
|
|
// Keep the patch anchored for inspection, then follow again when the prompt closes.
|
|
if was_following && let MouseMode::Selection(Some((thread_id, id))) = mode {
|
|
self.disclosure.resume_after_approval = Some((thread_id, id.to_owned()));
|
|
}
|
|
return Some(ViewAction::Changed);
|
|
}
|
|
self.disclosure.focused = None;
|
|
let visible = self
|
|
.visible
|
|
.get(usize::from(event.row.checked_sub(self.area.y)?))?;
|
|
if mode == MouseMode::Interactive
|
|
&& event
|
|
.modifiers
|
|
.intersects(KeyModifiers::CONTROL | KeyModifiers::SUPER)
|
|
{
|
|
return self
|
|
.reader_link_at(event.column, event.row)
|
|
.map(ViewAction::from);
|
|
}
|
|
if event.modifiers == KeyModifiers::SHIFT && self.has_selection_range() {
|
|
self.last_click = None;
|
|
self.extend_selection(event.column, event.row);
|
|
if let Some(selection) = &mut self.selection {
|
|
selection.dragging = true;
|
|
selection.pressed_link = None;
|
|
}
|
|
return Some(ViewAction::Changed);
|
|
}
|
|
let clicks =
|
|
crate::text_selection::click_count(&mut self.last_click, event.column, event.row);
|
|
if clicks >= 2 {
|
|
let column = event.column.saturating_sub(self.area.x);
|
|
let layout = &visible.layout;
|
|
let offset = layout.position_at(visible.row, column);
|
|
let at_row_end = offset == layout.position_at(visible.row, u16::MAX);
|
|
let can_select_from_padding = at_row_end
|
|
&& clicks == 3
|
|
&& !self.is_select_mode()
|
|
&& layout.table_cell_at(visible.row, column, offset).is_some();
|
|
if at_row_end && !can_select_from_padding {
|
|
return None;
|
|
}
|
|
}
|
|
let link = (mode == MouseMode::Interactive && clicks == 1 && event.modifiers.is_empty())
|
|
.then(|| self.reader_link_at(event.column, event.row))
|
|
.flatten();
|
|
self.begin_selection(cells, event.column, event.row, clicks);
|
|
if let Some(selection) = &mut self.selection {
|
|
selection.pressed_link = link;
|
|
}
|
|
Some(ViewAction::Changed)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "input_tests.rs"]
|
|
mod tests;
|
|
|
|
#[cfg(test)]
|
|
#[path = "right_click_copy_tests.rs"]
|
|
mod right_click_copy_tests;
|