-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix not working link toolbar on iOS. #18071
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
Draft
Mati365
wants to merge
8
commits into
master
Choose a base branch
from
ck/18023
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+436
−41
Draft
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3dc3802
Force select link on click in the middle on iOS.
Mati365 d964d7d
Fix variable.
Mati365 aa196bb
Move link touch detection to 2scm plugin.
Mati365 f0894d8
Fix typing.
Mati365 e3f5b3f
Add tests.
Mati365 48d869d
Fix typo.
Mati365 2644099
Restore typing.
Mati365 6cfd476
Apply CR remarks.
Mati365 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,7 @@ | |
|
|
||
| import { Plugin, type Editor } from '@ckeditor/ckeditor5-core'; | ||
|
|
||
| import { keyCodes } from '@ckeditor/ckeditor5-utils'; | ||
|
|
||
| import { keyCodes, env } from '@ckeditor/ckeditor5-utils'; | ||
| import { | ||
| MouseObserver, | ||
| TouchObserver, | ||
|
|
@@ -24,7 +23,10 @@ import { | |
| type ViewDocumentSelectionChangeEvent, | ||
| type ViewDocumentTouchStartEvent, | ||
| type ModelInsertContentEvent, | ||
| type ModelDeleteContentEvent | ||
| type ModelDeleteContentEvent, | ||
| type ViewElement, | ||
| type ViewNode, | ||
| type ViewDocumentFragment | ||
| } from '@ckeditor/ckeditor5-engine'; | ||
|
|
||
| import type { ViewDocumentDeleteEvent } from './deleteobserver.js'; | ||
|
|
@@ -504,6 +506,11 @@ export default class TwoStepCaretMovement extends Plugin { | |
| let touched = false; | ||
| let clicked = false; | ||
|
|
||
| // Handle iOS-specific middle-link touch behavior. | ||
| if ( env.isiOS ) { | ||
| this._enableMiddleLinkTouchHandlerForIOS(); | ||
| } | ||
|
|
||
| // This event should be fired before selection on mobile devices. | ||
| this.listenTo<ViewDocumentTouchStartEvent>( document, 'touchstart', () => { | ||
| clicked = false; | ||
|
|
@@ -563,6 +570,71 @@ export default class TwoStepCaretMovement extends Plugin { | |
| } ); | ||
| } | ||
|
|
||
| /** | ||
| * Enables special handling for middle-link touches on iOS devices. | ||
| * When a user touches the middle part of a link (not on edges), the cursor | ||
| * will be positioned at the end of the link to allow easy typing after the link. | ||
| * | ||
| * This is iOS-specific behavior to improve the user experience when working with links. | ||
| * | ||
| * See: https://github.com/ckeditor/ckeditor5/issues/18023 | ||
| */ | ||
| private _enableMiddleLinkTouchHandlerForIOS(): void { | ||
| const { editor } = this; | ||
| const viewDocument = editor.editing.view.document; | ||
|
|
||
| this.listenTo<ViewDocumentTouchStartEvent>( viewDocument, 'touchstart', ( evt, data ) => { | ||
| // Get the view element directly from the event data. | ||
| const targetViewElement = data.target; | ||
|
|
||
| // Find the closest link element (could be the target itself or one of its ancestors). | ||
| let linkElement: ViewElement | null = null; | ||
|
|
||
| if ( isLinkElement( targetViewElement ) ) { | ||
| linkElement = targetViewElement; | ||
| } else { | ||
| linkElement = targetViewElement.getAncestors().find( isLinkElement ) as ViewElement | null; | ||
|
||
| } | ||
|
|
||
| // If no link element found, exit early. | ||
| if ( !linkElement ) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if touch happened in the middle of the link. | ||
| const domElement = editor.editing.view.domConverter.mapViewToDom( linkElement )!; | ||
| const rect = domElement.getBoundingClientRect(); | ||
|
|
||
| const { clientX, clientY } = data.domEvent.touches[ 0 ]; | ||
|
|
||
| // Define edge threshold in pixels for X axis only. | ||
| const edgeThresholdPx = 10; | ||
|
|
||
| // Consider it a middle click if: | ||
| // 1. Not on left or right edge (with threshold). | ||
| const isNotLeftEdge = clientX > ( rect.left + edgeThresholdPx ); | ||
| const isNotRightEdge = clientX < ( rect.right - edgeThresholdPx ); | ||
|
|
||
| // 2. Vertically within the link boundaries (no threshold). | ||
| const isVerticallyInside = clientY >= rect.top && clientY <= rect.bottom; | ||
|
|
||
| const isMiddleLinkClick = isNotLeftEdge && isNotRightEdge && isVerticallyInside; | ||
|
|
||
| // If not a middle click, exit early. | ||
| if ( !isMiddleLinkClick ) { | ||
| return; | ||
| } | ||
|
|
||
| // Set the selection to the end of the link. | ||
| editor.model.change( writer => { | ||
| const viewRange = editor.editing.view.createPositionAt( linkElement!, 'end' ); | ||
| const modelPosition = editor.editing.mapper.toModelPosition( viewRange ); | ||
|
|
||
| writer.setSelection( modelPosition ); | ||
| } ); | ||
| } ); | ||
| } | ||
|
|
||
| /** | ||
| * Starts listening to {@link module:engine/model/model~Model#event:insertContent} and corrects the model | ||
| * selection attributes if the selection is at the end of a two-step node after inserting the content. | ||
|
|
@@ -782,3 +854,10 @@ function isBetweenDifferentAttributes( position: Position, attributes: Set<strin | |
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Returns `true` if a given view node is the link element. | ||
| */ | ||
| function isLinkElement( node: ViewNode | ViewDocumentFragment ): boolean { | ||
| return node.is( 'attributeElement' ) && !!node.getCustomProperty( 'link' ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.