diff options
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 05ec5141..0a0966be 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -272,8 +272,13 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
272 | while (!isEmpty_Range(&runLine)) { | 272 | while (!isEmpty_Range(&runLine)) { |
273 | run.bounds.pos = addX_I2(pos, indent * gap_UI); | 273 | run.bounds.pos = addX_I2(pos, indent * gap_UI); |
274 | const char *contPos; | 274 | const char *contPos; |
275 | run.bounds.size = tryAdvanceRange_Text( | 275 | const int avail = d->size.x - run.bounds.pos.x; |
276 | run.font, runLine, isPreformat ? 0 : (d->size.x - run.bounds.pos.x), &contPos); | 276 | const iInt2 dims = |
277 | tryAdvance_Text(run.font, runLine, isPreformat ? 0 : avail, &contPos); | ||
278 | run.bounds.size.x = iMax(avail, dims.x); /* Extends to the right edge for selection. */ | ||
279 | run.bounds.size.y = dims.y; | ||
280 | run.visBounds = run.bounds; | ||
281 | run.visBounds.size.x = dims.x; | ||
277 | if (contPos > runLine.start) { | 282 | if (contPos > runLine.start) { |
278 | run.text = (iRangecc){ runLine.start, contPos }; | 283 | run.text = (iRangecc){ runLine.start, contPos }; |
279 | } | 284 | } |
@@ -435,7 +440,15 @@ const iGmRun *findRun_GmDocument(const iGmDocument *d, iInt2 pos) { | |||
435 | return NULL; | 440 | return NULL; |
436 | } | 441 | } |
437 | 442 | ||
438 | const iGmRun *findRunCStr_GmDocument(const iGmDocument *d, const char *textCStr) { | 443 | const char *findLoc_GmDocument(const iGmDocument *d, iInt2 pos) { |
444 | const iGmRun *run = findRun_GmDocument(d, pos); | ||
445 | if (run) { | ||
446 | return findLoc_GmRun(run, pos); | ||
447 | } | ||
448 | return NULL; | ||
449 | } | ||
450 | |||
451 | const iGmRun *findRunAtLoc_GmDocument(const iGmDocument *d, const char *textCStr) { | ||
439 | iConstForEach(Array, i, &d->layout) { | 452 | iConstForEach(Array, i, &d->layout) { |
440 | const iGmRun *run = i.value; | 453 | const iGmRun *run = i.value; |
441 | if (contains_Range(&run->text, textCStr) || run->text.start > textCStr /* went past */) { | 454 | if (contains_Range(&run->text, textCStr) || run->text.start > textCStr /* went past */) { |
@@ -457,4 +470,11 @@ const iString *title_GmDocument(const iGmDocument *d) { | |||
457 | return &d->title; | 470 | return &d->title; |
458 | } | 471 | } |
459 | 472 | ||
473 | const char *findLoc_GmRun(const iGmRun *d, iInt2 pos) { | ||
474 | const int x = pos.x - left_Rect(d->bounds); | ||
475 | const char *loc; | ||
476 | tryAdvanceNoWrap_Text(d->font, d->text, x, &loc); | ||
477 | return loc; | ||
478 | } | ||
479 | |||
460 | iDefineClass(GmDocument) | 480 | iDefineClass(GmDocument) |