From 79df264a522e3747127d96dee228723fc6acfe9e Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 17 May 2023 11:53:03 -0700 Subject: [PATCH] [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. --- .../io/flutter/plugin/editing/InputConnectionAdaptor.java | 7 ------- .../flutter/plugin/editing/InputConnectionAdaptorTest.java | 7 ++++--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java index 1a56a11201..222158fcd7 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java @@ -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; } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java index fbb44da41b..93f92c182e 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java @@ -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)); }