Added line range select and copy
CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-latest) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / release (macos-latest, aarch64-apple-darwin) (push) Canceled after 0s
CI / release (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Canceled after 0s
CI / release (windows-latest, x86_64-pc-windows-msvc) (push) Canceled after 0s
CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-latest) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / release (macos-latest, aarch64-apple-darwin) (push) Canceled after 0s
CI / release (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Canceled after 0s
CI / release (windows-latest, x86_64-pc-windows-msvc) (push) Canceled after 0s
This commit is contained in:
1 parent
0d94f2bf2e
commit
79f5f7dcea
2 files changed
+69
-7
No files matched your search
+67
-6
@@ -145,6 +145,8 @@ pub struct LogTab {
|
|||||||
width_changed_at: Option<Instant>,
|
width_changed_at: Option<Instant>,
|
||||||
pending_width: f32,
|
pending_width: f32,
|
||||||
selected: Option<u32>,
|
selected: Option<u32>,
|
||||||
|
/// The other end of a Shift+click range; `None` selects just `selected`.
|
||||||
|
sel_start: Option<u32>,
|
||||||
pending_jump: Option<PendingJump>,
|
pending_jump: Option<PendingJump>,
|
||||||
center_on_anchor: bool,
|
center_on_anchor: bool,
|
||||||
ensure_visible: Option<u32>,
|
ensure_visible: Option<u32>,
|
||||||
@@ -231,6 +233,7 @@ impl LogTab {
|
|||||||
width_changed_at: None,
|
width_changed_at: None,
|
||||||
pending_width: 0.0,
|
pending_width: 0.0,
|
||||||
selected: None,
|
selected: None,
|
||||||
|
sel_start: None,
|
||||||
pending_jump: None,
|
pending_jump: None,
|
||||||
center_on_anchor: false,
|
center_on_anchor: false,
|
||||||
ensure_visible: None,
|
ensure_visible: None,
|
||||||
@@ -288,6 +291,7 @@ impl LogTab {
|
|||||||
self.collapsed.clear();
|
self.collapsed.clear();
|
||||||
self.revealed.clear();
|
self.revealed.clear();
|
||||||
self.selected = None;
|
self.selected = None;
|
||||||
|
self.sel_start = None;
|
||||||
self.anchor = Anchor::default();
|
self.anchor = Anchor::default();
|
||||||
self.expand_version += 1;
|
self.expand_version += 1;
|
||||||
self.rowmap_key.0 = usize::MAX;
|
self.rowmap_key.0 = usize::MAX;
|
||||||
@@ -642,6 +646,7 @@ impl LogTab {
|
|||||||
let line = if self.is_expanded(entry) { line } else { 0 };
|
let line = if self.is_expanded(entry) { line } else { 0 };
|
||||||
self.anchor = Anchor { entry, line, px: 0.0 };
|
self.anchor = Anchor { entry, line, px: 0.0 };
|
||||||
self.selected = Some(entry);
|
self.selected = Some(entry);
|
||||||
|
self.sel_start = None;
|
||||||
self.center_on_anchor = expand;
|
self.center_on_anchor = expand;
|
||||||
self.rowmap_key.0 = usize::MAX;
|
self.rowmap_key.0 = usize::MAX;
|
||||||
}
|
}
|
||||||
@@ -772,6 +777,29 @@ impl LogTab {
|
|||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Visible positions `lo..=hi` of the selected entries.
|
||||||
|
fn selection_range(&self) -> Option<(usize, usize)> {
|
||||||
|
let end = self.visible.position(self.selected?)?;
|
||||||
|
let start = self.sel_start.and_then(|s| self.visible.position(s)).unwrap_or(end);
|
||||||
|
Some((start.min(end), start.max(end)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Full text of every selected entry that is shown, one after another.
|
||||||
|
fn selection_text(&self, idx: &EntryIndex) -> String {
|
||||||
|
let Some((lo, hi)) = self.selection_range() else { return String::new() };
|
||||||
|
let mut out = String::new();
|
||||||
|
for p in lo..=hi {
|
||||||
|
let e = self.visible.entry(p);
|
||||||
|
if (e as usize) < idx.len() {
|
||||||
|
if !out.is_empty() {
|
||||||
|
out.push('\n');
|
||||||
|
}
|
||||||
|
out.push_str(&self.entry_text(idx, e, 64 << 20));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
pub fn detail_text(&self, entry: u32) -> String {
|
pub fn detail_text(&self, entry: u32) -> String {
|
||||||
let idx = self.index.index.read().unwrap();
|
let idx = self.index.index.read().unwrap();
|
||||||
if entry as usize >= idx.len() {
|
if entry as usize >= idx.len() {
|
||||||
@@ -1147,10 +1175,12 @@ impl LogTab {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let page = (self.page_h - self.row_h).max(self.row_h);
|
let page = (self.page_h - self.row_h).max(self.row_h);
|
||||||
let (up, down, pgup, pgdn, home, end, left, right, space, copy) = ctx.input_mut(|i| {
|
let (up, down, shift_up, shift_down, pgup, pgdn, home, end, left, right, space, copy) = ctx.input_mut(|i| {
|
||||||
(
|
(
|
||||||
i.consume_key(Modifiers::NONE, Key::ArrowUp),
|
i.consume_key(Modifiers::NONE, Key::ArrowUp),
|
||||||
i.consume_key(Modifiers::NONE, Key::ArrowDown),
|
i.consume_key(Modifiers::NONE, Key::ArrowDown),
|
||||||
|
i.consume_key(Modifiers::SHIFT, Key::ArrowUp),
|
||||||
|
i.consume_key(Modifiers::SHIFT, Key::ArrowDown),
|
||||||
i.consume_key(Modifiers::NONE, Key::PageUp),
|
i.consume_key(Modifiers::NONE, Key::PageUp),
|
||||||
i.consume_key(Modifiers::NONE, Key::PageDown),
|
i.consume_key(Modifiers::NONE, Key::PageDown),
|
||||||
i.consume_key(cmd, Key::Home) || i.consume_key(Modifiers::NONE, Key::Home),
|
i.consume_key(cmd, Key::Home) || i.consume_key(Modifiers::NONE, Key::Home),
|
||||||
@@ -1163,7 +1193,10 @@ impl LogTab {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
if up || down {
|
if up || down {
|
||||||
self.move_selection(if down { 1 } else { -1 });
|
self.move_selection(if down { 1 } else { -1 }, false);
|
||||||
|
}
|
||||||
|
if shift_up || shift_down {
|
||||||
|
self.move_selection(if shift_down { 1 } else { -1 }, true);
|
||||||
}
|
}
|
||||||
if pgup {
|
if pgup {
|
||||||
self.scroll_px = -page;
|
self.scroll_px = -page;
|
||||||
@@ -1188,17 +1221,24 @@ impl LogTab {
|
|||||||
}
|
}
|
||||||
if copy {
|
if copy {
|
||||||
let idx = self.index.index.read().unwrap();
|
let idx = self.index.index.read().unwrap();
|
||||||
if (sel as usize) < idx.len() {
|
let text = self.selection_text(&idx);
|
||||||
ctx.copy_text(self.entry_text(&idx, sel, 64 << 20));
|
if !text.is_empty() {
|
||||||
|
ctx.copy_text(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_selection(&mut self, delta: i64) {
|
/// Moves the selection by `delta` entries; `extend` grows the range instead.
|
||||||
|
fn move_selection(&mut self, delta: i64, extend: bool) {
|
||||||
if self.visible.is_empty() {
|
if self.visible.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if !extend {
|
||||||
|
self.sel_start = None;
|
||||||
|
} else if self.sel_start.is_none() {
|
||||||
|
self.sel_start = self.selected;
|
||||||
|
}
|
||||||
let cur = match self.selected.and_then(|s| self.visible.position(s)) {
|
let cur = match self.selected.and_then(|s| self.visible.position(s)) {
|
||||||
Some(p) => p as i64 + delta,
|
Some(p) => p as i64 + delta,
|
||||||
None => self.visible.nearest_position(self.anchor.entry) as i64,
|
None => self.visible.nearest_position(self.anchor.entry) as i64,
|
||||||
@@ -1406,6 +1446,8 @@ impl LogTab {
|
|||||||
let mut r = row;
|
let mut r = row;
|
||||||
let mut max_w = 0.0f32;
|
let mut max_w = 0.0f32;
|
||||||
let mut clicked_row: Option<(u32, bool)> = None;
|
let mut clicked_row: Option<(u32, bool)> = None;
|
||||||
|
let sel_range = self.selection_range();
|
||||||
|
let shift = ui.input(|i| i.modifiers.shift);
|
||||||
let mut toggle: Option<u32> = None;
|
let mut toggle: Option<u32> = None;
|
||||||
while y < view.bottom() && r < total {
|
while y < view.bottom() && r < total {
|
||||||
let Some(p) = self.rowmap.locate(r) else { break };
|
let Some(p) = self.rowmap.locate(r) else { break };
|
||||||
@@ -1418,7 +1460,8 @@ impl LogTab {
|
|||||||
if let Some(tint) = self.entry_tint(&idx, entry) {
|
if let Some(tint) = self.entry_tint(&idx, entry) {
|
||||||
painter.rect_filled(row_rect, 0.0, tint);
|
painter.rect_filled(row_rect, 0.0, tint);
|
||||||
}
|
}
|
||||||
if self.selected == Some(entry) {
|
let in_sel = sel_range.is_some_and(|(lo, hi)| (lo..=hi).contains(&p.vpos));
|
||||||
|
if in_sel {
|
||||||
painter.rect_filled(row_rect, 0.0, sel_fill);
|
painter.rect_filled(row_rect, 0.0, sel_fill);
|
||||||
}
|
}
|
||||||
if gutter_numbers {
|
if gutter_numbers {
|
||||||
@@ -1471,8 +1514,19 @@ impl LogTab {
|
|||||||
clicked_row = Some((entry, true));
|
clicked_row = Some((entry, true));
|
||||||
}
|
}
|
||||||
let (ls, le) = self.line_range(&idx, entry, p.line);
|
let (ls, le) = self.line_range(&idx, entry, p.line);
|
||||||
|
let multi = in_sel && sel_range.is_some_and(|(lo, hi)| hi > lo);
|
||||||
resp.context_menu(|ui| {
|
resp.context_menu(|ui| {
|
||||||
|
if !in_sel {
|
||||||
self.selected = Some(entry);
|
self.selected = Some(entry);
|
||||||
|
self.sel_start = None;
|
||||||
|
}
|
||||||
|
if multi && let Some((lo, hi)) = sel_range {
|
||||||
|
if ui.button(format!("Copy {} selected entries", fmt_num((hi - lo + 1) as u64))).clicked() {
|
||||||
|
ui.ctx().copy_text(self.selection_text(&idx));
|
||||||
|
ui.close();
|
||||||
|
}
|
||||||
|
ui.separator();
|
||||||
|
}
|
||||||
if ui.button("Copy line").clicked() {
|
if ui.button("Copy line").clicked() {
|
||||||
ui.ctx().copy_text(String::from_utf8_lossy(&self.bytes()[ls..le]).into_owned());
|
ui.ctx().copy_text(String::from_utf8_lossy(&self.bytes()[ls..le]).into_owned());
|
||||||
ui.close();
|
ui.close();
|
||||||
@@ -1521,6 +1575,11 @@ impl LogTab {
|
|||||||
ui.memory_mut(|m| m.surrender_focus(id));
|
ui.memory_mut(|m| m.surrender_focus(id));
|
||||||
}
|
}
|
||||||
if let Some((e, dbl)) = clicked_row {
|
if let Some((e, dbl)) = clicked_row {
|
||||||
|
if !shift {
|
||||||
|
self.sel_start = None;
|
||||||
|
} else if self.sel_start.is_none() {
|
||||||
|
self.sel_start = self.selected.or(Some(e));
|
||||||
|
}
|
||||||
self.selected = Some(e);
|
self.selected = Some(e);
|
||||||
if dbl {
|
if dbl {
|
||||||
toggle = Some(e);
|
toggle = Some(e);
|
||||||
@@ -1535,8 +1594,10 @@ impl LogTab {
|
|||||||
if let Some(e) = toggle {
|
if let Some(e) = toggle {
|
||||||
let open = self.is_expanded(e);
|
let open = self.is_expanded(e);
|
||||||
self.set_expanded(e, !open);
|
self.set_expanded(e, !open);
|
||||||
|
if self.selection_range().is_none_or(|(lo, hi)| lo == hi) {
|
||||||
self.selected = Some(e);
|
self.selected = Some(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Horizontal extent and scrollbar (wrap off).
|
// Horizontal extent and scrollbar (wrap off).
|
||||||
if !self.wrap {
|
if !self.wrap {
|
||||||
|
|||||||
+2
-1
@@ -316,7 +316,8 @@ impl App {
|
|||||||
("Up / Down", "Select entry"),
|
("Up / Down", "Select entry"),
|
||||||
("Space / Right", "Expand entry"),
|
("Space / Right", "Expand entry"),
|
||||||
("Left", "Collapse entry"),
|
("Left", "Collapse entry"),
|
||||||
("Ctrl/Cmd+C", "Copy selected entry"),
|
("Shift+Click / Shift+Up / Down", "Select a range of entries"),
|
||||||
|
("Ctrl/Cmd+C", "Copy selected entries"),
|
||||||
("PageUp / PageDown", "Scroll a page"),
|
("PageUp / PageDown", "Scroll a page"),
|
||||||
("Home / End", "Start / end of file"),
|
("Home / End", "Start / end of file"),
|
||||||
] {
|
] {
|
||||||
|
|||||||
Reference in new issue
Block a user