diff options
Diffstat (limited to 'main/src/ui')
-rw-r--r-- | main/src/ui/call_window/call_bottom_bar.vala | 2 | ||||
-rw-r--r-- | main/src/ui/conversation_content_view/message_widget.vala | 3 | ||||
-rw-r--r-- | main/src/ui/global_search.vala | 2 | ||||
-rw-r--r-- | main/src/ui/util/helper.vala | 35 |
4 files changed, 40 insertions, 2 deletions
diff --git a/main/src/ui/call_window/call_bottom_bar.vala b/main/src/ui/call_window/call_bottom_bar.vala index 641a4def..e0848cc9 100644 --- a/main/src/ui/call_window/call_bottom_bar.vala +++ b/main/src/ui/call_window/call_bottom_bar.vala @@ -138,7 +138,7 @@ public class Dino.Ui.CallBottomBar : Gtk.Box { public void show_counterpart_ended(string text) { stack.set_visible_child_name("label"); - label.label = text; + label.label = Util.unbreak_space_around_non_spacing_mark(text); } public bool is_menu_active() { diff --git a/main/src/ui/conversation_content_view/message_widget.vala b/main/src/ui/conversation_content_view/message_widget.vala index 376ef4bd..d116e7de 100644 --- a/main/src/ui/conversation_content_view/message_widget.vala +++ b/main/src/ui/conversation_content_view/message_widget.vala @@ -140,6 +140,9 @@ public class MessageMetaItem : ContentMetaItem { } } + // Work around pango bug + markup_text = Util.unbreak_space_around_non_spacing_mark((owned) markup_text); + if (conversation.type_ == Conversation.Type.GROUPCHAT) { markup_text = Util.parse_add_markup_theme(markup_text, conversation.nickname, true, true, true, Util.is_dark_theme(this.label), ref theme_dependent); } else { diff --git a/main/src/ui/global_search.vala b/main/src/ui/global_search.vala index 2fb31a90..a63aaed1 100644 --- a/main/src/ui/global_search.vala +++ b/main/src/ui/global_search.vala @@ -223,7 +223,7 @@ public class GlobalSearch { grid.margin_top = 3; grid.margin_bottom = 3; - string text = item.message.body.replace("\n", "").replace("\r", ""); + string text = Util.unbreak_space_around_non_spacing_mark(item.message.body.replace("\n", "").replace("\r", "")); if (text.length > 200) { int index = text.index_of(search); if (index + search.length <= 100) { diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index e12dfe20..578e313a 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -170,6 +170,41 @@ public static Map<unichar, unichar> get_matching_chars() { return MATCHING_CHARS; } +/** + * This replaces spaces with non-breaking spaces when they are adjacent to a non-spacing mark. + * + * We do this to work-around a bug in Pango. See https://gitlab.gnome.org/GNOME/pango/-/issues/798 and + * https://gitlab.gnome.org/GNOME/pango/-/issues/832 + * + * This is zero-copy iff no space is adjacent to a non-spacing mark, otherwise the provided string will be destroyed + * and the returned string should be used instead. + */ +public static string unbreak_space_around_non_spacing_mark(owned string s) { + int current_index = 0; + unichar current_char = 0; + int prev_index = 0; + unichar prev_char = 0; + bool is_non_spacing_mark = false; + while (s.get_next_char(ref current_index, out current_char)) { + int replace_index = -1; + if (is_non_spacing_mark && current_char == ' ') { + replace_index = prev_index; + current_char = ' '; + } + is_non_spacing_mark = ICU.get_int_property_value(current_char, ICU.Property.BIDI_CLASS) == ICU.CharDirection.DIR_NON_SPACING_MARK; + if (prev_char == ' ' && is_non_spacing_mark) { + replace_index = prev_index - 1; + } + if (replace_index != -1) { + s = s[0:replace_index] + " " + s[(replace_index + 1):s.length]; + current_index += 1; + } + prev_index = current_index; + prev_char = current_char; + } + return (owned) s; +} + public static string parse_add_markup(string s_, string? highlight_word, bool parse_links, bool parse_text_markup) { bool ignore_out_var = false; return parse_add_markup_theme(s_, highlight_word, parse_links, parse_text_markup, parse_text_markup, false, ref ignore_out_var); |