-
Notifications
You must be signed in to change notification settings - Fork 836
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
fix(macos): Implement actions for ExpandSelectionToDocumentBoundaryIntent and ExpandSelectionToLineBreakIntent to use keyboard shortcuts, unrelated cleanup to the bug fix. #2279
Conversation
…t and ExpandSelectionToLineBreakIntent
@CatHood0 I will address the change of The support for shortcuts is not clean enough, some of them are overridable: HideSelectionToolbarIntent:
_makeOverridable(QuillEditorHideSelectionToolbarAction(this)),
UndoTextIntent: _makeOverridable(QuillEditorUndoKeyboardAction(this)),
RedoTextIntent: _makeOverridable(QuillEditorRedoKeyboardAction(this)), Some of them do start with ToggleTextStyleIntednt: _formatSelectionAction,
IndentSelectionIntent: _indentSelectionAction,
QuillEditorApplyHeaderIntent: _applyHeaderAction,
QuillEditorApplyCheckListIntent: _applyCheckListAction,
// TODO: Double check and see if those and related should be overridable
QuillEditorApplyLinkIntent: QuillEditorApplyLinkAction(this),
ScrollToDocumentBoundaryIntent: NavigateToDocumentBoundaryAction(this), Others are not instantiated directly and have private member and the only usage is in the shortcuts:
It's not clear how should we name things, we need to agree on something, each class is named very differently without conventions or guidelines, it's also not clear that if we should add the In addition to other questions and issues, I didn't register them in the TODOs. The file |
…efaultSinlgeActivatorIntents() and QuillKeyboardServiceWidget to EditorKeyboardShortcuts, move their files inside raw_editor directory
…torIntents() from editor_keyboard_shortcuts.dart
…_activator_intents.dart to match the name of defaultSinlgeActivatorIntents()
It seems that there are even more important things to clean up, I have also noticed some duplicated logic, and a new update will be soon however it's not related to this PR so it might be confusing to review. I have tried to separate it into a new PR though decided not to. |
It seems that we're using We need to file an issue for this and fix them all in a clean way so we don't lose track of this. Reported in #2288. |
…utsActions outside of QuillRawEditorState
…or, update macOS example Podfile.lock
…od and add assert to check the platform
// Navigate to the start or end of the document | ||
SingleActivator( | ||
LogicalKeyboardKey.home, | ||
control: !_isDesktopMacOS, | ||
meta: _isDesktopMacOS, | ||
): const ScrollToDocumentBoundaryIntent(forward: false), | ||
SingleActivator( | ||
LogicalKeyboardKey.end, | ||
control: !_isDesktopMacOS, | ||
meta: _isDesktopMacOS, | ||
): const ScrollToDocumentBoundaryIntent(forward: true), |
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.
Those two included in #1937. I wasn't and still not sure if this is needed, seems to be redundant though.
// Plain text of the document (needed to find line breaks) | ||
final text = state.controller.plainTextEditingValue.text; | ||
|
||
final currentSelection = state.controller.selection; | ||
|
||
// Calculate the next or previous line break based on direction | ||
final searchStartOffset = currentSelection.extentOffset; | ||
|
||
final targetLineBreak = () { | ||
if (intent.forward) { | ||
final nextLineBreak = text.indexOf('\n', searchStartOffset); | ||
final noNextLineBreak = nextLineBreak == -1; | ||
return noNextLineBreak ? text.length : nextLineBreak + 1; | ||
} | ||
|
||
// Backward | ||
|
||
// Ensure (searchStartOffset - 1) is not negative to avoid [RangeError] | ||
final safePreviousSearchOffset = | ||
(searchStartOffset > 0) ? (searchStartOffset - 1) : 0; | ||
|
||
final previousLineBreak = | ||
text.lastIndexOf('\n', safePreviousSearchOffset); | ||
|
||
final noPreviousLineBreak = previousLineBreak == -1; | ||
return noPreviousLineBreak ? 0 : previousLineBreak; | ||
}(); | ||
|
||
// Create a new selection, extending it to the line break was found | ||
final newSelection = currentSelection.copyWith( | ||
extentOffset: targetLineBreak, | ||
); | ||
|
||
return Actions.invoke( | ||
context ?? (throw StateError('BuildContext should not be null.')), | ||
UpdateSelectionIntent( | ||
state.textEditingValue, | ||
newSelection, | ||
SelectionChangedCause.keyboard, | ||
), |
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.
Will need to know if this functionality already exist as a function to call, prefer to not repeat it twice, it can be confusing for other developers and for me in the future.
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.
Related _linebreak()
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.
The support for shortcuts is not clean enough, some of them are overridable:
Just a comment: I have had a brief encounter with _makeOverridable and was surprised by how it works:
Overridable means it can be overridden by prior implementations. That is exactly the opposite of what I understand by the term.
For example: Widget build Stack:
Widget 1 overridable action
Widget 2 overridable action
Widget 3 uses action from Widget 1! Because the prior implementation takes priority.
In order for the implementation in Widget 2 to correct a defect in Widget 1's implementation, it has to not use _makeOverridable.
I hope I am wrong in this.
In my case, I seem to recollect that there was an error in how Flutter handled a macOS shortcut key and since Flutter was at the top of the rendering stack it always took priority so my fix would never work if I used _makeOverridable!
The current code is quite confusing, even after the cleanup we have SingleActivator(
LogicalKeyboardKey.home,
control: !_isDesktopMacOS,
meta: _isDesktopMacOS,
): const ScrollToDocumentBoundaryIntent(forward: false),
SingleActivator(
LogicalKeyboardKey.end,
control: !_isDesktopMacOS,
meta: _isDesktopMacOS,
): const ScrollToDocumentBoundaryIntent(forward: true), Doesn't make any difference, I still want to know if this is macOS specific and why we don't need to register a activator for it before moving further. Was added in #1937. |
…tcutsActionsManager, move raw_editor_actions to keyboard_shortcuts/editor_keyboard_shortcut_actions_manager.dart
See #2288, while cleaning up, I'm having even more questions and the answers are not clear, I have spent almost one or two days trying to fix a minor bug, the bug has been fixed without fixing the related code quality issues, I prefer to completely rewrite the Keyboard shortcuts with their actions and intent instead and might do in a separate PR or might improve it later. Hopefully was able to move around 170 lines of code from @CatHood0 @AtlasAutocode If you can review the PR, once addressing all the changes, will merge this PR for now. |
Sorry I haven't been able to fix a few issues yet. I've had a hard time these days. I'll take the time tonight to do some code reviews and fix issues that were already on my list. |
No need to be sorry, take as much as time as you need. I appreciate your commitment to tackling the code reviews and issues tonight. If you need any assistance or just want to discuss anything, feel free to reach out. |
This PR is not the best in improving the organization and code quality though it's slightly more organized than the current code. I will merge however I have many questions, some things are unclear, and it's less time-consuming to rewrite the shortcuts functionality. This is a bug fix and unrelated and unrelated to the issue. I'm open to feedback if anything can be improved here. |
…tent and ExpandSelectionToLineBreakIntent to use keyboard shortcuts, unrelated cleanup to the bug fix. (singerdmx#2279)
Description
Implement actions for ExpandSelectionToDocumentBoundaryIntent and ExpandSelectionToLineBreakIntent in addition to unrelated cleanup that is not required to have the bug fix.
This PR will be updated soon, see #1192 for more details about the issue.
Related Issues
ExtendSelectionToNextParagraphBoundaryOrCaretLocationIntent
is also missing and will throw when pressing (option + shift + arrow up/down).Type of Change
Suggestions
Not for merge yet.
TODO