TextEdit option cursor_at_end to control initial position of cursor at beginning or end. (#687)
This commit is contained in:
parent
56502fbb3c
commit
931c3a9b6a
1 changed files with 19 additions and 1 deletions
|
@ -237,6 +237,7 @@ pub struct TextEdit<'t, S: TextBuffer = String> {
|
||||||
desired_width: Option<f32>,
|
desired_width: Option<f32>,
|
||||||
desired_height_rows: usize,
|
desired_height_rows: usize,
|
||||||
lock_focus: bool,
|
lock_focus: bool,
|
||||||
|
cursor_at_end: bool,
|
||||||
}
|
}
|
||||||
impl<'t, S: TextBuffer> TextEdit<'t, S> {
|
impl<'t, S: TextBuffer> TextEdit<'t, S> {
|
||||||
pub fn cursor(ui: &Ui, id: Id) -> Option<CursorPair> {
|
pub fn cursor(ui: &Ui, id: Id) -> Option<CursorPair> {
|
||||||
|
@ -264,6 +265,7 @@ impl<'t, S: TextBuffer> TextEdit<'t, S> {
|
||||||
desired_width: None,
|
desired_width: None,
|
||||||
desired_height_rows: 1,
|
desired_height_rows: 1,
|
||||||
lock_focus: false,
|
lock_focus: false,
|
||||||
|
cursor_at_end: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +285,7 @@ impl<'t, S: TextBuffer> TextEdit<'t, S> {
|
||||||
desired_width: None,
|
desired_width: None,
|
||||||
desired_height_rows: 4,
|
desired_height_rows: 4,
|
||||||
lock_focus: false,
|
lock_focus: false,
|
||||||
|
cursor_at_end: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,6 +372,14 @@ impl<'t, S: TextBuffer> TextEdit<'t, S> {
|
||||||
self.lock_focus = b;
|
self.lock_focus = b;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// When `true` (default), the cursor will initially be placed at the end of the text.
|
||||||
|
///
|
||||||
|
/// When `false`, the cursor will initially be placed at the beginning of the text.
|
||||||
|
pub fn cursor_at_end(mut self, b: bool) -> Self {
|
||||||
|
self.cursor_at_end = b;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'t, S: TextBuffer> Widget for TextEdit<'t, S> {
|
impl<'t, S: TextBuffer> Widget for TextEdit<'t, S> {
|
||||||
|
@ -438,6 +449,7 @@ impl<'t, S: TextBuffer> TextEdit<'t, S> {
|
||||||
desired_width,
|
desired_width,
|
||||||
desired_height_rows,
|
desired_height_rows,
|
||||||
lock_focus,
|
lock_focus,
|
||||||
|
cursor_at_end,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let mask_if_password = |text: &str| {
|
let mask_if_password = |text: &str| {
|
||||||
|
@ -569,7 +581,13 @@ impl<'t, S: TextBuffer> TextEdit<'t, S> {
|
||||||
secondary: galley.from_pcursor(cursorp.secondary.pcursor),
|
secondary: galley.from_pcursor(cursorp.secondary.pcursor),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| CursorPair::one(galley.end()));
|
.unwrap_or_else(|| {
|
||||||
|
if cursor_at_end {
|
||||||
|
CursorPair::one(galley.end())
|
||||||
|
} else {
|
||||||
|
CursorPair::default()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// We feed state to the undoer both before and after handling input
|
// We feed state to the undoer both before and after handling input
|
||||||
// so that the undoer creates automatic saves even when there are no events for a while.
|
// so that the undoer creates automatic saves even when there are no events for a while.
|
||||||
|
|
Loading…
Reference in a new issue