Compare commits
2 Commits
6b51fc5f99
...
8c127cbd6e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c127cbd6e | ||
|
|
9dce49eb78 |
@@ -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),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user