From a8290b993023221a90bed3f6a4c096053bfc8f30 Mon Sep 17 00:00:00 2001 From: sigma-axis <132639613+sigma-axis@users.noreply.github.com> Date: Thu, 26 Sep 2024 21:38:44 +0900 Subject: [PATCH] Now keeps selection when modified. --- reactive_dlg.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/reactive_dlg.cpp b/reactive_dlg.cpp index 3236e72..f0b3dec 100644 --- a/reactive_dlg.cpp +++ b/reactive_dlg.cpp @@ -562,15 +562,17 @@ struct TrackLabel : SettingDlg { if (clamp) val = std::clamp(val, info->value_min(), info->value_max()); // get the caret position, relative to the end of the text. - auto caret = len - get_edit_selection(info->hwnd_label).first; + auto [car_l, car_r] = get_edit_selection(info->hwnd_label); + car_l = len - car_l; car_r = len - car_r; if (auto prec = info->precision(); prec > 1) { int dec_places = static_cast(0.5 + std::log10(prec)); // values have fraction part. // preserve the caret position relative to the decimal point. - if (auto pt = std::wcschr(text, L'.'); pt != nullptr) - caret -= (text + len) - pt; - caret += 1 + dec_places; + if (auto pt = std::wcschr(text, L'.'); pt != nullptr) { + car_l -= (text + len) - pt; car_r -= (text + len) - pt; + } + car_l += 1 + dec_places; car_r += 1 + dec_places; len = std::swprintf(text, std::size(text), L"%.*f", dec_places, val); } @@ -584,7 +586,8 @@ struct TrackLabel : SettingDlg { ::SetWindowTextW(info->hwnd_label, text); // restore the caret position preserving the relative position to the decimal point. - set_edit_caret(info->hwnd_label, std::clamp(len - caret, 0, len)); + car_l = std::clamp(len - car_l, 0, len); car_r = std::clamp(len - car_r, 0, len); + set_edit_selection(info->hwnd_label, car_l, car_r); return true; } @@ -2330,7 +2333,7 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID lpvReserved) // 看板. //////////////////////////////// #define PLUGIN_NAME "Reactive Dialog" -#define PLUGIN_VERSION "v1.80-beta1" +#define PLUGIN_VERSION "v1.80-beta2" #define PLUGIN_AUTHOR "sigma-axis" #define PLUGIN_INFO_FMT(name, ver, author) (name##" "##ver##" by "##author) #define PLUGIN_INFO PLUGIN_INFO_FMT(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)