AliSoftware / AliSoftware/OHAttributedLabel

Cannot activate link within a truncation character

Abierto
#17 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Issue
Lenguaje dominante
Objective-C
Estrellas
1.5k
Forks
341
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.