Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #882 from matrix-org/nicolasm/multiline-cursor-issue
Browse files Browse the repository at this point in the history
[iOS] Fix the position of the caret
  • Loading branch information
nimau authored Nov 21, 2023
2 parents 320f5c1 + 4dea856 commit 89282f7
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,12 @@ public class WysiwygTextView: UITextView {
override public func caretRect(for position: UITextPosition) -> CGRect {
// Compute system expected caret rect.
let rect = super.caretRect(for: position)
// Determine rect for glyph at expected position.
let index = offset(from: beginningOfDocument, to: position)
let glyphRange = layoutManager.glyphRange(forCharacterRange: .init(location: index, length: 1), actualCharacterRange: nil)
let glyphRect = layoutManager.boundingRect(forGlyphRange: glyphRange, in: textContainer)
// Use the system caret rect for `x` position and width and correct
// the `y` position and the height using the text glyphs.
// the `y` position and the height.
return CGRect(x: rect.minX,
y: glyphRect.minY - Constants.caretVerticalOffset,
y: rect.minY - Constants.caretVerticalOffset,
width: rect.width,
height: glyphRect.height + 2 * Constants.caretVerticalOffset)
height: rect.height + 2 * Constants.caretVerticalOffset)
}

// Enter Key commands support
Expand Down

0 comments on commit 89282f7

Please sign in to comment.