use crate::{
grid::config::Position,
grid::records::{ExactRecords, PeekableRecords, Records, RecordsMut},
settings::TableOption,
};
#[derive(Debug, Default, Clone)]
pub struct TabSize(usize);
impl TabSize {
pub fn new(size: usize) -> Self {
Self(size)
}
}
impl<R, D, C> TableOption<R, C, D> for TabSize
where
R: Records + ExactRecords + RecordsMut<String> + PeekableRecords,
{
fn change(self, records: &mut R, _: &mut C, _: &mut D) {
let tab_size = self.0;
for row in 0..records.count_rows() {
for col in 0..records.count_columns() {
let pos = Position::new(row, col);
let text = records.get_text(pos);
let text = text.replace('\t', &" ".repeat(tab_size));
records.set(pos, text);
}
}
}
}