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

Cannot activate link within a truncation character #17

Open
idpaterson opened this issue May 22, 2011 · 0 comments
Open

Cannot activate link within a truncation character #17

idpaterson opened this issue May 22, 2011 · 0 comments
Labels

Comments

@idpaterson
Copy link

This may be an issue with CoreText, and probably will not affect many people. However, for our purposes it was necessary to find a workaround since we are using OHAttributedLabel to render fixed-width columns of links with truncation.

For example, tapping the … if this were in an OHAttributedLabel would not fire the link:
Visit AliSoft…e GitHub!

The problem is that CTLineGetStringIndexForPosition gives an index of either 0 or 1 when linkAtPoint: is given a point corresponding to a truncation character like the ubiquitous … ellipsis. This is not entirely mysterious since the ellipsis is not actually in the string and may represent multiple character indices, but there does not seem to be any documentation specifying what output to expect and why.

Both 0 and 1 are valid indices, but only for the first line. After validating that the click is inside the current line, we added a test like this to determine if the position reported for the line is wrong based on the line's range in the attributed string:

CFRange range = CTLineGetStringRange(line);
CFIndex idx = CTLineGetStringIndexForPosition(line, relativePoint);
if (idx < range.location) {
  // Fix invalid index
}

Before this workaround, all taps over a truncation character anywhere in the list would activate the link at index 0 or 1 in the string. For our purposes, I simply choose a position in the line based on its range that is guaranteed to be in the link. Another option might be to test horizontally adjacent points until a link is hit. That may not be a general-purpose solution, and this issue report is more to offer awareness of the issue than to request any general fix.

stegiorgi pushed a commit to wedoit-io/OHAttributedLabel that referenced this issue Jan 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant