diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-27 11:20:33 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-27 11:20:33 +0200 |
commit | e16dcb7e9d8b85f56d724692a0281811549079e4 (patch) | |
tree | bba25e250eb6cda54734a63ce7158d591ad70c7b /src/gmdocument.c | |
parent | d75ad4213c81e588358aee4786ad13ca08c80d0c (diff) |
GmDocument: Finding position in source
The returned position at a source location is now a range, pointing to the left and right edges of the contacted character.
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 3cf00a4b..30f5169a 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -1528,12 +1528,12 @@ const iGmRun *findRun_GmDocument(const iGmDocument *d, iInt2 pos) { | |||
1528 | return last; | 1528 | return last; |
1529 | } | 1529 | } |
1530 | 1530 | ||
1531 | const char *findLoc_GmDocument(const iGmDocument *d, iInt2 pos) { | 1531 | iRangecc findLoc_GmDocument(const iGmDocument *d, iInt2 pos) { |
1532 | const iGmRun *run = findRun_GmDocument(d, pos); | 1532 | const iGmRun *run = findRun_GmDocument(d, pos); |
1533 | if (run) { | 1533 | if (run) { |
1534 | return findLoc_GmRun(run, pos); | 1534 | return findLoc_GmRun(run, pos); |
1535 | } | 1535 | } |
1536 | return NULL; | 1536 | return iNullRange; |
1537 | } | 1537 | } |
1538 | 1538 | ||
1539 | const iGmRun *findRunAtLoc_GmDocument(const iGmDocument *d, const char *textCStr) { | 1539 | const iGmRun *findRunAtLoc_GmDocument(const iGmDocument *d, const char *textCStr) { |
@@ -1662,16 +1662,25 @@ iChar siteIcon_GmDocument(const iGmDocument *d) { | |||
1662 | return d->siteIcon; | 1662 | return d->siteIcon; |
1663 | } | 1663 | } |
1664 | 1664 | ||
1665 | const char *findLoc_GmRun(const iGmRun *d, iInt2 pos) { | 1665 | iRangecc findLoc_GmRun(const iGmRun *d, iInt2 pos) { |
1666 | if (pos.y < top_Rect(d->bounds)) { | 1666 | if (pos.y < top_Rect(d->bounds)) { |
1667 | return d->text.start; | 1667 | return (iRangecc){ d->text.start, d->text.start }; |
1668 | } | 1668 | } |
1669 | const int x = pos.x - left_Rect(d->bounds); | 1669 | const int x = pos.x - left_Rect(d->bounds); |
1670 | if (x <= 0) { | 1670 | if (x <= 0) { |
1671 | return d->text.start; | 1671 | return (iRangecc){ d->text.start, d->text.start }; |
1672 | } | ||
1673 | iRangecc loc; | ||
1674 | tryAdvanceNoWrap_Text(d->font, d->text, x, &loc.start); | ||
1675 | loc.end = loc.start; | ||
1676 | iChar ch; | ||
1677 | if (d->text.end != loc.start) { | ||
1678 | int chLen = decodeBytes_MultibyteChar(loc.start, d->text.end - loc.start, &ch); | ||
1679 | if (chLen > 0) { | ||
1680 | /* End after the character. */ | ||
1681 | loc.end += chLen; | ||
1682 | } | ||
1672 | } | 1683 | } |
1673 | const char *loc; | ||
1674 | tryAdvanceNoWrap_Text(d->font, d->text, x, &loc); | ||
1675 | return loc; | 1684 | return loc; |
1676 | } | 1685 | } |
1677 | 1686 | ||