summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defs.h33
-rw-r--r--src/prefs.c1
-rw-r--r--src/prefs.h1
-rw-r--r--src/ui/documentwidget.c12
-rw-r--r--src/ui/inputwidget.c11
-rw-r--r--src/ui/util.c21
6 files changed, 65 insertions, 14 deletions
diff --git a/src/defs.h b/src/defs.h
index 6f58e749..cf04514e 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -47,6 +47,39 @@ enum iScrollType {
47 max_ScrollType 47 max_ScrollType
48}; 48};
49 49
50enum iReturnKeyFlag {
51 return_ReturnKeyFlag = 0,
52 shiftReturn_ReturnKeyFlag = 1,
53 controlReturn_ReturnKeyFlag = 2,
54 guiReturn_ReturnKeyFlag = 3,
55 mask_ReturnKeyFlag = 0xf,
56 accept_ReturnKeyFlag = 4, /* shift */
57};
58
59/* Return key behavior is not handled via normal bindings because only certain combinations
60 are valid. */
61enum iReturnKeyBehavior {
62 default_ReturnKeyBehavior =
63 shiftReturn_ReturnKeyFlag | (return_ReturnKeyFlag << accept_ReturnKeyFlag),
64 acceptWithShift_ReturnKeyBehavior =
65 return_ReturnKeyFlag | (shiftReturn_ReturnKeyFlag << accept_ReturnKeyFlag),
66 acceptWithPrimaryMod_ReturnKeyBehavior =
67#if defined (iPlatformApple)
68 return_ReturnKeyFlag | (guiReturn_ReturnKeyFlag << accept_ReturnKeyFlag),
69#else
70 return_ReturnKeyFlag | (controlReturn_ReturnKeyFlag << accept_ReturnKeyFlag),
71#endif
72};
73
74int keyMod_ReturnKeyFlag (int flag);
75
76iLocalDef int lineBreakKeyMod_ReturnKeyBehavior(int behavior) {
77 return keyMod_ReturnKeyFlag(behavior & mask_ReturnKeyFlag);
78}
79iLocalDef int acceptKeyMod_ReturnKeyBehavior(int behavior) {
80 return keyMod_ReturnKeyFlag((behavior >> accept_ReturnKeyFlag) & mask_ReturnKeyFlag);
81}
82
50/* Icons */ 83/* Icons */
51 84
52#define menu_Icon "\U0001d362" 85#define menu_Icon "\U0001d362"
diff --git a/src/prefs.c b/src/prefs.c
index f06aab19..13a95a3d 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -39,6 +39,7 @@ void init_Prefs(iPrefs *d) {
39 d->sideIcon = iTrue; 39 d->sideIcon = iTrue;
40 d->hideToolbarOnScroll = iTrue; 40 d->hideToolbarOnScroll = iTrue;
41 d->pinSplit = 1; 41 d->pinSplit = 1;
42 d->returnKey = default_ReturnKeyBehavior;
42 d->hoverLink = iFalse; 43 d->hoverLink = iFalse;
43 d->smoothScrolling = iTrue; 44 d->smoothScrolling = iTrue;
44 d->smoothScrollSpeed[keyboard_ScrollType] = 10; 45 d->smoothScrollSpeed[keyboard_ScrollType] = 10;
diff --git a/src/prefs.h b/src/prefs.h
index 7de6df5d..58c73bf7 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -54,6 +54,7 @@ struct Impl_Prefs {
54 iBool hideToolbarOnScroll; 54 iBool hideToolbarOnScroll;
55 int pinSplit; /* 0: no pinning, 1: left doc, 2: right doc */ 55 int pinSplit; /* 0: no pinning, 1: left doc, 2: right doc */
56 /* Behavior */ 56 /* Behavior */
57 int returnKey;
57 iString downloadDir; 58 iString downloadDir;
58 iBool hoverLink; 59 iBool hoverLink;
59 iBool smoothScrolling; 60 iBool smoothScrolling;
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 1504426f..b041f5b4 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -1887,10 +1887,14 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
1887 /* The line break and URL length counters are positioned differently on mobile. 1887 /* The line break and URL length counters are positioned differently on mobile.
1888 There is no line breaks in sensitive input. */ 1888 There is no line breaks in sensitive input. */
1889 if (deviceType_App() == desktop_AppDeviceType) { 1889 if (deviceType_App() == desktop_AppDeviceType) {
1890 lineBreak = new_LabelWidget("${dlg.input.linebreak}" 1890 iString *keyStr = collectNew_String();
1891 uiTextAction_ColorEscape 1891 toString_Sym(SDLK_RETURN,
1892 " " shiftReturn_Icon, 1892 lineBreakKeyMod_ReturnKeyBehavior(prefs_App()->returnKey),
1893 NULL); 1893 keyStr);
1894 lineBreak = new_LabelWidget(
1895 format_CStr("${dlg.input.linebreak}" uiTextAction_ColorEscape " %s",
1896 cstr_String(keyStr)),
1897 NULL);
1894 insertChildAfter_Widget(buttons, iClob(lineBreak), 0); 1898 insertChildAfter_Widget(buttons, iClob(lineBreak), 0);
1895 } 1899 }
1896 else { 1900 else {
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index 3a979b20..2c1c3165 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -1693,8 +1693,9 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
1693 case SDLK_RETURN: 1693 case SDLK_RETURN:
1694 case SDLK_KP_ENTER: 1694 case SDLK_KP_ENTER:
1695 if (~d->inFlags & isSensitive_InputWidgetFlag && d->maxLen == 0) { 1695 if (~d->inFlags & isSensitive_InputWidgetFlag && d->maxLen == 0) {
1696 if (mods == KMOD_SHIFT || (~d->inFlags & isUrl_InputWidgetFlag && 1696 if (mods == lineBreakKeyMod_ReturnKeyBehavior(prefs_App()->returnKey) ||
1697 d->inFlags & enterKeyInsertsLineFeed_InputWidgetFlag)) { 1697 (~d->inFlags & isUrl_InputWidgetFlag &&
1698 d->inFlags & enterKeyInsertsLineFeed_InputWidgetFlag)) {
1698 pushUndo_InputWidget_(d); 1699 pushUndo_InputWidget_(d);
1699 deleteMarked_InputWidget_(d); 1700 deleteMarked_InputWidget_(d);
1700 insertChar_InputWidget_(d, '\n'); 1701 insertChar_InputWidget_(d, '\n');
@@ -1702,11 +1703,13 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
1702 return iTrue; 1703 return iTrue;
1703 } 1704 }
1704 } 1705 }
1705 if (d->inFlags & enterKeyEnabled_InputWidgetFlag) { 1706 if (d->inFlags & enterKeyEnabled_InputWidgetFlag &&
1707 mods == acceptKeyMod_ReturnKeyBehavior(prefs_App()->returnKey)) {
1706 d->inFlags |= enterPressed_InputWidgetFlag; 1708 d->inFlags |= enterPressed_InputWidgetFlag;
1707 setFocus_Widget(NULL); 1709 setFocus_Widget(NULL);
1710 return iTrue;
1708 } 1711 }
1709 return iTrue; 1712 return iFalse;
1710 case SDLK_ESCAPE: 1713 case SDLK_ESCAPE:
1711 end_InputWidget(d, iFalse); 1714 end_InputWidget(d, iFalse);
1712 setFocus_Widget(NULL); 1715 setFocus_Widget(NULL);
diff --git a/src/ui/util.c b/src/ui/util.c
index da7a69b4..63600557 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -169,6 +169,13 @@ int keyMods_Sym(int kmods) {
169 return kmods; 169 return kmods;
170} 170}
171 171
172int keyMod_ReturnKeyFlag(int flag) {
173 flag &= mask_ReturnKeyFlag;
174 const int kmods[4] = { 0, KMOD_SHIFT, KMOD_CTRL, KMOD_GUI };
175 if (flag < 0 || flag >= iElemCount(kmods)) return 0;
176 return kmods[flag];
177}
178
172int openTabMode_Sym(int kmods) { 179int openTabMode_Sym(int kmods) {
173 const int km = keyMods_Sym(kmods); 180 const int km = keyMods_Sym(kmods);
174 return (km == KMOD_SHIFT ? otherRoot_OpenTabFlag : 0) | /* open to the side */ 181 return (km == KMOD_SHIFT ? otherRoot_OpenTabFlag : 0) | /* open to the side */
@@ -1307,12 +1314,14 @@ iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, con
1307 setId_Widget(as_Widget(input), "input"); 1314 setId_Widget(as_Widget(input), "input");
1308 updateValueInputWidth_(dlg); 1315 updateValueInputWidth_(dlg);
1309 addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI))); 1316 addChild_Widget(dlg, iClob(makePadding_Widget(gap_UI)));
1310 addChild_Widget( 1317 addChild_Widget(dlg,
1311 dlg, 1318 iClob(makeDialogButtons_Widget(
1312 iClob(makeDialogButtons_Widget( 1319 (iMenuItem[]){ { "${cancel}", SDLK_ESCAPE, 0, "valueinput.cancel" },
1313 (iMenuItem[]){ { "${cancel}", SDLK_ESCAPE, 0, "valueinput.cancel" }, 1320 { acceptLabel,
1314 { acceptLabel, 0, 0, "valueinput.accept" } }, 1321 SDLK_RETURN,
1315 2))); 1322 acceptKeyMod_ReturnKeyBehavior(prefs_App()->returnKey),
1323 "valueinput.accept" } },
1324 2)));
1316 finalizeSheet_Mobile(dlg); 1325 finalizeSheet_Mobile(dlg);
1317 if (parent) { 1326 if (parent) {
1318 setFocus_Widget(as_Widget(input)); 1327 setFocus_Widget(as_Widget(input));