diff --git a/mux/src/pane.rs b/mux/src/pane.rs index 62070eb50..fe32a28ad 100644 --- a/mux/src/pane.rs +++ b/mux/src/pane.rs @@ -172,6 +172,12 @@ pub trait Pane: Downcast { fn get_logical_lines(&self, lines: Range) -> Vec { let (mut first, mut phys) = self.get_lines(lines); + // Avoid pathological cases where we have eg: a really long logical line + // (such as 1.5MB of json) that we previously wrapped. We don't want to + // un-wrap, scan, and re-wrap that thing. + // This is an imperfect length constraint to partially manage the cost. + const MAX_LOGICAL_LINE_LEN: usize = 1024; + // Look backwards to find the start of the first logical line while first > 0 { let (prior, back) = self.get_lines(first - 1..first); @@ -181,6 +187,9 @@ pub trait Pane: Downcast { if !back[0].last_cell_was_wrapped() { break; } + if back[0].cells().len() > MAX_LOGICAL_LINE_LEN { + break; + } first = prior; for (idx, line) in back.into_iter().enumerate() { phys.insert(idx, line); @@ -192,6 +201,9 @@ pub trait Pane: Downcast { if !last.last_cell_was_wrapped() { break; } + if last.cells().len() > MAX_LOGICAL_LINE_LEN { + break; + } let next_row = first + phys.len() as StableRowIndex; let (last_row, mut ahead) = self.get_lines(next_row..next_row + 1); @@ -214,7 +226,9 @@ pub trait Pane: Downcast { }); } Some(prior) => { - if prior.logical.last_cell_was_wrapped() { + if prior.logical.last_cell_was_wrapped() + && prior.logical.cells().len() <= MAX_LOGICAL_LINE_LEN + { prior.logical.set_last_cell_was_wrapped(false); prior.logical.append_line(line.clone()); prior.physical_lines.push(line);