diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-17 21:35:11 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-17 21:35:11 +0200 |
commit | 59462f7c4f35c75b2951827a81a5cc0ca4d7dbec (patch) | |
tree | fc40d83dcc15f2861a4e3323dab9cb9cde8e60c8 /src/ui/inputwidget.c | |
parent | 292b81a0a635204fa588a73e352ac8e6ffa98f40 (diff) |
InputWidget: In a narrow window, omit the default URL scheme
The default URL scheme is "gemini". If missing, it will always be added back when making requests. This allows it to be omitted from the URL input field if space needs saving.
Other schemes, like "gopher", won't be omitted.
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r-- | src/ui/inputwidget.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 06e6373e..04d3ff69 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -258,9 +258,26 @@ static iString *visText_InputWidget_(const iInputWidget *d) { | |||
258 | static void updateBuffered_InputWidget_(iInputWidget *d) { | 258 | static void updateBuffered_InputWidget_(iInputWidget *d) { |
259 | if (isFinishedLaunching_App()) { | 259 | if (isFinishedLaunching_App()) { |
260 | invalidateBuffered_InputWidget_(d); | 260 | invalidateBuffered_InputWidget_(d); |
261 | iString *visText = visText_InputWidget_(d); | 261 | iString *bufText = NULL; |
262 | d->buffered = new_TextBuf(d->font, cstr_String(visText)); | 262 | if (d->inFlags & isUrl_InputWidgetFlag) { |
263 | delete_String(visText); | 263 | /* Highlight the host name. */ |
264 | iUrl parts; | ||
265 | const iString *text = text_InputWidget(d); | ||
266 | init_Url(&parts, text); | ||
267 | if (!isEmpty_Range(&parts.host)) { | ||
268 | bufText = new_String(); | ||
269 | appendRange_String(bufText, (iRangecc){ constBegin_String(text), parts.host.start }); | ||
270 | appendCStr_String(bufText, uiTextStrong_ColorEscape); | ||
271 | appendRange_String(bufText, parts.host); | ||
272 | appendCStr_String(bufText, restore_ColorEscape); | ||
273 | appendRange_String(bufText, (iRangecc){ parts.host.end, constEnd_String(text) }); | ||
274 | } | ||
275 | } | ||
276 | if (!bufText) { | ||
277 | bufText = visText_InputWidget_(d); | ||
278 | } | ||
279 | d->buffered = new_TextBuf(d->font, uiInputText_ColorId, cstr_String(bufText)); | ||
280 | delete_String(bufText); | ||
264 | } | 281 | } |
265 | } | 282 | } |
266 | 283 | ||
@@ -275,6 +292,12 @@ void setText_InputWidget(iInputWidget *d, const iString *text) { | |||
275 | punyEncodeUrlHost_String(enc); | 292 | punyEncodeUrlHost_String(enc); |
276 | text = enc; | 293 | text = enc; |
277 | } | 294 | } |
295 | /* Omit the default (Gemini) scheme if the window is narrow. */ | ||
296 | if (isNarrow_Window(get_Window()) && startsWithCase_String(text, "gemini:")) { | ||
297 | iString *shortened = collect_String(copy_String(text)); | ||
298 | remove_Block(&shortened->chars, 0, 7); | ||
299 | text = shortened; | ||
300 | } | ||
278 | } | 301 | } |
279 | clearUndo_InputWidget_(d); | 302 | clearUndo_InputWidget_(d); |
280 | clear_Array(&d->text); | 303 | clear_Array(&d->text); |
@@ -919,7 +942,7 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
919 | } | 942 | } |
920 | if (d->buffered && !isFocused && !isHint) { | 943 | if (d->buffered && !isFocused && !isHint) { |
921 | /* Most input widgets will use this, since only one is focused at a time. */ | 944 | /* Most input widgets will use this, since only one is focused at a time. */ |
922 | draw_TextBuf(d->buffered, textOrigin, uiInputText_ColorId); | 945 | draw_TextBuf(d->buffered, textOrigin, white_ColorId); |
923 | } | 946 | } |
924 | else { | 947 | else { |
925 | draw_Text(d->font, | 948 | draw_Text(d->font, |