diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-20 18:58:52 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-20 18:58:52 +0300 |
commit | d3d15b308b05b0cead00b0adba20f6bee172341d (patch) | |
tree | 4c857e24cc9bebc376ac1c149794793d6fb9ccfe /src/gmdocument.c | |
parent | fabff758122481dab88d13258db191980a90b678 (diff) |
Improved text selection starting on empty space
IssueID #4
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index ad47f693..39c45c80 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -1083,13 +1083,29 @@ iRangecc findTextBefore_GmDocument(const iGmDocument *d, const iString *text, co | |||
1083 | 1083 | ||
1084 | const iGmRun *findRun_GmDocument(const iGmDocument *d, iInt2 pos) { | 1084 | const iGmRun *findRun_GmDocument(const iGmDocument *d, iInt2 pos) { |
1085 | /* TODO: Perf optimization likely needed; use a block map? */ | 1085 | /* TODO: Perf optimization likely needed; use a block map? */ |
1086 | const iGmRun *last = NULL; | ||
1087 | iBool isFirstNonDecoration = iTrue; | ||
1086 | iConstForEach(Array, i, &d->layout) { | 1088 | iConstForEach(Array, i, &d->layout) { |
1087 | const iGmRun *run = i.value; | 1089 | const iGmRun *run = i.value; |
1088 | if (contains_Rect(run->bounds, pos)) { | 1090 | if (run->flags & decoration_GmRunFlag) continue; |
1089 | return run; | 1091 | const iRangei span = ySpan_Rect(run->bounds); |
1092 | if (contains_Range(&span, pos.y)) { | ||
1093 | last = run; | ||
1094 | break; | ||
1095 | } | ||
1096 | if (isFirstNonDecoration && pos.y < top_Rect(run->bounds)) { | ||
1097 | last = run; | ||
1098 | break; | ||
1090 | } | 1099 | } |
1100 | if (top_Rect(run->bounds) > pos.y) break; /* Below the point. */ | ||
1101 | last = run; | ||
1102 | isFirstNonDecoration = iFalse; | ||
1091 | } | 1103 | } |
1092 | return NULL; | 1104 | // if (last) { |
1105 | // printf("found run at (%d,%d): %p [%s]\n", pos.x, pos.y, last, cstr_Rangecc(last->text)); | ||
1106 | // fflush(stdout); | ||
1107 | // } | ||
1108 | return last; | ||
1093 | } | 1109 | } |
1094 | 1110 | ||
1095 | const char *findLoc_GmDocument(const iGmDocument *d, iInt2 pos) { | 1111 | const char *findLoc_GmDocument(const iGmDocument *d, iInt2 pos) { |
@@ -1229,7 +1245,13 @@ iChar siteIcon_GmDocument(const iGmDocument *d) { | |||
1229 | } | 1245 | } |
1230 | 1246 | ||
1231 | const char *findLoc_GmRun(const iGmRun *d, iInt2 pos) { | 1247 | const char *findLoc_GmRun(const iGmRun *d, iInt2 pos) { |
1248 | if (pos.y < top_Rect(d->bounds)) { | ||
1249 | return d->text.start; | ||
1250 | } | ||
1232 | const int x = pos.x - left_Rect(d->bounds); | 1251 | const int x = pos.x - left_Rect(d->bounds); |
1252 | if (x <= 0) { | ||
1253 | return d->text.start; | ||
1254 | } | ||
1233 | const char *loc; | 1255 | const char *loc; |
1234 | tryAdvanceNoWrap_Text(d->font, d->text, x, &loc); | 1256 | tryAdvanceNoWrap_Text(d->font, d->text, x, &loc); |
1235 | return loc; | 1257 | return loc; |