Skip to content

Commit

Permalink
tweak(console): Improve keyboard focus
Browse files Browse the repository at this point in the history
This improves the focusing of the text input field in the client console.
We now focus the input field when:
- Opening the console
- Hovering over the input field
- Whenever the console gains focus and no other clickable or input-taking item is active
  • Loading branch information
tens0rfl0w committed Oct 28, 2024
1 parent 2632c6d commit 62bce91
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions code/components/conhost-v2/src/ConsoleHostGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ struct CfxBigConsole : FiveMConsoleBase

// Input field in the first column
ImGui::PushItemWidth(-FLT_MIN);
bool reclaim_focus = false;
if (ImGui::InputText("##_Input", InputBuf, _countof(InputBuf),
ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory, &TextEditCallbackStub, (void*)this))
{
Expand All @@ -417,7 +416,6 @@ struct CfxBigConsole : FiveMConsoleBase
if (InputBuf[0])
ExecCommand(InputBuf);
strcpy(InputBuf, "");
reclaim_focus = true;
}
ImGui::PopItemWidth();

Expand All @@ -431,6 +429,11 @@ struct CfxBigConsole : FiveMConsoleBase
{
OpenLogFile();
shouldOpenLog = false;
}

if (ImGui::IsItemHovered() || (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && !ImGui::IsAnyItemActive() && !ImGui::IsMouseClicked(0)))
{
ImGui::SetKeyboardFocusHere(-1);
}

bool preAutoScrollValue = AutoScrollEnabled;
Expand Down

0 comments on commit 62bce91

Please sign in to comment.