From e86da10689fc3f92e0dac6cc84455e61c8d5c0c2 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Tue, 31 May 2022 23:26:28 -0400 Subject: [PATCH] fix: only scroll when using arrow keys --- ChatTwo/Ui/ChatLog.cs | 15 ++++++++++++--- ChatTwo/Util/AutoTranslate.cs | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index d46d7c5..a5602c6 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -41,6 +41,7 @@ internal sealed class ChatLog : IUiComponent { private List? _autoCompleteList; private bool _fixCursor; private int _autoCompleteSelection; + private bool _autoCompleteShouldScroll; internal Vector2 LastWindowSize { get; private set; } = Vector2.Zero; internal Vector2 LastWindowPos { get; private set; } = Vector2.Zero; @@ -979,6 +980,7 @@ internal sealed class ChatLog : IUiComponent { if (ImGui.InputTextWithHint("##auto-complete-filter", Language.AutoTranslate_Search_Hint, ref this._autoCompleteInfo.ToComplete, 256, ImGuiInputTextFlags.CallbackAlways | ImGuiInputTextFlags.CallbackHistory, this.AutoCompleteCallback)) { this._autoCompleteList = AutoTranslate.Matching(this.Ui.Plugin.DataManager, this._autoCompleteInfo.ToComplete, this.Ui.Plugin.Config.SortAutoTranslate); this._autoCompleteSelection = 0; + this._autoCompleteShouldScroll = true; } var selected = -1; @@ -1011,7 +1013,7 @@ internal sealed class ChatLog : IUiComponent { ImGui.SetKeyboardFocusHere(); } - if (ImGui.BeginChild("##auto-complete-list", new Vector2(0, 0), false, ImGuiWindowFlags.HorizontalScrollbar)) { + if (ImGui.BeginChild("##auto-complete-list", Vector2.Zero, false, ImGuiWindowFlags.HorizontalScrollbar)) { var clipper = new ImGuiListClipperPtr(ImGuiNative.ImGuiListClipper_ImGuiListClipper()); clipper.Begin(this._autoCompleteList.Count); @@ -1046,8 +1048,11 @@ internal sealed class ChatLog : IUiComponent { } } - var selectedPos = clipper.StartPosY + clipper.ItemsHeight * (this._autoCompleteSelection * 1f); - ImGui.SetScrollFromPosY(selectedPos - ImGui.GetWindowPos().Y); + if (this._autoCompleteShouldScroll) { + this._autoCompleteShouldScroll = false; + var selectedPos = clipper.StartPosY + clipper.ItemsHeight * (this._autoCompleteSelection * 1f); + ImGui.SetScrollFromPosY(selectedPos - ImGui.GetWindowPos().Y); + } ImGui.EndChild(); } @@ -1075,6 +1080,8 @@ internal sealed class ChatLog : IUiComponent { this._autoCompleteSelection--; } + this._autoCompleteShouldScroll = true; + return 1; } case ImGuiKey.DownArrow: { @@ -1084,6 +1091,8 @@ internal sealed class ChatLog : IUiComponent { this._autoCompleteSelection++; } + this._autoCompleteShouldScroll = true; + return 1; } } diff --git a/ChatTwo/Util/AutoTranslate.cs b/ChatTwo/Util/AutoTranslate.cs index f30c7e6..6bb61c9 100644 --- a/ChatTwo/Util/AutoTranslate.cs +++ b/ChatTwo/Util/AutoTranslate.cs @@ -93,7 +93,7 @@ internal static class AutoTranslate { if (Entries.TryGetValue(data.Language, out var entries)) { return entries; } - + var shouldAdd = ValidEntries.Count == 0; var parser = Parser(); @@ -186,7 +186,7 @@ internal static class AutoTranslate { text.TextValue, text )); - + if (shouldAdd) { ValidEntries.Add((row.Group, row.RowId)); }