mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 15:20:05 -04:00
Fix: dragging to above/below a TextEdit or Label will select text to begin/end (#3858)
This also adds a `Galley::begin` method to match `Galley::end` (both returning cursor positions). * Part of https://github.com/emilk/egui/issues/3816
This commit is contained in:
@@ -38,7 +38,7 @@ impl CursorRange {
|
||||
|
||||
/// Select all the text in a galley
|
||||
pub fn select_all(galley: &Galley) -> Self {
|
||||
Self::two(Cursor::default(), galley.end())
|
||||
Self::two(galley.begin(), galley.end())
|
||||
}
|
||||
|
||||
pub fn as_ccursor_range(&self) -> CCursorRange {
|
||||
@@ -342,7 +342,7 @@ fn move_single_cursor(
|
||||
Key::ArrowUp => {
|
||||
if modifiers.command {
|
||||
// mac and windows behavior
|
||||
*cursor = Cursor::default();
|
||||
*cursor = galley.begin();
|
||||
} else {
|
||||
*cursor = galley.cursor_up_one_row(cursor);
|
||||
}
|
||||
@@ -359,7 +359,7 @@ fn move_single_cursor(
|
||||
Key::Home => {
|
||||
if modifiers.ctrl {
|
||||
// windows behavior
|
||||
*cursor = Cursor::default();
|
||||
*cursor = galley.begin();
|
||||
} else {
|
||||
*cursor = galley.cursor_begin_of_row(cursor);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,27 @@ pub struct TextCursorState {
|
||||
ccursor_range: Option<CCursorRange>,
|
||||
}
|
||||
|
||||
impl From<CursorRange> for TextCursorState {
|
||||
fn from(cursor_range: CursorRange) -> Self {
|
||||
Self {
|
||||
cursor_range: Some(cursor_range),
|
||||
ccursor_range: Some(CCursorRange {
|
||||
primary: cursor_range.primary.ccursor,
|
||||
secondary: cursor_range.secondary.ccursor,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CCursorRange> for TextCursorState {
|
||||
fn from(ccursor_range: CCursorRange) -> Self {
|
||||
Self {
|
||||
cursor_range: None,
|
||||
ccursor_range: Some(ccursor_range),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TextCursorState {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.cursor_range.is_none() && self.ccursor_range.is_none()
|
||||
@@ -33,7 +54,7 @@ impl TextCursorState {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn range(&mut self, galley: &Galley) -> Option<CursorRange> {
|
||||
pub fn range(&self, galley: &Galley) -> Option<CursorRange> {
|
||||
self.cursor_range
|
||||
.map(|cursor_range| {
|
||||
// We only use the PCursor (paragraph number, and character offset within that paragraph).
|
||||
|
||||
Reference in New Issue
Block a user