Browse Source

message-toolbar: Fix inserting mention before another mention

fractal-11
Kévin Commaille 10 months ago
parent
commit
1935d564d4
No known key found for this signature in database
GPG Key ID: F26F4BE20A08255B
  1. 25
      src/session/view/content/room_history/message_toolbar/composer_state.rs

25
src/session/view/content/room_history/message_toolbar/composer_state.rs

@ -236,18 +236,19 @@ mod imp {
/// Add the given widget at the position of the given iter to this
/// state.
pub(super) fn add_widget(&self, widget: impl IsA<gtk::Widget>, iter: &mut gtk::TextIter) {
let widget = widget.upcast();
let anchor = match iter.child_anchor() {
Some(anchor) => anchor,
None => self.buffer.create_child_anchor(iter),
pub(super) fn add_widget(&self, widget: gtk::Widget, iter: &mut gtk::TextIter) {
let Some(view) = self.view.upgrade() else {
return;
};
if let Some(view) = self.view.upgrade() {
view.add_child_at_anchor(&widget, &anchor);
}
// Reuse the child anchor at the iter if it does not have a child widget,
// otherwise create a new one.
let anchor = iter
.child_anchor()
.filter(|anchor| self.widget_at_anchor(anchor).is_none())
.unwrap_or_else(|| self.buffer.create_child_anchor(iter));
view.add_child_at_anchor(&widget, &anchor);
self.widgets.borrow_mut().push((widget, anchor));
}
@ -311,7 +312,7 @@ mod imp {
match DraftMention::new(&room, &text[content_start..content_end]) {
DraftMention::Source(source) => {
self.add_widget(source.to_pill(), &mut end_iter);
self.add_widget(source.to_pill().upcast(), &mut end_iter);
}
DraftMention::Text(s) => {
self.buffer.insert(&mut end_iter, s);
@ -410,7 +411,7 @@ mod imp {
self.buffer.insert(&mut iter, &text[pos..start]);
}
self.add_widget(pill, &mut iter);
self.add_widget(pill.upcast(), &mut iter);
pos = end;
}
@ -489,7 +490,7 @@ impl ComposerState {
/// Add the given widget at the position of the given iter to this state.
pub(crate) fn add_widget(&self, widget: impl IsA<gtk::Widget>, iter: &mut gtk::TextIter) {
self.imp().add_widget(widget, iter);
self.imp().add_widget(widget.upcast(), iter);
}
/// Get the widget at the given anchor, if any.

Loading…
Cancel
Save