From b181150bad024e35a85386085efb096abd7d6901 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 24 Aug 2021 14:25:02 +0300 Subject: 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. --- src/ui/inputwidget.c | 22 +++++++++++----------- src/ui/text.c | 22 +++++++++------------- 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) { /*----------------------------------------------------------------------------------------------*/ iDeclareType(InputLine) - + struct Impl_InputLine { iString text; iRanges range; /* byte offset inside the entire content; for marking */ @@ -157,7 +157,7 @@ static void mergeLines_(const iArray *inputLines, iString *merged) { } iDefineTypeConstruction(InputLine) - + /*----------------------------------------------------------------------------------------------*/ iDeclareType(InputUndo) @@ -227,7 +227,7 @@ struct Impl_InputWidget { }; iDefineObjectConstructionArgs(InputWidget, (size_t maxLen), maxLen) - + static void updateMetrics_InputWidget_(iInputWidget *); static void restoreBackup_InputWidget_(iInputWidget *d) { @@ -610,7 +610,7 @@ static uint32_t cursorTimer_(uint32_t interval, void *w) { static void startOrStopCursorTimer_InputWidget_(iInputWidget *d, iBool doStart) { if (doStart && !d->timer) { - d->timer = SDL_AddTimer(refreshInterval_InputWidget_, cursorTimer_, d); + d->timer = SDL_AddTimer(refreshInterval_InputWidget_, cursorTimer_, d); } else if (!doStart && d->timer) { SDL_RemoveTimer(d->timer); @@ -679,7 +679,7 @@ void deinit_InputWidget(iInputWidget *d) { delete_TextBuf(d->buffered); clearUndo_InputWidget_(d); deinit_Array(&d->undoStack); - startOrStopCursorTimer_InputWidget_(d, iFalse); + startOrStopCursorTimer_InputWidget_(d, iFalse); deinit_String(&d->srcHint); deinit_String(&d->hint); deinit_String(&d->oldText); @@ -708,7 +708,7 @@ static iBool popUndo_InputWidget_(iInputWidget *d) { splitToLines_(&undo->text, &d->lines); d->cursor = undo->cursor; deinit_InputUndo_(undo); - popBack_Array(&d->undoStack); + popBack_Array(&d->undoStack); iZap(d->mark); updateAllLinesAndResizeHeight_InputWidget_(d); return iTrue; @@ -836,7 +836,7 @@ static iRangei visibleLineRange_InputWidget_(const iInputWidget *d) { static void updateBuffered_InputWidget_(iInputWidget *d) { invalidateBuffered_InputWidget_(d); if (isHintVisible_InputWidget_(d)) { - d->buffered = newRange_TextBuf(d->font, uiAnnotation_ColorId, range_String(&d->hint)); + d->buffered = newRange_TextBuf(d->font, uiAnnotation_ColorId, range_String(&d->hint)); } else { /* Draw all the potentially visible lines to a buffer. */ @@ -1073,7 +1073,7 @@ static void insertRange_InputWidget_(iInputWidget *d, iRangecc range) { } textOfLinesWasChanged_InputWidget_(d, (iRangei){ firstModified, d->cursor.y + 1 }); showCursor_InputWidget_(d); - refresh_Widget(as_Widget(d)); + refresh_Widget(as_Widget(d)); } static void insertChar_InputWidget_(iInputWidget *d, iChar chr) { @@ -1110,7 +1110,7 @@ void setCursor_InputWidget(iInputWidget *d, iInt2 pos) { static iBool moveCursorByLine_InputWidget_(iInputWidget *d, int dir, int horiz) { const iInputLine *line = cursorLine_InputWidget_(d); iInt2 relCoord = relativeCursorCoord_InputWidget_(d); - int relLine = relCoord.y / lineHeight_Text(d->font); + int relLine = relCoord.y / lineHeight_Text(d->font); if ((dir < 0 && relLine > 0) || (dir > 0 && relLine < numWrapLines_InputLine_(line) - 1)) { relCoord.y += dir * lineHeight_Text(d->font); } @@ -1542,7 +1542,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { else if (lineDelta > 0) { lineDelta = iMin(lineDelta, lastLine_InputWidget_(d)->wrapLines.end - d->visWrapLines.end); - if (!lineDelta) d->wheelAccum = 0; + if (!lineDelta) d->wheelAccum = 0; } d->wheelAccum -= lineDelta * lineHeight; d->visWrapLines.start += lineDelta; @@ -1925,7 +1925,7 @@ static void draw_InputWidget_(const iInputWidget *d) { } iPaint p; init_Paint(&p); - /* `lines` is already up to date and ready for drawing. */ + /* `lines` is already up to date and ready for drawing. */ fillRect_Paint( &p, bounds, isFocused ? uiInputBackgroundFocused_ColorId : uiInputBackground_ColorId); 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, d->vertOffset = height * (1.0f - scale) / 2; /* Custom tweaks. */ if (data == &fontNotoSansSymbolsRegular_Embedded) { - d->vertOffset *= 1.2f; + d->vertOffset *= 1.2f; } else if (data == &fontNotoSansSymbols2Regular_Embedded) { d->vertOffset /= 2; @@ -1433,7 +1433,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { iBool isFirst = iTrue; const iBool checkHitPoint = wrap && !isEqual_I2(wrap->hitPoint, zero_I2()); const iBool checkHitChar = wrap && wrap->hitChar; - iBool wasCharHit = iFalse; + //iBool wasCharHit = iFalse; while (!isEmpty_Range(&wrapRuns)) { if (isFirst) { isFirst = iFalse; @@ -1453,11 +1453,9 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { for (size_t runIndex = wrapRuns.start; runIndex < wrapRuns.end; runIndex++) { const iAttributedRun *run = at_Array(&attrText.runs, runIndex); if (run->flags.isLineBreak) { - if (checkHitChar && !wasCharHit) { - if (wrap->hitChar == sourcePtr_AttributedText_(&attrText, run->logical.start)) { - wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor); - wasCharHit = iTrue; - } + if (checkHitChar && wrap->hitChar == sourcePtr_AttributedText_(&attrText, run->logical.start)) { + wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor); +// wasCharHit = iTrue; } wrapPosRange.end = run->logical.start; wrapResumePos = run->logical.end; @@ -1481,11 +1479,9 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { if (logPos < wrapPosRange.start || logPos >= wrapPosRange.end) { continue; } - if (checkHitChar && !wasCharHit) { - if (wrap->hitChar == sourcePtr_AttributedText_(&attrText, logPos)) { - wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor); - wasCharHit = iTrue; - } + if (checkHitChar && wrap->hitChar == sourcePtr_AttributedText_(&attrText, logPos)) { + wrap->hitAdvance_out = init_I2(wrapAdvance, yCursor); + //wasCharHit = iTrue; } /* Check if the hit point is on the left side of this line. */ 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, (color & fillBackground_ColorId ? fillBackground_RunMode : 0) | runFlagsFromId_(fontId), .text = text, - .maxLen = maxLen, + .maxLen = maxLen, .pos = pos, // .xposLayoutBound = xposBound, .color = color & mask_ColorId, -- cgit v1.2.3