]> git.eshelyaron.com Git - emacs.git/commitdiff
Try to preserve font styles in the Haiku font dialog
authorPo Lu <luangruo@yahoo.com>
Wed, 11 May 2022 02:02:21 +0000 (02:02 +0000)
committerPo Lu <luangruo@yahoo.com>
Wed, 11 May 2022 02:02:21 +0000 (02:02 +0000)
* 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

index 6b4951e139adcceb2f075d56b744b09b6b58bb22..cb9dfabc4e719cba644e8cafe9a8759189e3c97b 100644 (file)
@@ -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 ("<error>");
 
+           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