fix: only scroll when using arrow keys

This commit is contained in:
Anna 2022-05-31 23:26:28 -04:00
parent 2be7e0d135
commit e86da10689
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
2 changed files with 14 additions and 5 deletions

View File

@ -41,6 +41,7 @@ internal sealed class ChatLog : IUiComponent {
private List<AutoTranslateEntry>? _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;
}
}

View File

@ -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));
}