Unverified Commit d031a61a authored by Tomasz Gucio's avatar Tomasz Gucio Committed by GitHub

Add RenderEditable keys listener back in attach() (#75614)

parent 5a2c917d
......@@ -1639,6 +1639,8 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
_offset.addListener(markNeedsPaint);
_showHideCursor();
_showCursor.addListener(_showHideCursor);
if (_listenerAttached)
RawKeyboard.instance.addListener(_handleKeyEvent);
}
@override
......
......@@ -955,6 +955,67 @@ void main() {
expect(delegate.textEditingValue.text, '');
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61021
test('arrow keys work after detaching the widget and attaching it again', () async {
final TextSelectionDelegate delegate = FakeEditableTextState()
..textEditingValue = const TextEditingValue(
text: 'W Szczebrzeszynie chrząszcz brzmi w trzcinie',
selection: TextSelection.collapsed(offset: 0),
);
final ViewportOffset viewportOffset = ViewportOffset.zero();
final RenderEditable editable = RenderEditable(
backgroundCursorColor: Colors.grey,
selectionColor: Colors.black,
textDirection: TextDirection.ltr,
cursorColor: Colors.red,
offset: viewportOffset,
textSelectionDelegate: delegate,
onSelectionChanged: (TextSelection selection, RenderEditable renderObject, SelectionChangedCause cause) {
renderObject.selection = selection;
},
startHandleLayerLink: LayerLink(),
endHandleLayerLink: LayerLink(),
text: const TextSpan(
text: 'W Szczebrzeszynie chrząszcz brzmi w trzcinie',
style: TextStyle(
height: 1.0, fontSize: 10.0, fontFamily: 'Ahem',
),
),
selection: const TextSelection.collapsed(
offset: 0,
),
);
final PipelineOwner pipelineOwner = PipelineOwner();
editable.attach(pipelineOwner);
editable.hasFocus = true;
editable.detach();
layout(editable);
editable.hasFocus = true;
editable.selectPositionAt(from: Offset.zero, cause: SelectionChangedCause.tap);
editable.selection = const TextSelection.collapsed(offset: 0);
pumpFrame();
await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight, platform: 'android');
await simulateKeyUpEvent(LogicalKeyboardKey.arrowRight, platform: 'android');
await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight, platform: 'android');
await simulateKeyUpEvent(LogicalKeyboardKey.arrowRight, platform: 'android');
await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight, platform: 'android');
await simulateKeyUpEvent(LogicalKeyboardKey.arrowRight, platform: 'android');
await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight, platform: 'android');
await simulateKeyUpEvent(LogicalKeyboardKey.arrowRight, platform: 'android');
expect(editable.selection?.isCollapsed, true);
expect(editable.selection?.baseOffset, 4);
await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft, platform: 'android');
await simulateKeyUpEvent(LogicalKeyboardKey.arrowLeft, platform: 'android');
expect(editable.selection?.isCollapsed, true);
expect(editable.selection?.baseOffset, 3);
await simulateKeyDownEvent(LogicalKeyboardKey.delete, platform: 'android');
await simulateKeyUpEvent(LogicalKeyboardKey.delete, platform: 'android');
expect(delegate.textEditingValue.text, 'W Sczebrzeszynie chrząszcz brzmi w trzcinie');
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61021
test('arrow keys with selection text', () async {
final TextSelectionDelegate delegate = FakeEditableTextState();
final ViewportOffset viewportOffset = ViewportOffset.zero();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment