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