AliSoftware / AliSoftware/OHAttributedLabel

Cannot activate link within a truncation character

オープン
#17 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
Issue
主要言語
Objective-C
スター
1.5k
フォーク
341
PR マージ指標
30日以内にマージされた PR はありません

説明

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](https://github.com/AliSoftware)!

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。