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

Move hit test position inside text container to get correct cursor position #595

Merged
merged 3 commits into from
Jul 26, 2019

Conversation

leonspok
Copy link
Contributor

@leonspok leonspok commented Jul 25, 2019

The problem was that by default if you press in the inset area of UITextView cursor is positioned at the beginning of UITextView.

UITextView has these methods available for overriding:

/* Hit testing. */
- (nullable UITextPosition *)closestPositionToPoint:(CGPoint)point;
- (nullable UITextPosition *)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange *)range;
- (nullable UITextRange *)characterRangeAtPoint:(CGPoint)point;

They are used to determine cursor position when user presses on UITextView. We can move the given point to the closest point inside UITextView's text content, which enables it to return proper cursor position.

Here is an example:

Green - fixed version, red - default behaviour.

demo 2019-07-25 16_51_43

@codecov-io
Copy link

codecov-io commented Jul 25, 2019

Codecov Report

Merging #595 into master will decrease coverage by 0.38%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #595      +/-   ##
==========================================
- Coverage   58.07%   57.68%   -0.39%     
==========================================
  Files          90       90              
  Lines        3859     3885      +26     
==========================================
  Hits         2241     2241              
- Misses       1618     1644      +26
Impacted Files Coverage Δ
...ttoAdditions/Source/Input/ExpandableTextView.swift 52.51% <0%> (-12.09%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21dc0a1...83a8f93. Read the comment docs.

@leonspok leonspok merged commit d51eb5c into master Jul 26, 2019
@AntonPalich AntonPalich deleted the fix-text-view-initial-cursor-position branch July 29, 2019 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants