fix: Command Palette focus not working

This commit is contained in:
WerWolv 2022-07-02 21:38:58 +02:00
parent fc20d751bb
commit d0f1a40f16
1 changed files with 17 additions and 18 deletions

View File

@ -28,15 +28,24 @@ namespace hex::plugin::builtin {
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
ImGui::CloseCurrentPopup();
ImGui::PushItemWidth(-1);
if (ImGui::InputText(
"##command_input", this->m_commandBuffer.data(), this->m_commandBuffer.size(), ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_EnterReturnsTrue, [](ImGuiInputTextCallbackData *callbackData) -> int {
auto _this = static_cast<ViewCommandPalette *>(callbackData->UserData);
_this->m_lastResults = _this->getCommandResults(callbackData->Buf);
if (this->m_focusInputTextBox) {
auto textState = ImGui::GetInputTextState(ImGui::GetID("##command_input"));
if (textState != nullptr) {
textState->Stb.cursor = strlen(this->m_commandBuffer.data());
}
return 0;
},
this)) {
ImGui::SetKeyboardFocusHere(0);
this->m_focusInputTextBox = false;
}
ImGui::PushItemWidth(-1);
if (ImGui::InputText("##command_input", this->m_commandBuffer.data(), this->m_commandBuffer.size(), ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_EnterReturnsTrue,
[](ImGuiInputTextCallbackData *callbackData) -> int {
auto _this = static_cast<ViewCommandPalette *>(callbackData->UserData);
_this->m_lastResults = _this->getCommandResults(callbackData->Buf);
return 0;
}, this)) {
if (!this->m_lastResults.empty()) {
auto &[displayResult, matchedCommand, callback] = this->m_lastResults.front();
callback(matchedCommand);
@ -52,16 +61,6 @@ namespace hex::plugin::builtin {
this->m_justOpened = false;
}
if (this->m_focusInputTextBox) {
auto textState = ImGui::GetInputTextState(ImGui::GetID("##command_input"));
if (textState != nullptr) {
textState->Stb.cursor = strlen(this->m_commandBuffer.data());
}
ImGui::SetKeyboardFocusHere(0);
this->m_focusInputTextBox = false;
}
ImGui::Separator();
for (const auto &[displayResult, matchedCommand, callback] : this->m_lastResults) {