feat: toggle wrapping in shell output windows

This commit is contained in:
2026-10-18 01:23:19 +02:00
parent 00207b5526
commit 074df97c02
4 changed files with 125 additions and 23 deletions
+30 -4
View File
@@ -140,6 +140,9 @@ pub struct StartupDiagnostic {
pub(crate) struct ShellOutput {
pub(crate) title: String,
pub(crate) content: StartupDiagnostic,
pub(crate) wrapping: bool,
pub(crate) wrapped_rows: Cell<usize>,
pub(crate) wrapped_lines: std::cell::RefCell<(usize, Vec<(usize, crate::wrap::Segment)>)>,
}
pub struct Hover {
@@ -6992,6 +6995,9 @@ impl Editor {
.collect();
self.command_output = Some(ShellOutput {
title: format!("{status} · !{command}"),
wrapping: false,
wrapped_rows: Cell::new(1),
wrapped_lines: Default::default(),
content: StartupDiagnostic {
lines,
top: 0,
@@ -7002,25 +7008,45 @@ impl Editor {
}
fn handle_command_output(&mut self, input: &Input) -> bool {
let toggle = input == &Input::Char('w')
|| matches!(
self.bindings
.get(&self.binding_mode())
.and_then(|keys| keys.get(input)),
Some(Binding::Action(Action::WordWrapToggle))
);
let Some(output) = &mut self.command_output else {
return false;
};
if toggle {
output.wrapping = !output.wrapping;
output.content.top = 0;
output.content.left = 0;
return true;
}
let rows = if output.wrapping {
output.wrapped_rows.get()
} else {
output.content.lines.len()
};
let content = &mut output.content;
match input {
Input::Escape | Input::Enter => self.command_output = None,
Input::Up | Input::Ctrl('k') => content.top = content.top.saturating_sub(1),
Input::Down | Input::Ctrl('j') => {
content.top = content.top.saturating_add(1).min(content.lines.len() - 1);
content.top = content.top.saturating_add(1).min(rows.saturating_sub(1));
}
Input::Left | Input::Ctrl('h') => content.left = content.left.saturating_sub(1),
Input::Right | Input::Ctrl('l') => {
Input::Left | Input::Ctrl('h') if !output.wrapping => {
content.left = content.left.saturating_sub(1)
}
Input::Right | Input::Ctrl('l') if !output.wrapping => {
content.left = content.left.saturating_add(1).min(content.max_column);
}
Input::Home => {
content.top = 0;
content.left = 0;
}
Input::End => content.top = content.lines.len() - 1,
Input::End => content.top = rows.saturating_sub(1),
_ => {}
}
true