-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SuperTextField] Fix new line duplication (Resolves #1468) #1469
[SuperTextField] Fix new line duplication (Resolves #1468) #1469
Conversation
@@ -738,3 +739,21 @@ class FakeSuperEditorScroller implements DocumentScroller { | |||
@override | |||
void detach() => throw UnimplementedError(); | |||
} | |||
|
|||
/// The platform to be used when simulating a keyboard event with `sendKeyEvent`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would this platform be different than the defaultTargetPlatform
? Also, where is this being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used in _pressEnterOnSuperTextField
. I extracted this from pressEnter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you extract it instead of use it? And also I'd still like to know why it doesn't use defaultTargetPlatform
. I don't remember what we did for pressEnter
originally, or why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't use pressEnter
because I had to check whether or not the key was handled in order to generate the input action and the insertion delta.
@@ -1288,7 +1288,13 @@ class _SuperTextFieldImeInteractorState extends State<SuperTextFieldImeInteracto | |||
void _onPerformAction(TextInputAction action) { | |||
switch (action) { | |||
case TextInputAction.newline: | |||
widget.textController.insertNewline(); | |||
// On mac desktop, we don't insert new lines via keyboard events. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This says "On mac desktop" but I don't see any platform inspection nearby....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not inspecting the platform because for other desktop platforms, the new line is inserted via keyboard handlers. Because of that, the IME doesn't reports input actions nor insertion deltas.
If, at some point, we remove the ENTER keyboard handler, we would be in the same situation as on mac...
Should I just update the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the purpose of this code comment to explain why we're not doing anything when we get a newline?
If so, does the following comment better capture the situation?
// Do nothing for IME newline actions
//
// Mac: Key presses flow, unhandled, to the OS and turn into IME selectors. We handle newlines there.
// Windows/Linux: Newlines are inserted by Super Editor key handlers, instead of IME actions, because Flutter doesn't dispatch newline IME actions for these platforms.
// Android/iOS: This text field implementation is only for desktop, mobile is handled elsewhere.
Also, can you remind me why we're using key handlers for Windows/Linux and not using the IME actions? Is that because Flutter doesn't send us IME actions for those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, we used key handlers to insert new line on all desktop platforms. After the performSelection
implementation, we stopped doing that on mac.
We could probably could do the same on the other desktop platforms. I tested on Windows and we also receive the input actions and insertion deltas if we don't handle the ENTER key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Let's try removing the ENTER handler from the IME handler list for Windows and Linux.
@@ -683,6 +621,38 @@ void main() { | |||
}); | |||
} | |||
|
|||
Future<void> _pressEnterOnSuperTextField(WidgetTester tester) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually specific to SuperTextField
? Why doesn't this apply to SuperEditor
, too? Also, does this belong in the testing robots package for general use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add this to the test robots. Should I open a PR for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you can open a PR for that. What about the first two questions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will apply for SuperEditor
also. I was looking into implementing it on testing robots pressEnter
, but then we will need to add an optional imeClientGetter
parameter.
To generate deltas, we need to access DeltaTextInputClient
in order to obtain the current editing value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we introduce a pressEnterOnIme()
to the robots package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you release a new version of flutter_test_robots? We'll need a pub version with the new methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just released v0.0.22
|
||
// The ENTER key event wasn't handled by the textfield. | ||
// The OS generates both a "\n" insertion and a new line action. | ||
await tester.ime.typeText('\n', getter: imeClientGetter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be checking for an open connection instead of assuming that there is one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@angelosilvestre is this ready for review? Or still doing work? |
Also, looks like tests are failing, FYI. |
@matthew-carroll This is ready for another review now. |
Looks like this PR has a merge conflict. |
bc580eb
to
77754b0
Compare
@matthew-carroll Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with removal of one superfluous import
@@ -1,6 +1,7 @@ | |||
import 'dart:math'; | |||
import 'dart:ui' as ui; | |||
|
|||
import 'package:flutter/foundation.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. Removed.
FYI @angelosilvestre CI is going to automatically create a PR when we merge, but you'll have to explicitly close and re-open the PR to get other CI checks to run. |
@matthew-carroll I didn't find any PR created for after the merge |
Ugh - CI is failing for some reason....complaining that GitHub bot doesn't have permission, which doesn't make sense given that this has worked previously. https://github.com/superlistapp/super_editor/actions/runs/6552954869/job/17799413806 |
[SuperTextField] Fix new line duplication. Resolves #1468
On macOS, pressing ENTER or SHIFT + ENTER is inserting two lines. This is caused because pressing ENTER generates both an
onPerformAction
call and a\n
insertion.On Windows this issue doesn't happen because we are using key event handlers to insert new lines. If we remove the key handler that inserts new lines, the issue happens on Windows as well. This issue was introduced when the selector handlers were implemented.
This PR changes
_onPerformAction
to avoid inserting new lines.