From 1241cdc5494a93c8bed0740e80e714595627ec09 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Tue, 16 May 2023 10:55:39 -0700 Subject: [PATCH 1/2] Do not collapse selection on shift key up --- .../io/flutter/plugin/editing/InputConnectionAdaptor.java | 7 ------- .../flutter/plugin/editing/InputConnectionAdaptorTest.java | 5 +++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java index 1a56a11201baf..222158fcd7d10 100644 --- a/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java +++ b/shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java @@ -326,13 +326,6 @@ public boolean handleKeyEvent(KeyEvent event) { 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/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java index fbb44da41bcb7..4a29c7db54f48 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java @@ -551,7 +551,8 @@ public void testPerformPrivateCommand_dataIsFloatArray() throws JSONException { } @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); @@ -561,7 +562,7 @@ public void testSendKeyEvent_shiftKeyUpCancelsSelection() { boolean didConsume = adaptor.handleKeyEvent(shiftKeyUp); assertTrue(didConsume); - assertEquals(selEnd, Selection.getSelectionStart(editable)); + assertEquals(selStart, Selection.getSelectionStart(editable)); assertEquals(selEnd, Selection.getSelectionEnd(editable)); } From a822e4704eb9022b54ef55e494cf703bf0379afd Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Tue, 16 May 2023 11:01:27 -0700 Subject: [PATCH 2/2] fix test --- .../io/flutter/plugin/editing/InputConnectionAdaptorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java index 4a29c7db54f48..93f92c182e0c2 100644 --- a/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java +++ b/shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java @@ -561,7 +561,7 @@ public void testSendKeyEvent_shiftKeyUpDoesNotCancelSelection() { KeyEvent shiftKeyUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT); boolean didConsume = adaptor.handleKeyEvent(shiftKeyUp); - assertTrue(didConsume); + assertFalse(didConsume); assertEquals(selStart, Selection.getSelectionStart(editable)); assertEquals(selEnd, Selection.getSelectionEnd(editable)); }