From 61319ed7dcf21d065d19357ec2ff43402d0ef295 Mon Sep 17 00:00:00 2001 From: ChangeCaps <42285338+ChangeCaps@users.noreply.github.com> Date: Sun, 15 Sep 2024 06:41:26 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20ChangeCa?= =?UTF-8?q?ps/ori@a617b5abefa309c8d10362d966e552b3138d8917=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ori/core/view/trait.View.html | 2 +- ori/core/views/struct.TextInput.html | 10 ++--- ori/prelude/struct.TextInput.html | 10 ++--- ori/prelude/trait.View.html | 2 +- ori_core/view/trait.View.html | 2 +- ori_core/views/struct.TextInput.html | 8 ++-- src/ori_core/views/text_input.rs.html | 54 ++++++++++++++++++++++++++- 7 files changed, 69 insertions(+), 19 deletions(-) diff --git a/ori/core/view/trait.View.html b/ori/core/view/trait.View.html index be0ede7f4..7a026f2a1 100644 --- a/ori/core/view/trait.View.html +++ b/ori/core/view/trait.View.html @@ -199,7 +199,7 @@ state: &mut <Result<V, E> as View<T>>::State, cx: &mut DrawCx<'_, '_>, data: &mut T, -)
Set the callback that is called when the input is submitted.
-Set the callback that is called when the input is submitted.
-Set the callback that is called when the input is submitted.
-use cosmic_text::{
Action, Attrs, AttrsList, Buffer, BufferLine, BufferRef, Edit, Editor, LineEnding, Metrics,
- Motion, Shaping,
+ Motion, Selection, Shaping,
};
use ori_macro::{example, Build, Styled};
@@ -928,6 +953,19 @@
text
}
+ fn ime(&self) -> Ime {
+ let selection = match self.editor.selection_bounds() {
+ Some((start, end)) => start.index..end.index,
+ None => self.editor.cursor().index..self.editor.cursor().index,
+ };
+
+ Ime {
+ text: self.text(),
+ selection,
+ compose: None,
+ }
+ }
+
fn clear_text(&mut self) {
self.buffer_mut().lines = vec![BufferLine::new(
"",
@@ -1140,6 +1178,15 @@
}
if let Some(action) = delete_key(e) {
+ // NOTE: this is a workaround for a bug where the editor can select nothing,
+ // and will then delete the selection rather than the character at the cursor
+ if let Some((start, end)) = state.editor.selection_bounds() {
+ if start == end {
+ state.editor.set_selection(Selection::None);
+ state.editor.set_cursor(start);
+ }
+ }
+
state.editor.action(&mut cx.fonts().font_system, action);
cx.layout();
state.blink = 0.0;
@@ -1216,6 +1263,8 @@
state.editor.set_cursor(cosmic_text::Cursor::default());
}
}
+
+ cx.set_ime(Some(state.ime()));
}
Event::PointerPressed(e) => {
if !cx.is_hovered() {
@@ -1230,7 +1279,6 @@
}
cx.set_focused(true);
- cx.set_ime(Some(Ime::default()));
cx.animate();
state.blink = 0.0;
@@ -1244,6 +1292,8 @@
y: local.y as i32,
},
);
+
+ cx.set_ime(Some(state.ime()));
}
Event::PointerReleased(_) => {
state.dragging = false;