From 19e3b67f3e36a5478fa7e70a36a0aa5600cb2268 Mon Sep 17 00:00:00 2001 From: Anna Date: Sun, 16 Jun 2024 15:38:43 -0400 Subject: [PATCH] fix: check if template was changed --- client/Ui/MainWindowTabs/Write.cs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/client/Ui/MainWindowTabs/Write.cs b/client/Ui/MainWindowTabs/Write.cs index e18ec6c..762ffcb 100644 --- a/client/Ui/MainWindowTabs/Write.cs +++ b/client/Ui/MainWindowTabs/Write.cs @@ -118,33 +118,40 @@ internal class Write : ITab { const string placeholder = "****"; - void DrawPicker(string id, IReadOnlyList items, ref int x) { + bool DrawPicker(string id, IReadOnlyList items, ref int x) { var preview = x == -1 ? "" : items[x].Replace("{0}", placeholder); if (!ImGui.BeginCombo(id, preview)) { - return; + return false; } using var endCombo = new OnDispose(ImGui.EndCombo); + var changed = false; if (ImGui.Selectable("")) { x = -1; + changed = true; } for (var i = 0; i < items.Count; i++) { var template = items[i].Replace("{0}", placeholder); - if (ImGui.Selectable(template, i == x)) { - x = i; + if (!ImGui.Selectable(template, i == x)) { + continue; } + + x = i; + changed = true; } + + return changed; } void DrawTemplatePicker(string id, IReadOnlyList items, ref int x, ref (int, int) word) { - var wasAdvanced = this.Pack?.Templates[x].Words != null; - if (wasAdvanced) { + var wasAdvanced = this.Pack?.Templates.Get(x)?.Words != null; + + var changed = DrawPicker(id, items, ref x); + if (changed && wasAdvanced) { word = (-1, -1); } - - DrawPicker(id, items, ref x); } void DrawSpecificWordPicker(string id, Template template, ref (int, int) x) {