From c61cf176cb4dc0b08298b5b2d7fe9803b297f6ec Mon Sep 17 00:00:00 2001 From: dijunkun Date: Mon, 19 Oct 2026 01:21:35 +0800 Subject: [PATCH] [fix] limit remote ID input to nine digits without flicker --- .../src/gui/application/gui_application.cpp | 12 ++++++--- apps/desktop/src/gui/ui/main_window.slint | 27 +++++++------------ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/apps/desktop/src/gui/application/gui_application.cpp b/apps/desktop/src/gui/application/gui_application.cpp index f0c158c3..a51e6829 100644 --- a/apps/desktop/src/gui/application/gui_application.cpp +++ b/apps/desktop/src/gui/application/gui_application.cpp @@ -343,10 +343,14 @@ std::string FormatPeerId(const char* id) { std::string FormatRemotePeerIdInput(std::string_view input) { std::string digits = gallery::Workspace::NormalizeId(std::string(input)); - if (digits.size() > 9 || - !std::all_of(digits.begin(), digits.end(), - [](unsigned char c) { return c >= '0' && c <= '9'; })) - return digits; + digits.erase(std::remove_if(digits.begin(), digits.end(), + [](unsigned char c) { + return c < '0' || c > '9'; + }), + digits.end()); + if (digits.size() > 9) { + digits.resize(9); + } if (digits.size() > 3) { digits.insert(3, " "); } diff --git a/apps/desktop/src/gui/ui/main_window.slint b/apps/desktop/src/gui/ui/main_window.slint index 8e001b03..e14bf60a 100644 --- a/apps/desktop/src/gui/ui/main_window.slint +++ b/apps/desktop/src/gui/ui/main_window.slint @@ -958,7 +958,16 @@ export component MainWindow inherits Window { accessible-label: UiStrings.remote-id; vertical-alignment: center; selection-foreground-color: white; selection-background-color: WorkbenchStyle.accent; - edited => { root.connection-input-error = ""; remote-id-format-timer.running = true; } + edited => { + root.connection-input-error = ""; + // Enforce the digit limit before the next frame can + // render the text from typing, paste, or replacement. + let formatted = root.format-remote-id(self.text); + self.text = formatted; + // Formatted IDs are ASCII, so these are UTF-8 offsets. + self.set-selection-offsets( + formatted.character-count, formatted.character-count); + } accepted => { if !root.connection-pending { root.connect-requested(root.remote-id-input); } } } } @@ -1567,22 +1576,6 @@ export component MainWindow inherits Window { running: root.copy-feedback != CopyFeedback.idle; triggered => { root.copy-feedback = CopyFeedback.idle; } } - remote-id-format-timer := Timer { - interval: 1ms; - running: false; - triggered => { - // Use the running property for both transitions. restart() resumes - // the native repeating timer without restoring this property, so - // a later stop() cannot change it and the selection keeps resetting. - self.stop(); - let formatted = root.format-remote-id(root.remote-id-input); - root.remote-id-input = formatted; - // IDs are ASCII-only, so character-count is also the UTF-8 offset - // expected by set-selection-offsets(). - remote-id-editor.set-selection-offsets( - formatted.character-count, formatted.character-count); - } - } // Float above the workbench while keeping modal dialogs in front. if !root.gallery-mode && root.copy-feedback != CopyFeedback.idle: WorkbenchNotice { x: (parent.width - self.width) / 2;