Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

Elevated: paste text at once instead of typing it out

Bee0272fd7de011
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6f7dcef..af1135c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -92,6 +92,9 @@ change things that need a step from you, and its notes say so.
- Windows: **Win+V** pastes into the phone's screen and app windows. Windows
marks an item picked from clipboard history as one for clipboard watchers
to skip, and NectarLink skipped it even when you asked to paste it.
+- Pasting into the phone's screen or an app window is instant, instead of
+ typing out a letter at a time, and a pasted line break no longer presses
+ Enter (which sent chat messages early).
- Pausing a transfer on the receiving device just as its last bytes
arrived left the sending device waiting, showing it as still sending. Both
now show it paused.
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/elevated/Elevated.kt b/android/app/src/main/kotlin/app/nectarlink/android/elevated/Elevated.kt
index 24dc5a3..354b349 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/elevated/Elevated.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/elevated/Elevated.kt
@@ -618,16 +618,17 @@ object Elevated {
is MirrorInputEvent.Scroll -> "S ${event.x * w} ${event.y * h} ${event.dx} ${event.dy}"
is MirrorInputEvent.Key -> keys[event.key]?.let { "K $it" }
?: if (event.key == "notifications" && display == null) "C cmd statusbar expand-notifications" else return true
- // One line per piece: no line breaks inside. Non-ASCII pieces are pasted via the clipboard.
- is MirrorInputEvent.Text -> return event.text.split(LINE_BREAK).withIndex().all { (i, piece) ->
- (i == 0 || send(writer, "${to}K ${KeyEvent.KEYCODE_ENTER}")) && when {
- piece.isEmpty() -> true
- piece.any { it.code > 127 } -> {
- app.nectarlink.android.clipboard.PhoneClipboard.write(context, piece)
- send(writer, "${to}K ${KeyEvent.KEYCODE_PASTE}")
- }
- else -> send(writer, "${to}T $piece")
- }
+ // A key typed on the PC types; anything longer (a paste, a word from
+ // an input method, an emoji) goes on the clipboard, quietly, and is
+ // pasted at once: typing it out took a moment per letter, and a line
+ // break typed as Enter sends a chat message early.
+ is MirrorInputEvent.Text -> return when {
+ event.text.isEmpty() -> true
+ event.text == "\n" || event.text == "\r" || event.text == "\r\n" ->
+ send(writer, "${to}K ${KeyEvent.KEYCODE_ENTER}")
+ event.text.length == 1 && event.text[0].code in 32..126 -> send(writer, "${to}T ${event.text}")
+ // The clipboard is the phone's own, whichever display the text is for.
+ else -> setClipboard(event.text, null) && send(writer, "${to}K ${KeyEvent.KEYCODE_PASTE}")
}
is MirrorInputEvent.Gamepad ->
"G ${event.buttons} ${event.lx} ${event.ly} ${event.rx} ${event.ry} ${event.lt} ${event.rt}"
@@ -764,7 +765,6 @@ object Elevated {
false
}
- private val LINE_BREAK = Regex("\r\n|\r|\n")
private val PACKAGE = Regex("[A-Za-z][A-Za-z0-9_]*(\\.[A-Za-z][A-Za-z0-9_]*)+")
private val keys = mapOf(