Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3484,7 +3484,8 @@ class InputLogic(
Log.e(TAG, "Failed to get text after cursor: $e")
0
}
if (after > 0) mConnection.setSelection(end + after, end + after)
// also collapse a selection made during the request, the result would replace it
if (after > 0 || mConnection.expectedSelectionStart != end) mConnection.setSelection(end + after, end + after)
}

private fun tryJumpToNextPlaceholder(): Boolean {
Expand Down
8 changes: 8 additions & 0 deletions app/src/test/java/helium314/keyboard/latin/InputLogicTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,14 @@ class InputLogicTest {
assertEquals("first line\n\nAnswer.", text)
}

@Test fun `custom AI key result does not overwrite text selected during the request when appending`() {
reset()
setText("first line")
setCursorPosition(6, 10) // "line", up to the end of the text
latinIME.mInputLogic.insertCustomAiResult("Answer.", shouldAppend = true, hasSelection = false)
assertEquals("first line\n\nAnswer.", text)
}

@Test fun `custom AI key result replaces the selection`() {
reset()
setText("one teh two")
Expand Down
Loading