summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-19 08:43:08 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-19 08:43:08 +0200
commit38f6e9ee0207593e861e0045d75dca96f05e89ea (patch)
treecb4c4e61aa78bda98de4789f2c5fab93b15865cc /src/ui
parentabab828dbbc3332d9625408ff4c0471f39da4b91 (diff)
InputWidget: Improved default scheme hiding
Restore when there is more space available.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/inputwidget.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index 04d3ff69..699ed184 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -200,9 +200,33 @@ void setMode_InputWidget(iInputWidget *d, enum iInputMode mode) {
200 d->mode = mode; 200 d->mode = mode;
201} 201}
202 202
203static void restoreDefaultScheme_(iString *url) {
204 iUrl parts;
205 init_Url(&parts, url);
206 if (isEmpty_Range(&parts.scheme) && startsWith_String(url, "//")) {
207 prependCStr_String(url, "gemini:");
208 }
209}
210
211static const iString *omitDefaultScheme_(iString *url) {
212 if (startsWithCase_String(url, "gemini://")) {
213 remove_Block(&url->chars, 0, 7);
214 }
215 return url;
216}
217
218static iString *utf32toUtf8_InputWidget_(const iInputWidget *d) {
219 return newUnicodeN_String(constData_Array(&d->text), size_Array(&d->text));
220}
221
203const iString *text_InputWidget(const iInputWidget *d) { 222const iString *text_InputWidget(const iInputWidget *d) {
204 if (d) { 223 if (d) {
205 return collect_String(newUnicodeN_String(constData_Array(&d->text), size_Array(&d->text))); 224 iString *text = collect_String(utf32toUtf8_InputWidget_(d));
225 if (d->inFlags & isUrl_InputWidgetFlag) {
226 /* Add the "gemini" scheme back if one is omitted. */
227 restoreDefaultScheme_(text);
228 }
229 return text;
206 } 230 }
207 return collectNew_String(); 231 return collectNew_String();
208} 232}
@@ -262,7 +286,7 @@ static void updateBuffered_InputWidget_(iInputWidget *d) {
262 if (d->inFlags & isUrl_InputWidgetFlag) { 286 if (d->inFlags & isUrl_InputWidgetFlag) {
263 /* Highlight the host name. */ 287 /* Highlight the host name. */
264 iUrl parts; 288 iUrl parts;
265 const iString *text = text_InputWidget(d); 289 const iString *text = collect_String(utf32toUtf8_InputWidget_(d));
266 init_Url(&parts, text); 290 init_Url(&parts, text);
267 if (!isEmpty_Range(&parts.host)) { 291 if (!isEmpty_Range(&parts.host)) {
268 bufText = new_String(); 292 bufText = new_String();
@@ -292,11 +316,9 @@ void setText_InputWidget(iInputWidget *d, const iString *text) {
292 punyEncodeUrlHost_String(enc); 316 punyEncodeUrlHost_String(enc);
293 text = enc; 317 text = enc;
294 } 318 }
295 /* Omit the default (Gemini) scheme if the window is narrow. */ 319 /* Omit the default (Gemini) scheme if there isn't much space. */
296 if (isNarrow_Window(get_Window()) && startsWithCase_String(text, "gemini:")) { 320 if (isNarrow_Window(get_Window())) { // flags_Widget(as_Widget(d)) & tight_WidgetFlag) {
297 iString *shortened = collect_String(copy_String(text)); 321 text = omitDefaultScheme_(collect_String(copy_String(text)));
298 remove_Block(&shortened->chars, 0, 7);
299 text = shortened;
300 } 322 }
301 } 323 }
302 clearUndo_InputWidget_(d); 324 clearUndo_InputWidget_(d);
@@ -674,6 +696,12 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
674 else if (isMetricsChange_UserEvent(ev)) { 696 else if (isMetricsChange_UserEvent(ev)) {
675 updateMetrics_InputWidget_(d); 697 updateMetrics_InputWidget_(d);
676 } 698 }
699 else if (isResize_UserEvent(ev)) {
700 if (d->inFlags & isUrl_InputWidgetFlag) {
701 /* Restore/omit the default scheme if necessary. */
702 setText_InputWidget(d, text_InputWidget(d));
703 }
704 }
677 else if (isFocused_Widget(d) && isCommand_UserEvent(ev, "copy")) { 705 else if (isFocused_Widget(d) && isCommand_UserEvent(ev, "copy")) {
678 copy_InputWidget_(d, iFalse); 706 copy_InputWidget_(d, iFalse);
679 return iTrue; 707 return iTrue;