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