collab-common 0.0.7

Code shared by collab's client and server
Documentation
use serde::{Deserialize, Serialize};

use crate::{Cursor, FileId};

/// TODO: docs
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CursorMoved {
    cursor: Cursor,
    file: FileId,
}

impl CursorMoved {
    /// Returns the new [`Cursor`].
    #[inline(always)]
    pub fn cursor(&self) -> Cursor {
        self.cursor
    }

    /// Returns the [`FileId`] of the file the cursor was moved in.
    ///
    /// This can be used to determine if the cursor was moved within the same
    /// file or if it was moved to another file in the project.
    ///
    /// The returned `FileId` is always of a file whose
    /// [`FileKind`](crate::FileKind) is
    /// [`Document`](crate::FileKind::Document), never
    /// [`Directory`](crate::FileKind::Directory).
    #[inline(always)]
    pub fn file(&self) -> FileId {
        self.file
    }

    /// Creates a new `CursorMoved` message.
    #[cfg(feature = "__client")]
    #[inline(always)]
    pub fn new(cursor: Cursor, file: FileId) -> Self {
        Self { cursor, file }
    }
}