widget: Avoid invalidation from unrealize

On unrealize, reset the IM preedit data without causing
an invalidation, which would access data already destroyed.

#29
parent bd74d0dd
......@@ -4356,6 +4356,18 @@ Terminal::im_preedit_set_active(bool active) noexcept
m_im_preedit_active = active;
}
void
Terminal::im_preedit_reset() noexcept
{
m_im_preedit.clear();
m_im_preedit.shrink_to_fit();
m_im_preedit_cursor = 0;
if (m_im_preedit_attrs != nullptr) {
pango_attr_list_unref(m_im_preedit_attrs);
m_im_preedit_attrs = nullptr;
}
}
void
Terminal::im_preedit_changed(char const* str,
int cursorpos,
......@@ -4365,13 +4377,10 @@ Terminal::im_preedit_changed(char const* str,
* for repainting. */
invalidate_cursor_once();
im_preedit_reset();
m_im_preedit = str;
if (m_im_preedit_attrs != nullptr) {
pango_attr_list_unref(m_im_preedit_attrs);
}
m_im_preedit_attrs = attrs;
m_im_preedit_cursor = cursorpos;
m_im_preedit_attrs = attrs;
m_im_preedit_cursor = cursorpos;
/* Invalidate again with the new cursor position */
invalidate_cursor_once();
......@@ -8240,13 +8249,6 @@ Terminal::widget_unrealize()
match_hilite_clear();
m_im_preedit_active = FALSE;
m_im_preedit.clear();
m_im_preedit.shrink_to_fit();
if (m_im_preedit_attrs != NULL) {
pango_attr_list_unref(m_im_preedit_attrs);
m_im_preedit_attrs = NULL;
}
m_im_preedit_cursor = 0;
/* Clean up our draw structure. */
if (m_draw != NULL) {
......
......@@ -855,6 +855,7 @@ public:
void im_commit(char const* text);
void im_preedit_set_active(bool active) noexcept;
void im_preedit_reset() noexcept;
void im_preedit_changed(char const* str,
int cursorpos,
PangoAttrList* attrs) noexcept;
......
......@@ -349,7 +349,7 @@ Widget::unrealize() noexcept
G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL,
this);
m_terminal->im_preedit_changed("", 0, nullptr);
m_terminal->im_preedit_reset();
gtk_im_context_set_client_window(m_im_context.get(), nullptr);
m_im_context.reset();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment