feat: swap cursor start/end if needed when sending

This commit is contained in:
əlemi 2023-09-10 23:20:07 +02:00
parent ed151e2213
commit 5812dea19a
2 changed files with 15 additions and 1 deletions

View file

@ -50,7 +50,11 @@ impl Controller<CursorEvent> for CursorController {
type Input = CursorPosition; type Input = CursorPosition;
/// enqueue a cursor event to be broadcast to current workspace /// enqueue a cursor event to be broadcast to current workspace
fn send(&self, cursor: CursorPosition) -> Result<(), Error> { /// will automatically invert cursor start/end if they are inverted
fn send(&self, mut cursor: CursorPosition) -> Result<(), Error> {
if cursor.start() < cursor.end() {
std::mem::swap(&mut cursor.start, &mut cursor.end);
}
Ok(self.op.send(CursorEvent { Ok(self.op.send(CursorEvent {
user: self.uid.clone(), user: self.uid.clone(),
position: Some(cursor), position: Some(cursor),

View file

@ -37,3 +37,13 @@ impl CursorPosition {
self.end.clone().unwrap_or((0, 0).into()) self.end.clone().unwrap_or((0, 0).into())
} }
} }
impl PartialOrd for RowCol {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
match self.row.partial_cmp(&other.row) {
Some(core::cmp::Ordering::Equal) => {}
ord => return ord,
}
self.col.partial_cmp(&other.col)
}
}