Skip to content
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

[macOS] Show correction panel for grammar errors #10986

Merged
merged 1 commit into from
Mar 3, 2023

Conversation

pxlcoder
Copy link
Member

@pxlcoder pxlcoder commented Mar 3, 2023

8172768

[macOS] Show correction panel for grammar errors
https://bugs.webkit.org/show_bug.cgi?id=253294
rdar://105738781

Reviewed by Wenson Hsieh.

Native text views on macOS display a correction panel when grammar checking is
enabled and the cursor is at the end of a grammar error, or when at the end of
a misspelled word.

Currently, WebKit only implements this behavior for misspelled words. This
patch adds support for showing a correction panel for grammar errors, matching
AppKit behavior.

* Source/WebCore/editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::timerFired):

Obtain suggestions for an ungrammatical phrase.

(WebCore::AlternativeTextController::handleAlternativeTextUIResult):

Insert accepted suggestions the same way as spelling suggestions.

(WebCore::AlternativeTextController::shouldStartTimerFor const):

Add grammar markers to the allowlist of markers that can display alternative text.

Improve the readability of the method by using a switch statement.

(WebCore::AlternativeTextController::respondToMarkerAtEndOfWord):

Start the timer to get grammar suggestions for the current word.

* Source/WebCore/page/AlternativeTextClient.h:
* Source/WebKit/UIProcess/mac/CorrectionPanel.mm:
(correctionIndicatorType):

The correction panel for grammar suggestions should appear the same as the
panel for spelling suggestions.

* Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::shouldEraseMarkersAfterChangeSelection const):

Prevent grammar markers from being removed on selection changes, matching
native behavior.

* Source/WebKitLegacy/mac/WebCoreSupport/CorrectionPanel.mm:
(correctionIndicatorType):

The correction panel for grammar suggestions should appear the same as the
panel for spelling suggestions.

Canonical link: https://commits.webkit.org/261151@main

2d3629b

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2   πŸ§ͺ api-mac βœ… πŸ›  gtk
  πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk1 βœ… πŸ§ͺ gtk-wk2
  πŸ›  tv ❌ πŸ§ͺ mac-wk2   πŸ§ͺ api-gtk
βœ… πŸ›  tv-sim ❌ πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  watch βœ… πŸ§ͺ mac-wk2-stress
βœ… πŸ›  watch-sim
βœ… πŸ›  πŸ§ͺ unsafe-merge

@pxlcoder pxlcoder self-assigned this Mar 3, 2023
@pxlcoder pxlcoder added the HTML Editing For bugs in HTML editing support (including designMode and contentEditable). label Mar 3, 2023
@pxlcoder
Copy link
Member Author

pxlcoder commented Mar 3, 2023

Thanks for the review!

@pxlcoder pxlcoder added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Mar 3, 2023
https://bugs.webkit.org/show_bug.cgi?id=253294
rdar://105738781

Reviewed by Wenson Hsieh.

Native text views on macOS display a correction panel when grammar checking is
enabled and the cursor is at the end of a grammar error, or when at the end of
a misspelled word.

Currently, WebKit only implements this behavior for misspelled words. This
patch adds support for showing a correction panel for grammar errors, matching
AppKit behavior.

* Source/WebCore/editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::timerFired):

Obtain suggestions for an ungrammatical phrase.

(WebCore::AlternativeTextController::handleAlternativeTextUIResult):

Insert accepted suggestions the same way as spelling suggestions.

(WebCore::AlternativeTextController::shouldStartTimerFor const):

Add grammar markers to the allowlist of markers that can display alternative text.

Improve the readability of the method by using a switch statement.

(WebCore::AlternativeTextController::respondToMarkerAtEndOfWord):

Start the timer to get grammar suggestions for the current word.

* Source/WebCore/page/AlternativeTextClient.h:
* Source/WebKit/UIProcess/mac/CorrectionPanel.mm:
(correctionIndicatorType):

The correction panel for grammar suggestions should appear the same as the
panel for spelling suggestions.

* Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::shouldEraseMarkersAfterChangeSelection const):

Prevent grammar markers from being removed on selection changes, matching
native behavior.

* Source/WebKitLegacy/mac/WebCoreSupport/CorrectionPanel.mm:
(correctionIndicatorType):

The correction panel for grammar suggestions should appear the same as the
panel for spelling suggestions.

Canonical link: https://commits.webkit.org/261151@main
@webkit-commit-queue
Copy link
Collaborator

Committed 261151@main (8172768): https://commits.webkit.org/261151@main

Reviewed commits have been landed. Closing PR #10986 and removing active labels.

@webkit-early-warning-system webkit-early-warning-system merged commit 8172768 into WebKit:main Mar 3, 2023
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HTML Editing For bugs in HTML editing support (including designMode and contentEditable).
Projects
None yet
4 participants