mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 23:21:08 +03:00
termwiz: don't claim that visible_cells is double-ended
It's not; there's important state that only works in forward iteration.
This commit is contained in:
parent
7be01110ca
commit
c2dfba27f3
@ -883,7 +883,7 @@ impl Line {
|
|||||||
/// the characters that follow wide characters, the column index may
|
/// the characters that follow wide characters, the column index may
|
||||||
/// skip some positions. It is returned as a convenience to the consumer
|
/// skip some positions. It is returned as a convenience to the consumer
|
||||||
/// as using .enumerate() on this iterator wouldn't be as useful.
|
/// as using .enumerate() on this iterator wouldn't be as useful.
|
||||||
pub fn visible_cells<'a>(&'a self) -> impl DoubleEndedIterator<Item = CellRef<'a>> {
|
pub fn visible_cells<'a>(&'a self) -> impl Iterator<Item = CellRef<'a>> {
|
||||||
match &self.cells {
|
match &self.cells {
|
||||||
CellStorage::V(cells) => VisibleCellIter::V(CellSliceIter {
|
CellStorage::V(cells) => VisibleCellIter::V(CellSliceIter {
|
||||||
cells: cells.iter(),
|
cells: cells.iter(),
|
||||||
@ -1151,40 +1151,20 @@ struct CellSliceIter<'a> {
|
|||||||
skip_width: usize,
|
skip_width: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CellSliceIter<'a> {
|
|
||||||
fn advance(&mut self, forwards: bool) -> Option<CellRef<'a>> {
|
|
||||||
while self.skip_width > 0 {
|
|
||||||
self.skip_width -= 1;
|
|
||||||
let _ = if forwards {
|
|
||||||
self.cells.next()
|
|
||||||
} else {
|
|
||||||
self.cells.next_back()
|
|
||||||
}?;
|
|
||||||
self.idx += 1;
|
|
||||||
}
|
|
||||||
let cell = if forwards {
|
|
||||||
self.cells.next()
|
|
||||||
} else {
|
|
||||||
self.cells.next_back()
|
|
||||||
}?;
|
|
||||||
let cell_index = self.idx;
|
|
||||||
self.idx += 1;
|
|
||||||
self.skip_width = cell.width().saturating_sub(1);
|
|
||||||
Some(CellRef::CellRef { cell_index, cell })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for CellSliceIter<'a> {
|
impl<'a> Iterator for CellSliceIter<'a> {
|
||||||
type Item = CellRef<'a>;
|
type Item = CellRef<'a>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<CellRef<'a>> {
|
fn next(&mut self) -> Option<CellRef<'a>> {
|
||||||
self.advance(true)
|
while self.skip_width > 0 {
|
||||||
}
|
self.skip_width -= 1;
|
||||||
}
|
let _ = self.cells.next()?;
|
||||||
|
self.idx += 1;
|
||||||
impl<'a> DoubleEndedIterator for CellSliceIter<'a> {
|
}
|
||||||
fn next_back(&mut self) -> Option<CellRef<'a>> {
|
let cell = self.cells.next()?;
|
||||||
self.advance(false)
|
let cell_index = self.idx;
|
||||||
|
self.idx += 1;
|
||||||
|
self.skip_width = cell.width().saturating_sub(1);
|
||||||
|
Some(CellRef::CellRef { cell_index, cell })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1204,15 +1184,6 @@ impl<'a> Iterator for VisibleCellIter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DoubleEndedIterator for VisibleCellIter<'a> {
|
|
||||||
fn next_back(&mut self) -> Option<CellRef<'a>> {
|
|
||||||
match self {
|
|
||||||
Self::V(iter) => iter.next_back(),
|
|
||||||
Self::C(iter) => iter.next_back(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum CellRef<'a> {
|
pub enum CellRef<'a> {
|
||||||
CellRef {
|
CellRef {
|
||||||
@ -1529,13 +1500,11 @@ pub struct ClusterLineCellIter<'a> {
|
|||||||
line: &'a ClusteredLine,
|
line: &'a ClusteredLine,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ClusterLineCellIter<'a> {
|
impl<'a> Iterator for ClusterLineCellIter<'a> {
|
||||||
fn advance(&mut self, forwards: bool) -> Option<CellRef<'a>> {
|
type Item = CellRef<'a>;
|
||||||
let text = if forwards {
|
|
||||||
self.graphemes.next()?
|
fn next(&mut self) -> Option<CellRef<'a>> {
|
||||||
} else {
|
let text = self.graphemes.next()?;
|
||||||
self.graphemes.next_back()?
|
|
||||||
};
|
|
||||||
|
|
||||||
let cell_index = self.idx;
|
let cell_index = self.idx;
|
||||||
let width = if self.line.is_double_wide(cell_index) {
|
let width = if self.line.is_double_wide(cell_index) {
|
||||||
@ -1548,11 +1517,7 @@ impl<'a> ClusterLineCellIter<'a> {
|
|||||||
let attrs = &self.cluster.as_ref()?.attrs;
|
let attrs = &self.cluster.as_ref()?.attrs;
|
||||||
|
|
||||||
if self.cluster_total >= self.cluster.as_ref()?.cell_width {
|
if self.cluster_total >= self.cluster.as_ref()?.cell_width {
|
||||||
self.cluster = if forwards {
|
self.cluster = self.clusters.next();
|
||||||
self.clusters.next()
|
|
||||||
} else {
|
|
||||||
self.clusters.next_back()
|
|
||||||
};
|
|
||||||
self.cluster_total = 0;
|
self.cluster_total = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1565,20 +1530,6 @@ impl<'a> ClusterLineCellIter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for ClusterLineCellIter<'a> {
|
|
||||||
type Item = CellRef<'a>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<CellRef<'a>> {
|
|
||||||
self.advance(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> DoubleEndedIterator for ClusterLineCellIter<'a> {
|
|
||||||
fn next_back(&mut self) -> Option<CellRef<'a>> {
|
|
||||||
self.advance(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -577,10 +577,9 @@ impl CopyRenderable {
|
|||||||
if let Some(line) = lines.get(0) {
|
if let Some(line) = lines.get(0) {
|
||||||
self.cursor.y = top;
|
self.cursor.y = top;
|
||||||
self.cursor.x = 0;
|
self.cursor.x = 0;
|
||||||
for cell in line.visible_cells().rev() {
|
for cell in line.visible_cells() {
|
||||||
if cell.str() != " " {
|
if cell.str() != " " {
|
||||||
self.cursor.x = cell.cell_index();
|
self.cursor.x = cell.cell_index();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user