[Android] Do not collapse text selection on shift key up (flutter/engine#42075)

Fixes https://github.com/flutter/flutter/issues/101569

This block of code was originally introduced in https://github.com/flutter/engine/pull/15560 , but removing it does not have any affect on the software text editing controls in GBoard.

Before this change
* shift + arrow right/left selection would collapse after releasing the shift key. 
* shift + mouse click to expand selection would collapse after releasing the shift key.

After this change
* shift key up no longer collapses the selection.
This commit is contained in:
Renzo Olivares
2023-05-17 11:53:03 -07:00
committed by GitHub
parent 46598122f7
commit 79df264a52
2 changed files with 4 additions and 10 deletions

View File

@@ -326,13 +326,6 @@ public class InputConnectionAdaptor extends BaseInputConnection
return true;
}
}
if (event.getAction() == KeyEvent.ACTION_UP
&& (event.getKeyCode() == KeyEvent.KEYCODE_SHIFT_LEFT
|| event.getKeyCode() == KeyEvent.KEYCODE_SHIFT_RIGHT)) {
int selEnd = Selection.getSelectionEnd(mEditable);
setSelection(selEnd, selEnd);
return true;
}
return false;
}

View File

@@ -551,7 +551,8 @@ public class InputConnectionAdaptorTest {
}
@Test
public void testSendKeyEvent_shiftKeyUpCancelsSelection() {
public void testSendKeyEvent_shiftKeyUpDoesNotCancelSelection() {
// Regression test for https://github.com/flutter/flutter/issues/101569.
int selStart = 5;
int selEnd = 10;
ListenableEditingState editable = sampleEditable(selStart, selEnd);
@@ -560,8 +561,8 @@ public class InputConnectionAdaptorTest {
KeyEvent shiftKeyUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT);
boolean didConsume = adaptor.handleKeyEvent(shiftKeyUp);
assertTrue(didConsume);
assertEquals(selEnd, Selection.getSelectionStart(editable));
assertFalse(didConsume);
assertEquals(selStart, Selection.getSelectionStart(editable));
assertEquals(selEnd, Selection.getSelectionEnd(editable));
}