From 736081320803c6d1f987f753f63581a0fd42b1fe Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 11 May 2022 02:02:21 +0000 Subject: [PATCH] Try to preserve font styles in the Haiku font dialog * haiku_support.cc (class EmacsFontSelectionDialog) (UpdateStylesForIndex): If a style was previously selected and exists in the new family as well, select it after adding the new items. --- src/haiku_support.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 6b4951e139a..cb9dfabc4e7 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -2619,13 +2619,22 @@ class EmacsFontSelectionDialog : public BWindow void UpdateStylesForIndex (int idx) { - int n, i; + int n, i, previous_selection; uint32 flags; font_family family; font_style style; BStringItem *item; + char *current_style; n = all_styles.CountItems (); + current_style = NULL; + previous_selection = font_style_pane.CurrentSelection (); + + if (previous_selection >= 0) + { + item = all_styles.ItemAt (previous_selection); + current_style = strdup (item->Text ()); + } font_style_pane.MakeEmpty (); all_styles.MakeEmpty (); @@ -2641,6 +2650,10 @@ class EmacsFontSelectionDialog : public BWindow else item = new BStringItem (""); + if (current_style && pending_selection_idx < 0 + && !strcmp (current_style, style)) + pending_selection_idx = i; + font_style_pane.AddItem (item); all_styles.AddItem (item); } @@ -2654,6 +2667,9 @@ class EmacsFontSelectionDialog : public BWindow pending_selection_idx = -1; UpdateForSelectedStyle (); + + if (current_style) + free (current_style); } bool -- 2.39.2