From a0de2f62289cf942ed4c51d8b6d8dac2988fdc09 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 24 Dec 2024 01:08:18 +0800 Subject: [PATCH] Fixed ImGui console command input issue. [skip CI] --- Source/GUI/ImGuiDora.cpp | 19 ++++++++++--------- Tools/build-scripts/run_macos_arm64.sh | 2 +- Tools/build-scripts/run_macos_x86_64.sh | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Source/GUI/ImGuiDora.cpp b/Source/GUI/ImGuiDora.cpp index cf65076c9..9151403c0 100644 --- a/Source/GUI/ImGuiDora.cpp +++ b/Source/GUI/ImGuiDora.cpp @@ -86,8 +86,8 @@ class ConsolePanel { } word_start--; } - ImVector candidates; - ImVector commands; + ImVector candidates; + ImVector commands; { auto L = SharedLuaEngine.getState(); int top = lua_gettop(L); @@ -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 (;;) { @@ -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; @@ -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; } @@ -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(u8"命令行") : "REPL", _buf.data(), _buf.size(), inputTextFlags, &TextEditCallbackStub, r_cast(this))) { _historyPos = -1; diff --git a/Tools/build-scripts/run_macos_arm64.sh b/Tools/build-scripts/run_macos_arm64.sh index b2d1d7da8..8b516006a 100755 --- a/Tools/build-scripts/run_macos_arm64.sh +++ b/Tools/build-scripts/run_macos_arm64.sh @@ -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 diff --git a/Tools/build-scripts/run_macos_x86_64.sh b/Tools/build-scripts/run_macos_x86_64.sh index 2c7152ba7..e43c09df2 100755 --- a/Tools/build-scripts/run_macos_x86_64.sh +++ b/Tools/build-scripts/run_macos_x86_64.sh @@ -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