Skip to content

Commit

Permalink
text view: Never reset IM context
Browse files Browse the repository at this point in the history
  • Loading branch information
bragefuglseth committed Jun 24, 2024
1 parent bdca1a7 commit 8eafac6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/widgets/text_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ mod imp {
fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
self.text_view.allocate(width, height, baseline, None);
self.update_scroll_position(true);
self.update_caret_position(true, false);
self.update_caret_position(true);
self.update_colors();
}

Expand All @@ -143,7 +143,7 @@ mod imp {
.buffer()
.set_text(&insert_replacements(&text));
self.update_colors();
self.update_caret_position(true, true);
self.update_caret_position(true);
self.update_scroll_position(true);
self.update_accessible_state();
}
Expand All @@ -156,9 +156,9 @@ mod imp {
self.update_colors();
}

pub(super) fn typed_text_changed(&self, preedit: bool) {
pub(super) fn typed_text_changed(&self) {
self.update_colors();
self.update_caret_position(!self.running.get(), !preedit);
self.update_caret_position(!self.running.get());
self.update_scroll_position(!self.running.get());
self.update_accessible_state();

Expand Down Expand Up @@ -191,7 +191,7 @@ impl KpTextView {

pub fn set_typed_text(&self, text: &str) {
*self.imp().typed_text.borrow_mut() = text.to_string();
self.imp().typed_text_changed(false);
self.imp().typed_text_changed();
self.imp().input_context.borrow().as_ref().unwrap().reset();
}

Expand Down
12 changes: 4 additions & 8 deletions src/widgets/text_view/caret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl imp::KpTextView {

// Calculates where the caret currently should be, and runs an animation to get it there.
// If `force` is true, the change will happen unconditionally and without an animation.
pub(super) fn update_caret_position(&self, force: bool, update_im_cursor: bool) {
pub(super) fn update_caret_position(&self, force: bool) {
let obj = self.obj();

let input_context = self.input_context.borrow();
Expand Down Expand Up @@ -133,13 +133,9 @@ impl imp::KpTextView {
caret_y_animation.play();

// Update virtual caret to accomodate software input methods (e.g. Pinyin)

if update_im_cursor {
if let Some(input_context) = &*self.input_context.borrow() {
let caret_rect = gdk::Rectangle::new(x, y, 1, pos.height());
input_context.set_cursor_location(&caret_rect);
input_context.reset();
}
if let Some(input_context) = &*self.input_context.borrow() {
let caret_rect = gdk::Rectangle::new(x, y, 1, pos.height());
input_context.set_cursor_location(&caret_rect);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/text_view/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl imp::KpTextView {
}

*imp.previous_preedit.borrow_mut() = preedit.to_string();
imp.typed_text_changed(true);
imp.typed_text_changed();
}

}));
Expand Down Expand Up @@ -112,13 +112,13 @@ impl imp::KpTextView {
self.typed_text.borrow_mut().push_str(&letter);
}

self.typed_text_changed(false);
self.typed_text_changed();
}

fn pop_typed_text(&self, graphemes: usize) {
pop_grapheme_in_place(&mut self.typed_text.borrow_mut(), graphemes);

self.typed_text_changed(false);
self.typed_text_changed();
}

fn pop_typed_text_word(&self) {
Expand All @@ -127,6 +127,6 @@ impl imp::KpTextView {
&mut self.typed_text.borrow_mut(),
);

self.typed_text_changed(false);
self.typed_text_changed();
}
}

0 comments on commit 8eafac6

Please sign in to comment.