Skip to content
Open
Changes from 2 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
17 changes: 14 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/FieldEditText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ class FieldEditText :
}
return pastePlainText()
}
// Fix for issue where backspace removes multiple characters after CTRL+X cut
// After cutting, we need to reset the selection to a single cursor position
// to prevent backspace from using the old selection range
if (id == android.R.id.cut) {
// Get the cut position before calling super, as the selection will change
val cutPosition = min(selectionStart, selectionEnd)
val result = super.onTextContextMenuItem(id)
// Reset selection to cursor position after cut to fix backspace behavior
setSelection(cutPosition)
return result
}
return super.onTextContextMenuItem(id)
}

Expand All @@ -172,9 +183,9 @@ class FieldEditText :
getPlainText(clipboard, context)?.let { pasted ->
val start = min(selectionStart, selectionEnd)
val end = max(selectionStart, selectionEnd)
setText(
text!!.substring(0, start) + pasted + text!!.substring(end),
)
// Use Editable.replace() instead of setText() to preserve Editor state
// This prevents interference with cut operations and selection tracking
text?.replace(start, end, pasted)
setSelection(start + pasted.length)
return true
}
Expand Down