use crate::editor::Cursor;
use crate::mode::Mode;
#[derive(Debug, Clone, Copy)]
pub enum Selection {
Char { from: Cursor, to: Cursor },
Line { from_row: usize, to_row: usize },
Block {
r0: usize,
c0: usize,
r1: usize,
c1: usize,
},
}
pub fn selection(mode: Mode, anchor: Option<Cursor>, cursor: Cursor) -> Option<Selection> {
let anchor = anchor?;
Some(match mode {
Mode::Visual => {
let (from, to) = if (anchor.row, anchor.col) <= (cursor.row, cursor.col) {
(anchor, cursor)
} else {
(cursor, anchor)
};
Selection::Char { from, to }
}
Mode::VisualLine => Selection::Line {
from_row: anchor.row.min(cursor.row),
to_row: anchor.row.max(cursor.row),
},
Mode::VisualBlock => Selection::Block {
r0: anchor.row.min(cursor.row),
c0: anchor.col.min(cursor.col),
r1: anchor.row.max(cursor.row),
c1: anchor.col.max(cursor.col),
},
_ => return None,
})
}