small QOL
This commit is contained in:
@@ -12,17 +12,23 @@ pub struct TextEdit<State> {
|
||||
selection: TextSelection,
|
||||
history: Vec<(String, TextSelection)>,
|
||||
double_hit: Option<Cursor>,
|
||||
pub single_line: bool,
|
||||
pub mode: EditMode,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum EditMode {
|
||||
SingleLine,
|
||||
MultiLine,
|
||||
}
|
||||
|
||||
impl<State: 'static> TextEdit<State> {
|
||||
pub fn new(view: TextView<State>, single_line: bool) -> Self {
|
||||
pub fn new(view: TextView<State>, mode: EditMode) -> Self {
|
||||
Self {
|
||||
view,
|
||||
selection: Default::default(),
|
||||
history: Default::default(),
|
||||
double_hit: None,
|
||||
single_line,
|
||||
mode,
|
||||
}
|
||||
}
|
||||
pub fn select_content(&self, start: Cursor, end: Cursor) -> String {
|
||||
@@ -246,7 +252,7 @@ impl<'a, State: 'static> TextEditCtx<'a, State> {
|
||||
}
|
||||
|
||||
fn string(&self, text: &str) -> String {
|
||||
if self.text.single_line {
|
||||
if self.text.mode == EditMode::SingleLine {
|
||||
text.replace('\n', "")
|
||||
} else {
|
||||
text.to_string()
|
||||
@@ -315,7 +321,7 @@ impl<'a, State: 'static> TextEditCtx<'a, State> {
|
||||
}
|
||||
|
||||
pub fn newline(&mut self) {
|
||||
if self.text.single_line {
|
||||
if self.text.mode == EditMode::SingleLine {
|
||||
return;
|
||||
}
|
||||
self.clear_span();
|
||||
|
||||
Reference in New Issue
Block a user