Skip to content

Commit

Permalink
Fixed ImGui console command input issue. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Dec 23, 2024
1 parent 4f7df6f commit a0de2f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions Source/GUI/ImGuiDora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class ConsolePanel {
}
word_start--;
}
ImVector<const char*> candidates;
ImVector<const char*> commands;
ImVector<Slice> candidates;
ImVector<Slice> commands;
{
auto L = SharedLuaEngine.getState();
int top = lua_gettop(L);
Expand All @@ -97,20 +97,20 @@ class ConsolePanel {
while (lua_next(L, 2)) {
lua_pushvalue(L, -2);
if (lua_isstring(L, -1)) {
auto key = lua_tostring(L, -1);
auto key = tolua_toslice(L, -1, nullptr);
commands.push_back(key);
}
lua_pop(L, 2);
}
}
for (int i = 0; i < commands.size(); i++) {
if (std::strncmp(commands[i], word_start, (int)(word_end - word_start)) == 0) {
if (std::strncmp(commands[i].rawData(), word_start, (int)(word_end - word_start)) == 0) {
candidates.push_back(commands[i]);
}
}
if (candidates.Size == 1) {
data->DeleteChars((int)(word_start - data->Buf), (int)(word_end - word_start));
data->InsertChars(data->CursorPos, candidates[0]);
data->InsertChars(data->CursorPos, candidates[0].begin(), candidates[0].end());
} else if (candidates.Size > 1) {
int match_len = (int)(word_end - word_start);
for (;;) {
Expand All @@ -128,7 +128,8 @@ class ConsolePanel {
}
if (match_len > 0) {
data->DeleteChars((int)(word_start - data->Buf), (int)(word_end - word_start));
data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
data->InsertChars(data->CursorPos, candidates[0].begin(), candidates[0].begin() + match_len);

}
}
break;
Expand All @@ -147,9 +148,9 @@ class ConsolePanel {
}
}
if (prev_history_pos != _historyPos) {
const char* history_str = (_historyPos >= 0) ? _history[_historyPos].c_str() : "";
auto history_str = (_historyPos >= 0) ? Slice{_history[_historyPos]} : Slice{};
data->DeleteChars(0, data->BufTextLen);
data->InsertChars(0, history_str);
data->InsertChars(0, history_str.begin(), history_str.end());
}
break;
}
Expand Down Expand Up @@ -231,7 +232,7 @@ class ConsolePanel {
ImGui::EndChild();

bool reclaimFocus = false;
ImGuiInputTextFlags inputTextFlags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory;
ImGuiInputTextFlags inputTextFlags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackResize;
ImGui::PushItemWidth(-60);
if (ImGui::InputText(useChinese ? r_cast<const char*>(u8"命令行") : "REPL", _buf.data(), _buf.size(), inputTextFlags, &TextEditCallbackStub, r_cast<void*>(this))) {
_historyPos = -1;
Expand Down
2 changes: 1 addition & 1 deletion Tools/build-scripts/run_macos_arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ cd "$SCRIPT_DIR/../../Source/Rust"
cargo build --target aarch64-apple-darwin
cp target/aarch64-apple-darwin/debug/libdora_runtime.a lib/macOS/libdora_runtime.a
xcodebuild ARCHS=arm64 ONLY_ACTIVE_ARCH=NO -project ../../Projects/macOS/Dora.xcodeproj -target Dora -configuration Debug CONFIGURATION_BUILD_DIR=./build/Debug
../../Projects/macOS/build/Debug/Dora.app/Contents/MacOS/Dora asset ../../Assets
../../Projects/macOS/build/Debug/Dora.app/Contents/MacOS/Dora --asset ../../Assets

2 changes: 1 addition & 1 deletion Tools/build-scripts/run_macos_x86_64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ cd "$SCRIPT_DIR/../../Source/Rust"
cargo build --target x86_64-apple-darwin
cp target/x86_64-apple-darwin/debug/libdora_runtime.a lib/macOS/libdora_runtime.a
xcodebuild ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO -project ../../Projects/macOS/Dora.xcodeproj -target Dora -configuration Debug CONFIGURATION_BUILD_DIR=./build/Debug
../../Projects/macOS/build/Debug/Dora.app/Contents/MacOS/Dora asset ../../Assets
../../Projects/macOS/build/Debug/Dora.app/Contents/MacOS/Dora --asset ../../Assets

0 comments on commit a0de2f6

Please sign in to comment.