[fix] limit remote ID input to nine digits without flicker

This commit is contained in:
dijunkun
2026-10-19 01:21:35 +08:00
parent 65a5288986
commit c61cf176cb
2 changed files with 18 additions and 21 deletions
+10 -17
View File
@@ -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;