Use a RangeInclusive
for text selection.
This commit is contained in:
parent
875d3a650d
commit
68499cebf6
2 changed files with 14 additions and 26 deletions
|
@ -249,10 +249,8 @@ pub struct WidgetInfo {
|
|||
pub selected: Option<bool>,
|
||||
/// The current value of sliders etc.
|
||||
pub value: Option<f64>,
|
||||
// Location of primary cursor.
|
||||
pub primary_cursor: Option<usize>,
|
||||
// Location of secondary cursor.
|
||||
pub secondary_cursor: Option<usize>,
|
||||
// Selected range of characters in [`Self::current_text_value`].
|
||||
pub text_selection: Option<std::ops::RangeInclusive<usize>>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for WidgetInfo {
|
||||
|
@ -265,8 +263,7 @@ impl std::fmt::Debug for WidgetInfo {
|
|||
prev_text_value,
|
||||
selected,
|
||||
value,
|
||||
primary_cursor,
|
||||
secondary_cursor,
|
||||
text_selection,
|
||||
} = self;
|
||||
|
||||
let mut s = f.debug_struct("WidgetInfo");
|
||||
|
@ -289,11 +286,8 @@ impl std::fmt::Debug for WidgetInfo {
|
|||
if let Some(value) = value {
|
||||
s.field("value", value);
|
||||
}
|
||||
if let Some(primary_cursor) = primary_cursor {
|
||||
s.field("primary_cursor", primary_cursor);
|
||||
}
|
||||
if let Some(secondary_cursor) = secondary_cursor {
|
||||
s.field("secondary_cursor", secondary_cursor);
|
||||
if let Some(text_selection) = text_selection {
|
||||
s.field("text_selection", text_selection);
|
||||
}
|
||||
|
||||
s.finish()
|
||||
|
@ -310,8 +304,7 @@ impl WidgetInfo {
|
|||
prev_text_value: None,
|
||||
selected: None,
|
||||
value: None,
|
||||
primary_cursor: None,
|
||||
secondary_cursor: None,
|
||||
text_selection: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -361,14 +354,12 @@ impl WidgetInfo {
|
|||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn text_selection_changed(
|
||||
primary_cursor: usize,
|
||||
secondary_cursor: usize,
|
||||
text_value: impl ToString,
|
||||
text_selection: std::ops::RangeInclusive<usize>,
|
||||
current_text_value: impl ToString,
|
||||
) -> Self {
|
||||
Self {
|
||||
primary_cursor: Some(primary_cursor),
|
||||
secondary_cursor: Some(secondary_cursor),
|
||||
current_text_value: Some(text_value.to_string()),
|
||||
text_selection: Some(text_selection),
|
||||
current_text_value: Some(current_text_value.to_string()),
|
||||
..Self::new(WidgetType::TextEdit)
|
||||
}
|
||||
}
|
||||
|
@ -383,8 +374,7 @@ impl WidgetInfo {
|
|||
prev_text_value: _,
|
||||
selected,
|
||||
value,
|
||||
primary_cursor: _,
|
||||
secondary_cursor: _,
|
||||
text_selection: _,
|
||||
} = self;
|
||||
|
||||
// TODO: localization
|
||||
|
|
|
@ -663,11 +663,9 @@ impl<'t> TextEdit<'t> {
|
|||
if response.changed {
|
||||
response.widget_info(|| WidgetInfo::text_edit(&*text, &*prev_text));
|
||||
} else if let Some(text_cursor) = text_cursor {
|
||||
let info = WidgetInfo::text_selection_changed(
|
||||
text_cursor.primary.ccursor.index,
|
||||
text_cursor.secondary.ccursor.index,
|
||||
&*text,
|
||||
);
|
||||
let char_range =
|
||||
text_cursor.primary.ccursor.index..=text_cursor.secondary.ccursor.index;
|
||||
let info = WidgetInfo::text_selection_changed(char_range, &*text);
|
||||
response
|
||||
.ctx
|
||||
.output()
|
||||
|
|
Loading…
Reference in a new issue