Append submitted Android text on desktop

This commit is contained in:
Misaka
2026-05-15 22:31:55 +08:00
parent a6602206c5
commit 1b4267a6ff
2 changed files with 8 additions and 10 deletions

View File

@@ -43,7 +43,7 @@ public sealed class SyncMessageTests
}
[TestMethod]
public void ReplaceAllUsesFocusedTextReplacement()
public void ReplaceAllAppendsSubmittedText()
{
var keyboard = new RecordingKeyboardInjectionService();
var handler = new SyncMessageHandler(keyboard);
@@ -55,7 +55,7 @@ public sealed class SyncMessageTests
});
CollectionAssert.AreEqual(
new[] { "replace:final text" },
new[] { "insert:final text" },
keyboard.Calls);
}

View File

@@ -22,7 +22,7 @@ public sealed class SyncMessageHandler
remoteText += insertedText;
break;
case SyncAction.ReplaceAll:
ReplaceAll(message.Text ?? string.Empty);
AppendSubmittedText(message.Text ?? string.Empty);
break;
case SyncAction.Backspace:
keyboard.Backspace();
@@ -43,17 +43,15 @@ public sealed class SyncMessageHandler
}
}
private void ReplaceAll(string newText)
private void AppendSubmittedText(string text)
{
if (newText == remoteText)
if (string.IsNullOrEmpty(text))
{
return;
}
AppLogger.Info(
$"Hard replacing focused text. Old mirrored length: {remoteText.Length}, new length: {newText.Length}");
keyboard.ReplaceFocusedText(newText);
remoteText = newText;
AppLogger.Info($"Appending submitted text length: {text.Length}");
keyboard.InsertText(text);
remoteText += text;
}
}