Compare commits

...

2 Commits

Author SHA1 Message Date
Misaka
8c127cbd6e Send Android draft on button press 2026-05-15 22:21:26 +08:00
Misaka
9dce49eb78 Sync full Android text after composition settles 2026-05-15 22:09:31 +08:00

View File

@@ -42,14 +42,13 @@ class _InputSyncPageState extends State<InputSyncPage> {
final inputFocusNode = FocusNode();
WebSocketChannel? channel;
String lastText = '';
String lastSyncedText = '';
bool connected = false;
@override
void initState() {
super.initState();
_loadSavedConnection();
inputController.addListener(_syncTextChange);
}
@override
@@ -96,24 +95,14 @@ class _InputSyncPageState extends State<InputSyncPage> {
});
}
void _syncTextChange() {
final currentText = inputController.text;
if (!connected || channel == null || currentText == lastText) {
lastText = currentText;
void _sendCurrentText() {
if (!connected || channel == null) {
return;
}
if (currentText.length > lastText.length &&
currentText.startsWith(lastText)) {
_send('insertText', text: currentText.substring(lastText.length));
} else if (lastText.length == currentText.length + 1 &&
lastText.startsWith(currentText)) {
_send('backspace');
} else {
_send('insertText', text: currentText);
}
lastText = currentText;
lastSyncedText = inputController.text;
_send('replaceAll', text: inputController.text);
inputFocusNode.requestFocus();
}
void _send(String action, {String? text}) {
@@ -160,6 +149,12 @@ class _InputSyncPageState extends State<InputSyncPage> {
onPressed: connected ? _disconnect : _connect,
icon: Icon(connected ? Icons.link_off : Icons.link),
),
const SizedBox(width: 8),
IconButton.filled(
tooltip: 'Send',
onPressed: connected ? _sendCurrentText : null,
icon: const Icon(Icons.send),
),
],
),
),