summaryrefslogtreecommitdiff
path: root/src/ui/inputwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-07-27 18:55:19 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-07-27 18:55:19 +0300
commitae8cdc792cfa402d99fb3717c2d9ad7d56d4a9b2 (patch)
treea0f762fc46cd228d47126e9c53a5757374212bce /src/ui/inputwidget.c
parent68f36a4b8d8717e9dc0525e0e6f8d2ca5574b34d (diff)
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.
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r--src/ui/inputwidget.c20
1 files 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. */
41 41
42static const int refreshInterval_InputWidget_ = 256; 42static const int refreshInterval_InputWidget_ = 256;
43static const size_t maxUndo_InputWidget_ = 64; 43static const size_t maxUndo_InputWidget_ = 64;
44static const int unlimitedWidth_InputWidget_ = 1000000; /* TODO: WrapText disables some functionality if maxWidth==0 */
44 45
45static void enableEditorKeysInMenus_(iBool enable) { 46static void enableEditorKeysInMenus_(iBool enable) {
46#if defined (iPlatformAppleDesktop) 47#if defined (iPlatformAppleDesktop)
@@ -420,9 +421,10 @@ static const char *sensitive_ = "\u25cf";
420static iWrapText wrap_InputWidget_(const iInputWidget *d, int y) { 421static iWrapText wrap_InputWidget_(const iInputWidget *d, int y) {
421 return (iWrapText){ 422 return (iWrapText){
422 .text = range_String(&line_InputWidget_(d, y)->text), 423 .text = range_String(&line_InputWidget_(d, y)->text),
423 .maxWidth = d->maxLen == 0 ? width_Rect(contentBounds_InputWidget_(d)) : 0, 424 .maxWidth = d->maxLen == 0 ? width_Rect(contentBounds_InputWidget_(d))
424 .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode 425 : unlimitedWidth_InputWidget_,
425 : word_WrapTextMode), 426 .mode =
427 (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode),
426 .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), 428 .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0),
427 }; 429 };
428} 430}
@@ -829,13 +831,13 @@ void setText_InputWidget(iInputWidget *d, const iString *text) {
829 updateLine_InputWidget_(d, i.value); /* count number of visible lines */ 831 updateLine_InputWidget_(d, i.value); /* count number of visible lines */
830 } 832 }
831 updateLineRangesStartingFrom_InputWidget_(d, 0); 833 updateLineRangesStartingFrom_InputWidget_(d, 0);
832 //if (isFocused_Widget(d)) { 834 d->cursor = cursorMax_InputWidget_(d);
833 d->cursor = cursorMax_InputWidget_(d); 835 if (!isFocused_Widget(d)) {
834// } 836 iZap(d->mark);
837 }
835// else { 838// else {
836// d->cursor.y = iMin(d->cursor.y, (int) size_Array(&d->lines) - 1); 839// d->cursor.y = iMin(d->cursor.y, (int) size_Array(&d->lines) - 1);
837// d->cursor.x = iMin(d->cursor.x, size_String(&cursorLine_InputWidget_(d)->text)); 840// d->cursor.x = iMin(d->cursor.x, size_String(&cursorLine_InputWidget_(d)->text));
838 iZap(d->mark);
839// } 841// }
840 if (!isFocused_Widget(d)) { 842 if (!isFocused_Widget(d)) {
841 d->inFlags |= needUpdateBuffer_InputWidgetFlag; 843 d->inFlags |= needUpdateBuffer_InputWidgetFlag;
@@ -1257,7 +1259,7 @@ static iInt2 coordCursor_InputWidget_(const iInputWidget *d, iInt2 coord) {
1257 return cursorMax_InputWidget_(d); 1259 return cursorMax_InputWidget_(d);
1258 } 1260 }
1259 iWrapText wrapText = { 1261 iWrapText wrapText = {
1260 .maxWidth = d->maxLen == 0 ? width_Rect(bounds) : 0, 1262 .maxWidth = d->maxLen == 0 ? width_Rect(bounds) : unlimitedWidth_InputWidget_,
1261 .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode), 1263 .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode : word_WrapTextMode),
1262 .hitPoint = relCoord, 1264 .hitPoint = relCoord,
1263 .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), 1265 .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0),
@@ -1839,7 +1841,7 @@ static void draw_InputWidget_(const iInputWidget *d) {
1839 : isFocused /*&& !isEmpty_Array(&d->lines)*/ ? uiInputTextFocused_ColorId 1841 : isFocused /*&& !isEmpty_Array(&d->lines)*/ ? uiInputTextFocused_ColorId
1840 : uiInputText_ColorId; 1842 : uiInputText_ColorId;
1841 iWrapText wrapText = { 1843 iWrapText wrapText = {
1842 .maxWidth = d->maxLen == 0 ? width_Rect(contentBounds) : 0, 1844 .maxWidth = d->maxLen == 0 ? width_Rect(contentBounds) : unlimitedWidth_InputWidget_,
1843 .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode 1845 .mode = (d->inFlags & isUrl_InputWidgetFlag ? anyCharacter_WrapTextMode
1844 : word_WrapTextMode), 1846 : word_WrapTextMode),
1845 .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0), 1847 .overrideChar = (d->inFlags & isSensitive_InputWidgetFlag ? sensitiveChar_ : 0),