diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-08-04 06:49:40 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-08-04 06:49:40 +0300 |
commit | 7ff362911267649d796481a4126fba1e56108786 (patch) | |
tree | 647faf192e881218414447fddf8390582456dc1f | |
parent | a3cfeba41e5cd25d9e2e2c8022281b0dbdb82407 (diff) |
InputWidget: Line breaks only make sense in some fields
For example, any URL field should disallow line breaks. The line break modifier preference should be disregarded in an input field where there are no line breaks.
-rw-r--r-- | src/ui/inputwidget.c | 27 | ||||
-rw-r--r-- | src/ui/inputwidget.h | 2 | ||||
-rw-r--r-- | src/ui/root.c | 3 | ||||
-rw-r--r-- | src/ui/uploadwidget.c | 1 |
4 files changed, 17 insertions, 16 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 51d62125..d31130f5 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -188,8 +188,7 @@ enum iInputWidgetFlag { | |||
188 | markWords_InputWidgetFlag = iBit(8), | 188 | markWords_InputWidgetFlag = iBit(8), |
189 | needUpdateBuffer_InputWidgetFlag = iBit(9), | 189 | needUpdateBuffer_InputWidgetFlag = iBit(9), |
190 | enterKeyEnabled_InputWidgetFlag = iBit(10), | 190 | enterKeyEnabled_InputWidgetFlag = iBit(10), |
191 | enterKeyInsertsLineFeed_InputWidgetFlag | 191 | lineBreaksEnabled_InputWidgetFlag= iBit(11), |
192 | = iBit(11), | ||
193 | needBackup_InputWidgetFlag = iBit(12), | 192 | needBackup_InputWidgetFlag = iBit(12), |
194 | }; | 193 | }; |
195 | 194 | ||
@@ -588,10 +587,11 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) { | |||
588 | d->cursor = zero_I2(); | 587 | d->cursor = zero_I2(); |
589 | d->prevCursor = zero_I2(); | 588 | d->prevCursor = zero_I2(); |
590 | d->lastUpdateWidth = 0; | 589 | d->lastUpdateWidth = 0; |
591 | d->inFlags = eatEscape_InputWidgetFlag | enterKeyEnabled_InputWidgetFlag; | 590 | d->inFlags = eatEscape_InputWidgetFlag | enterKeyEnabled_InputWidgetFlag | |
592 | if (deviceType_App() != desktop_AppDeviceType) { | 591 | lineBreaksEnabled_InputWidgetFlag; |
593 | d->inFlags |= enterKeyInsertsLineFeed_InputWidgetFlag; | 592 | // if (deviceType_App() != desktop_AppDeviceType) { |
594 | } | 593 | // d->inFlags |= enterKeyInsertsLineFeed_InputWidgetFlag; |
594 | // } | ||
595 | iZap(d->mark); | 595 | iZap(d->mark); |
596 | setMaxLen_InputWidget(d, maxLen); | 596 | setMaxLen_InputWidget(d, maxLen); |
597 | d->visWrapLines.start = 0; | 597 | d->visWrapLines.start = 0; |
@@ -732,8 +732,8 @@ void setValidator_InputWidget(iInputWidget *d, iInputWidgetValidatorFunc validat | |||
732 | d->validatorContext = context; | 732 | d->validatorContext = context; |
733 | } | 733 | } |
734 | 734 | ||
735 | void setEnterInsertsLF_InputWidget(iInputWidget *d, iBool enterInsertsLF) { | 735 | void setLineBreaksEnabled_InputWidget(iInputWidget *d, iBool lineBreaksEnabled) { |
736 | iChangeFlags(d->inFlags, enterKeyInsertsLineFeed_InputWidgetFlag, enterInsertsLF); | 736 | iChangeFlags(d->inFlags, lineBreaksEnabled_InputWidgetFlag, lineBreaksEnabled); |
737 | } | 737 | } |
738 | 738 | ||
739 | void setEnterKeyEnabled_InputWidget(iInputWidget *d, iBool enterKeyEnabled) { | 739 | void setEnterKeyEnabled_InputWidget(iInputWidget *d, iBool enterKeyEnabled) { |
@@ -1614,10 +1614,10 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
1614 | return iTrue; | 1614 | return iTrue; |
1615 | case SDLK_RETURN: | 1615 | case SDLK_RETURN: |
1616 | case SDLK_KP_ENTER: | 1616 | case SDLK_KP_ENTER: |
1617 | if (~d->inFlags & isSensitive_InputWidgetFlag && d->maxLen == 0) { | 1617 | if (~d->inFlags & isSensitive_InputWidgetFlag && |
1618 | if (mods == lineBreakKeyMod_ReturnKeyBehavior(prefs_App()->returnKey) || | 1618 | ~d->inFlags & isUrl_InputWidgetFlag && |
1619 | (~d->inFlags & isUrl_InputWidgetFlag && | 1619 | d->inFlags & lineBreaksEnabled_InputWidgetFlag && d->maxLen == 0) { |
1620 | d->inFlags & enterKeyInsertsLineFeed_InputWidgetFlag)) { | 1620 | if (mods == lineBreakKeyMod_ReturnKeyBehavior(prefs_App()->returnKey)) { |
1621 | pushUndo_InputWidget_(d); | 1621 | pushUndo_InputWidget_(d); |
1622 | deleteMarked_InputWidget_(d); | 1622 | deleteMarked_InputWidget_(d); |
1623 | insertChar_InputWidget_(d, '\n'); | 1623 | insertChar_InputWidget_(d, '\n'); |
@@ -1626,7 +1626,8 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
1626 | } | 1626 | } |
1627 | } | 1627 | } |
1628 | if (d->inFlags & enterKeyEnabled_InputWidgetFlag && | 1628 | if (d->inFlags & enterKeyEnabled_InputWidgetFlag && |
1629 | mods == acceptKeyMod_ReturnKeyBehavior(prefs_App()->returnKey)) { | 1629 | (mods == acceptKeyMod_ReturnKeyBehavior(prefs_App()->returnKey) || |
1630 | (~d->inFlags & lineBreaksEnabled_InputWidgetFlag))) { | ||
1630 | d->inFlags |= enterPressed_InputWidgetFlag; | 1631 | d->inFlags |= enterPressed_InputWidgetFlag; |
1631 | setFocus_Widget(NULL); | 1632 | setFocus_Widget(NULL); |
1632 | return iTrue; | 1633 | return iTrue; |
diff --git a/src/ui/inputwidget.h b/src/ui/inputwidget.h index a94291ed..f7e46e8c 100644 --- a/src/ui/inputwidget.h +++ b/src/ui/inputwidget.h | |||
@@ -50,7 +50,7 @@ void setFont_InputWidget (iInputWidget *, int fontId); | |||
50 | void setContentPadding_InputWidget (iInputWidget *, int left, int right); /* only affects the text entry */ | 50 | void setContentPadding_InputWidget (iInputWidget *, int left, int right); /* only affects the text entry */ |
51 | void setLineLimits_InputWidget (iInputWidget *, int minLines, int maxLines); | 51 | void setLineLimits_InputWidget (iInputWidget *, int minLines, int maxLines); |
52 | void setValidator_InputWidget (iInputWidget *, iInputWidgetValidatorFunc validator, void *context); | 52 | void setValidator_InputWidget (iInputWidget *, iInputWidgetValidatorFunc validator, void *context); |
53 | void setEnterInsertsLF_InputWidget (iInputWidget *, iBool enterInsertsLF); | 53 | void setLineBreaksEnabled_InputWidget(iInputWidget *, iBool lineBreaksEnabled); |
54 | void setEnterKeyEnabled_InputWidget (iInputWidget *, iBool enterKeyEnabled); | 54 | void setEnterKeyEnabled_InputWidget (iInputWidget *, iBool enterKeyEnabled); |
55 | void setBackupFileName_InputWidget (iInputWidget *, const char *fileName); | 55 | void setBackupFileName_InputWidget (iInputWidget *, const char *fileName); |
56 | void begin_InputWidget (iInputWidget *); | 56 | void begin_InputWidget (iInputWidget *); |
diff --git a/src/ui/root.c b/src/ui/root.c index 9d92c44e..c61f1b35 100644 --- a/src/ui/root.c +++ b/src/ui/root.c | |||
@@ -1077,6 +1077,7 @@ void createUserInterface_Root(iRoot *d) { | |||
1077 | setSelectAllOnFocus_InputWidget(url, iTrue); | 1077 | setSelectAllOnFocus_InputWidget(url, iTrue); |
1078 | setId_Widget(as_Widget(url), "url"); | 1078 | setId_Widget(as_Widget(url), "url"); |
1079 | setLineLimits_InputWidget(url, 1, 1); /* just one line while not focused */ | 1079 | setLineLimits_InputWidget(url, 1, 1); /* just one line while not focused */ |
1080 | setLineBreaksEnabled_InputWidget(url, iFalse); | ||
1080 | setUrlContent_InputWidget(url, iTrue); | 1081 | setUrlContent_InputWidget(url, iTrue); |
1081 | setNotifyEdits_InputWidget(url, iTrue); | 1082 | setNotifyEdits_InputWidget(url, iTrue); |
1082 | setTextCStr_InputWidget(url, "gemini://"); | 1083 | setTextCStr_InputWidget(url, "gemini://"); |
@@ -1272,7 +1273,7 @@ void createUserInterface_Root(iRoot *d) { | |||
1272 | setHint_InputWidget(input, "${hint.findtext}"); | 1273 | setHint_InputWidget(input, "${hint.findtext}"); |
1273 | setSelectAllOnFocus_InputWidget(input, iTrue); | 1274 | setSelectAllOnFocus_InputWidget(input, iTrue); |
1274 | setEatEscape_InputWidget(input, iFalse); /* unfocus and close with one keypress */ | 1275 | setEatEscape_InputWidget(input, iFalse); /* unfocus and close with one keypress */ |
1275 | setEnterInsertsLF_InputWidget(input, iFalse); | 1276 | setLineBreaksEnabled_InputWidget(input, iFalse); |
1276 | setId_Widget(addChildFlags_Widget(searchBar, iClob(input), expand_WidgetFlag), | 1277 | setId_Widget(addChildFlags_Widget(searchBar, iClob(input), expand_WidgetFlag), |
1277 | "find.input"); | 1278 | "find.input"); |
1278 | addChild_Widget(searchBar, iClob(newIcon_LabelWidget(" \u2b9f ", 'g', KMOD_PRIMARY, "find.next"))); | 1279 | addChild_Widget(searchBar, iClob(newIcon_LabelWidget(" \u2b9f ", 'g', KMOD_PRIMARY, "find.next"))); |
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c index 7bfa73bd..2780f86a 100644 --- a/src/ui/uploadwidget.c +++ b/src/ui/uploadwidget.c | |||
@@ -117,7 +117,6 @@ void init_UploadWidget(iUploadWidget *d) { | |||
117 | setFont_InputWidget(d->input, monospace_FontId); | 117 | setFont_InputWidget(d->input, monospace_FontId); |
118 | setLineLimits_InputWidget(d->input, 7, 20); | 118 | setLineLimits_InputWidget(d->input, 7, 20); |
119 | setHint_InputWidget(d->input, "${hint.upload.text}"); | 119 | setHint_InputWidget(d->input, "${hint.upload.text}"); |
120 | setEnterInsertsLF_InputWidget(d->input, iTrue); | ||
121 | setFixedSize_Widget(as_Widget(d->input), init_I2(120 * gap_UI, -1)); | 120 | setFixedSize_Widget(as_Widget(d->input), init_I2(120 * gap_UI, -1)); |
122 | addChild_Widget(page, iClob(d->input)); | 121 | addChild_Widget(page, iClob(d->input)); |
123 | appendFramelessTabPage_Widget(tabs, iClob(page), "${heading.upload.text}", '1', 0); | 122 | appendFramelessTabPage_Widget(tabs, iClob(page), "${heading.upload.text}", '1', 0); |