mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-22 15:24:48 +01:00
feat: swap cursor start/end if needed when sending
This commit is contained in:
parent
ed151e2213
commit
5812dea19a
2 changed files with 15 additions and 1 deletions
|
@ -50,7 +50,11 @@ impl Controller<CursorEvent> for CursorController {
|
|||
type Input = CursorPosition;
|
||||
|
||||
/// 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 {
|
||||
user: self.uid.clone(),
|
||||
position: Some(cursor),
|
||||
|
|
|
@ -37,3 +37,13 @@ impl CursorPosition {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue