mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-10-28 00:33:06 +08:00
[fix] limit remote ID input to nine digits without flicker
This commit is contained in:
@@ -343,10 +343,14 @@ std::string FormatPeerId(const char* id) {
|
|||||||
|
|
||||||
std::string FormatRemotePeerIdInput(std::string_view input) {
|
std::string FormatRemotePeerIdInput(std::string_view input) {
|
||||||
std::string digits = gallery::Workspace::NormalizeId(std::string(input));
|
std::string digits = gallery::Workspace::NormalizeId(std::string(input));
|
||||||
if (digits.size() > 9 ||
|
digits.erase(std::remove_if(digits.begin(), digits.end(),
|
||||||
!std::all_of(digits.begin(), digits.end(),
|
[](unsigned char c) {
|
||||||
[](unsigned char c) { return c >= '0' && c <= '9'; }))
|
return c < '0' || c > '9';
|
||||||
return digits;
|
}),
|
||||||
|
digits.end());
|
||||||
|
if (digits.size() > 9) {
|
||||||
|
digits.resize(9);
|
||||||
|
}
|
||||||
if (digits.size() > 3) {
|
if (digits.size() > 3) {
|
||||||
digits.insert(3, " ");
|
digits.insert(3, " ");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -958,7 +958,16 @@ export component MainWindow inherits Window {
|
|||||||
accessible-label: UiStrings.remote-id;
|
accessible-label: UiStrings.remote-id;
|
||||||
vertical-alignment: center;
|
vertical-alignment: center;
|
||||||
selection-foreground-color: white; selection-background-color: WorkbenchStyle.accent;
|
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); } }
|
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;
|
running: root.copy-feedback != CopyFeedback.idle;
|
||||||
triggered => { 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.
|
// Float above the workbench while keeping modal dialogs in front.
|
||||||
if !root.gallery-mode && root.copy-feedback != CopyFeedback.idle: WorkbenchNotice {
|
if !root.gallery-mode && root.copy-feedback != CopyFeedback.idle: WorkbenchNotice {
|
||||||
x: (parent.width - self.width) / 2;
|
x: (parent.width - self.width) / 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user