From ae8cdc792cfa402d99fb3717c2d9ad7d56d4a9b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi
Date: Tue, 27 Jul 2021 18:55:19 +0300
Subject: [PATCH 1/1] InputWidget: Fixed cursor and selection issues
Cursor position was miscalculated because WrapText works a bit differently with maxWidth==0.
Selection was not always updated as intended.
src/ui/inputwidget.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index 1d036939..c9779ff0 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -41,6 +41,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
static const int refreshInterval_InputWidget_ = 256;
static const size_t maxUndo_InputWidget_ = 64;
+static const int unlimitedWidth_InputWidget_ = 1000000; /* TODO: WrapText disables some functionality if maxWidth==0 */
static void enableEditorKeysInMenus_(iBool enable) {
#if defined (iPlatformAppleDesktop)
@@ -420,9 +421,10 @@ static const char *sensitive_ = "\u25cf";
static iWrapText wrap_InputWidget_(const iInputWidget *d, int y) {
return (iWrapText){
.text = range_String(&line_InputWidget_(d, y)->text),
.maxWidth = d->maxLen == 0 ? width_Rect(contentBounds_InputWidget_(d)) : 0,
.mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode
: word_WrapTextMode),
.maxWidth = d->maxLen == 0 ? width_Rect(contentBounds_InputWidget_(d))
: unlimitedWidth_InputWidget_,
.mode =
(d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode),
.overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0),
};
}
@@ -829,13 +831,13 @@ void setText_InputWidget(iInputWidget *d, const iString *text) {
updateLine_InputWidget_(d, i.value); /* count number of visible lines */
}
updateLineRangesStartingFrom_InputWidget_(d, 0);
d->cursor = cursorMax_InputWidget_(d);
-// }
iZap(d->mark);
// else {
// d->cursor.y = iMin(d->cursor.y, (int) size_Array(&d->lines) - 1);
// d->cursor.x = iMin(d->cursor.x, size_String(&cursorLine_InputWidget_(d)->text));
iZap(d->mark);
// }
if (!isFocused_Widget(d)) {
d->inFlags |= needUpdateBuffer_InputWidgetFlag;
@@ -1257,7 +1259,7 @@ static iInt2 coordCursor_InputWidget_(const iInputWidget *d, iInt2 coord) {
return cursorMax_InputWidget_(d);
}
iWrapText wrapText = {
.maxWidth = d->maxLen == 0 ? width_Rect(bounds) : 0,
.maxWidth = d->maxLen == 0 ? width_Rect(bounds) : unlimitedWidth_InputWidget_,
.mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode),
.hitPoint = relCoord,
.overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0),
@@ -1839,7 +1841,7 @@ static void draw_InputWidget_(const iInputWidget *d) {
: isFocused /*&& !isEmpty_Array(&d->lines)*/ ? uiInputTextFocused_ColorId
: uiInputText_ColorId;
iWrapText wrapText = {
.maxWidth = d->maxLen == 0 ? width_Rect(contentBounds) : 0,
.maxWidth = d->maxLen == 0 ? width_Rect(contentBounds) : unlimitedWidth_InputWidget_,
.mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode
: word_WrapTextMode),
.overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0),
--
2.25.1
text/plain
This content has been proxied by September (ba2dc).