mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Use strongly typed CharIndex and ByteIndex + bug fixes (#8245)
Less risk of confusing the two. Found and fix a couple real bugs in the process! --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
//! Different types of text cursors, i.e. ways to point into a [`super::Galley`].
|
||||
|
||||
use super::index::CharIndex;
|
||||
|
||||
/// Character cursor.
|
||||
///
|
||||
/// The default cursor is zero.
|
||||
@@ -7,7 +9,7 @@
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub struct CCursor {
|
||||
/// Character offset (NOT byte offset!).
|
||||
pub index: usize,
|
||||
pub index: CharIndex,
|
||||
|
||||
/// If this cursors sits right at the border of a wrapped row break (NOT paragraph break)
|
||||
/// do we prefer the next row?
|
||||
@@ -18,9 +20,9 @@ pub struct CCursor {
|
||||
|
||||
impl CCursor {
|
||||
#[inline]
|
||||
pub fn new(index: usize) -> Self {
|
||||
pub fn new(index: impl Into<CharIndex>) -> Self {
|
||||
Self {
|
||||
index,
|
||||
index: index.into(),
|
||||
prefer_next_row: false,
|
||||
}
|
||||
}
|
||||
@@ -83,5 +85,5 @@ pub struct LayoutCursor {
|
||||
/// Character based (NOT bytes).
|
||||
/// It is fine if this points to something beyond the end of the current row.
|
||||
/// When moving up/down it may again be within the next row.
|
||||
pub column: usize,
|
||||
pub column: CharIndex,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user