summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-08-24 14:25:02 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-08-24 14:25:02 +0300
commitb181150bad024e35a85386085efb096abd7d6901 (patch)
tree8ea6757d3b46ae77c84e9873b7eb9c5bbdbfab93 /src/ui
parentb770246f447761d178336c53808a53f567ba4eb9 (diff)
InputWidget: Reverted an earlier change to fix cursor movement regression
In word-wrapped lines, a character will be hit multiple times and the latest hit is what counts.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/inputwidget.c22
-rw-r--r--src/ui/text.c22
2 files changed, 20 insertions, 24 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index e0272a5d..fa65cf3c 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -59,7 +59,7 @@ static void enableEditorKeysInMenus_(iBool enable) {
59/*----------------------------------------------------------------------------------------------*/ 59/*----------------------------------------------------------------------------------------------*/
60 60
61iDeclareType(InputLine) 61iDeclareType(InputLine)
62 62
63struct Impl_InputLine { 63struct Impl_InputLine {
64 iString text; 64 iString text;
65 iRanges range; /* byte offset inside the entire content; for marking */ 65 iRanges range; /* byte offset inside the entire content; for marking */
@@ -157,7 +157,7 @@ static void mergeLines_(const iArray *inputLines, iString *merged) {
157} 157}
158 158
159iDefineTypeConstruction(InputLine) 159iDefineTypeConstruction(InputLine)
160 160
161/*----------------------------------------------------------------------------------------------*/ 161/*----------------------------------------------------------------------------------------------*/
162 162
163iDeclareType(InputUndo) 163iDeclareType(InputUndo)
@@ -227,7 +227,7 @@ struct Impl_InputWidget {
227}; 227};
228 228
229iDefineObjectConstructionArgs(InputWidget, (size_t maxLen), maxLen) 229iDefineObjectConstructionArgs(InputWidget, (size_t maxLen), maxLen)
230 230
231static void updateMetrics_InputWidget_(iInputWidget *); 231static void updateMetrics_InputWidget_(iInputWidget *);
232 232
233static void restoreBackup_InputWidget_(iInputWidget *d) { 233static void restoreBackup_InputWidget_(iInputWidget *d) {
@@ -610,7 +610,7 @@ static uint32_t cursorTimer_(uint32_t interval, void *w) {
610 610
611static void startOrStopCursorTimer_InputWidget_(iInputWidget *d, iBool doStart) { 611static void startOrStopCursorTimer_InputWidget_(iInputWidget *d, iBool doStart) {
612 if (doStart && !d->timer) { 612 if (doStart && !d->timer) {
613 d->timer = SDL_AddTimer(refreshInterval_InputWidget_, cursorTimer_, d); 613 d->timer = SDL_AddTimer(refreshInterval_InputWidget_, cursorTimer_, d);
614 } 614 }
615 else if (!doStart && d->timer) { 615 else if (!doStart && d->timer) {
616 SDL_RemoveTimer(d->timer); 616 SDL_RemoveTimer(d->timer);
@@ -679,7 +679,7 @@ void deinit_InputWidget(iInputWidget *d) {
679 delete_TextBuf(d->buffered); 679 delete_TextBuf(d->buffered);
680 clearUndo_InputWidget_(d); 680 clearUndo_InputWidget_(d);
681 deinit_Array(&d->undoStack); 681 deinit_Array(&d->undoStack);
682 startOrStopCursorTimer_InputWidget_(d, iFalse); 682 startOrStopCursorTimer_InputWidget_(d, iFalse);
683 deinit_String(&d->srcHint); 683 deinit_String(&d->srcHint);
684 deinit_String(&d->hint); 684 deinit_String(&d->hint);
685 deinit_String(&d->oldText); 685 deinit_String(&d->oldText);
@@ -708,7 +708,7 @@ static iBool popUndo_InputWidget_(iInputWidget *d) {
708 splitToLines_(&undo->text, &d->lines); 708 splitToLines_(&undo->text, &d->lines);
709 d->cursor = undo->cursor; 709 d->cursor = undo->cursor;
710 deinit_InputUndo_(undo); 710 deinit_InputUndo_(undo);
711 popBack_Array(&d->undoStack); 711 popBack_Array(&d->undoStack);
712 iZap(d->mark); 712 iZap(d->mark);
713 updateAllLinesAndResizeHeight_InputWidget_(d); 713 updateAllLinesAndResizeHeight_InputWidget_(d);
714 return iTrue; 714 return iTrue;
@@ -836,7 +836,7 @@ static iRangei visibleLineRange_InputWidget_(const iInputWidget *d) {
836static void updateBuffered_InputWidget_(iInputWidget *d) { 836static void updateBuffered_InputWidget_(iInputWidget *d) {
837 invalidateBuffered_InputWidget_(d); 837 invalidateBuffered_InputWidget_(d);
838 if (isHintVisible_InputWidget_(d)) { 838 if (isHintVisible_InputWidget_(d)) {
839 d->buffered = newRange_TextBuf(d->font, uiAnnotation_ColorId, range_String(&d->hint)); 839 d->buffered = newRange_TextBuf(d->font, uiAnnotation_ColorId, range_String(&d->hint));
840 } 840 }
841 else { 841 else {
842 /* Draw all the potentially visible lines to a buffer. */ 842 /* Draw all the potentially visible lines to a buffer. */
@@ -1073,7 +1073,7 @@ static void insertRange_InputWidget_(iInputWidget *d, iRangecc range) {
1073 } 1073 }
1074 textOfLinesWasChanged_InputWidget_(d, (iRangei){ firstModified, d->cursor.y + 1 }); 1074 textOfLinesWasChanged_InputWidget_(d, (iRangei){ firstModified, d->cursor.y + 1 });
1075 showCursor_InputWidget_(d); 1075 showCursor_InputWidget_(d);
1076 refresh_Widget(as_Widget(d)); 1076 refresh_Widget(as_Widget(d));
1077} 1077}
1078 1078
1079static void insertChar_InputWidget_(iInputWidget *d, iChar chr) { 1079static void insertChar_InputWidget_(iInputWidget *d, iChar chr) {
@@ -1110,7 +1110,7 @@ void setCursor_InputWidget(iInputWidget *d, iInt2 pos) {
1110static iBool moveCursorByLine_InputWidget_(iInputWidget *d, int dir, int horiz) { 1110static iBool moveCursorByLine_InputWidget_(iInputWidget *d, int dir, int horiz) {
1111 const iInputLine *line = cursorLine_InputWidget_(d); 1111 const iInputLine *line = cursorLine_InputWidget_(d);
1112 iInt2 relCoord = relativeCursorCoord_InputWidget_(d); 1112 iInt2 relCoord = relativeCursorCoord_InputWidget_(d);
1113 int relLine = relCoord.y / lineHeight_Text(d->font); 1113 int relLine = relCoord.y / lineHeight_Text(d->font);
1114 if ((dir < 0 && relLine > 0) || (dir > 0 && relLine < numWrapLines_InputLine_(line) - 1)) { 1114 if ((dir < 0 && relLine > 0) || (dir > 0 && relLine < numWrapLines_InputLine_(line) - 1)) {
1115 relCoord.y += dir * lineHeight_Text(d->font); 1115 relCoord.y += dir * lineHeight_Text(d->font);
1116 } 1116 }
@@ -1542,7 +1542,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
1542 else if (lineDelta > 0) { 1542 else if (lineDelta > 0) {
1543 lineDelta = iMin(lineDelta, 1543 lineDelta = iMin(lineDelta,
1544 lastLine_InputWidget_(d)->wrapLines.end - d->visWrapLines.end); 1544 lastLine_InputWidget_(d)->wrapLines.end - d->visWrapLines.end);
1545 if (!lineDelta) d->wheelAccum = 0; 1545 if (!lineDelta) d->wheelAccum = 0;
1546 } 1546 }
1547 d->wheelAccum -= lineDelta * lineHeight; 1547 d->wheelAccum -= lineDelta * lineHeight;
1548 d->visWrapLines.start += lineDelta; 1548 d->visWrapLines.start += lineDelta;
@@ -1925,7 +1925,7 @@ static void draw_InputWidget_(const iInputWidget *d) {
1925 } 1925 }
1926 iPaint p; 1926 iPaint p;
1927 init_Paint(&p); 1927 init_Paint(&p);
1928 /* `lines` is already up to date and ready for drawing. */ 1928 /* `lines` is already up to date and ready for drawing. */
1929 fillRect_Paint( 1929 fillRect_Paint(
1930 &p, bounds, isFocused ? uiInputBackgroundFocused_ColorId : uiInputBackground_ColorId); 1930 &p, bounds, isFocused ? uiInputBackgroundFocused_ColorId : uiInputBackground_ColorId);
1931 drawRectThickness_Paint(&p, 1931 drawRectThickness_Paint(&p,
diff --git a/src/ui/text.c b/src/ui/text.c
index 639d8f13..a499d293 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -195,7 +195,7 @@ static void init_Font(iFont *d, const iBlock *data, int height, float scale,
195 d->vertOffset = height * (1.0f - scale) / 2; 195 d->vertOffset = height * (1.0f - scale) / 2;
196 /* Custom tweaks. */ 196 /* Custom tweaks. */
197 if (data == &fontNotoSansSymbolsRegular_Embedded) { 197 if (data == &fontNotoSansSymbolsRegular_Embedded) {
198 d->vertOffset *= 1.2f; 198 d->vertOffset *= 1.2f;
199 } 199 }
200 else if (data == &fontNotoSansSymbols2Regular_Embedded) { 200 else if (data == &fontNotoSansSymbols2Regular_Embedded) {
201 d->vertOffset /= 2; 201 d->vertOffset /= 2;
@@ -1433,7 +1433,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1433 iBool isFirst = iTrue; 1433 iBool isFirst = iTrue;
1434 const iBool checkHitPoint = wrap && !isEqual_I2(wrap->hitPoint, zero_I2()); 1434 const iBool checkHitPoint = wrap && !isEqual_I2(wrap->hitPoint, zero_I2());
1435 const iBool checkHitChar = wrap && wrap->hitChar; 1435 const iBool checkHitChar = wrap && wrap->hitChar;
1436 iBool wasCharHit = iFalse; 1436 //iBool wasCharHit = iFalse;
1437 while (!isEmpty_Range(&wrapRuns)) { 1437 while (!isEmpty_Range(&wrapRuns)) {
1438 if (isFirst) { 1438 if (isFirst) {
1439 isFirst = iFalse; 1439 isFirst = iFalse;
@@ -1453,11 +1453,9 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1453 for (size_t runIndex = wrapRuns.start; runIndex < wrapRuns.end; runIndex++) { 1453 for (size_t runIndex = wrapRuns.start; runIndex < wrapRuns.end; runIndex++) {
1454 const iAttributedRun *run = at_Array(&attrText.runs, runIndex); 1454 const iAttributedRun *run = at_Array(&attrText.runs, runIndex);
1455 if (run->flags.isLineBreak) { 1455 if (run->flags.isLineBreak) {
1456 if (checkHitChar && !wasCharHit) { 1456 if (checkHitChar && wrap->hitChar == sourcePtr_AttributedText_(&attrText, run->logical.start)) {
1457 if (wrap->hitChar == sourcePtr_AttributedText_(&attrText, run->logical.start)) { 1457 wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor);
1458 wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor); 1458// wasCharHit = iTrue;
1459 wasCharHit = iTrue;
1460 }
1461 } 1459 }
1462 wrapPosRange.end = run->logical.start; 1460 wrapPosRange.end = run->logical.start;
1463 wrapResumePos = run->logical.end; 1461 wrapResumePos = run->logical.end;
@@ -1481,11 +1479,9 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) {
1481 if (logPos < wrapPosRange.start || logPos >= wrapPosRange.end) { 1479 if (logPos < wrapPosRange.start || logPos >= wrapPosRange.end) {
1482 continue; 1480 continue;
1483 } 1481 }
1484 if (checkHitChar && !wasCharHit) { 1482 if (checkHitChar && wrap->hitChar == sourcePtr_AttributedText_(&attrText, logPos)) {
1485 if (wrap->hitChar == sourcePtr_AttributedText_(&attrText, logPos)) { 1483 wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor);
1486 wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor); 1484 //wasCharHit = iTrue;
1487 wasCharHit = iTrue;
1488 }
1489 } 1485 }
1490 /* Check if the hit point is on the left side of this line. */ 1486 /* Check if the hit point is on the left side of this line. */
1491 if (isHitPointOnThisLine && !wrap->hitChar_out && wrap->hitPoint.x < orig.x) { 1487 if (isHitPointOnThisLine && !wrap->hitChar_out && wrap->hitPoint.x < orig.x) {
@@ -1872,7 +1868,7 @@ static void drawBoundedN_Text_(int fontId, iInt2 pos, int xposBound, int color,
1872 (color & fillBackground_ColorId ? fillBackground_RunMode : 0) | 1868 (color & fillBackground_ColorId ? fillBackground_RunMode : 0) |
1873 runFlagsFromId_(fontId), 1869 runFlagsFromId_(fontId),
1874 .text = text, 1870 .text = text,
1875 .maxLen = maxLen, 1871 .maxLen = maxLen,
1876 .pos = pos, 1872 .pos = pos,
1877// .xposLayoutBound = xposBound, 1873// .xposLayoutBound = xposBound,
1878 .color = color & mask_ColorId, 1874 .color = color & mask_ColorId,