From f2c1405ceb7b8c2f13b6f74d2e11c66f29106023 Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= jaakko.keranen@iki.fi

Date: Fri, 26 May 2023 18:25:00 +0300

Subject: [PATCH 1/1] InputWidget: Revised how the "gemini:" prefix is treated

in narrow fields

The previous implementation was too error-prone.

BubbleID #19


res/about/version.gmi | 3 +++

src/ui/inputwidget.c | 50 +++++++++++++++++++++++--------------------

src/ui/inputwidget.h | 1 +

src/ui/root.c | 1 +

4 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/res/about/version.gmi b/res/about/version.gmi

index b4434bd2..37323870 100644

--- a/res/about/version.gmi

+++ b/res/about/version.gmi

@@ -6,6 +6,9 @@

Release notes

+## 1.16.2

+* Fixed issues with input fields related to handling URLs. Now only the navbar URL field omits the "gemini:" part when the field is narrow, and only when the field is inactive.

1.16.1

diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c

index 108dfec7..897bbc08 100644

--- a/src/ui/inputwidget.c

+++ b/src/ui/inputwidget.c

@@ -223,6 +223,7 @@ enum iInputWidgetFlag {

 dragCursor_InputWidgetFlag           = iBit(14),

 dragMarkerStart_InputWidgetFlag      = iBit(15),

 dragMarkerEnd_InputWidgetFlag        = iBit(16),

};

/----------------------------------------------------------------------------------------------/

@@ -998,26 +999,15 @@ void setMode_InputWidget(iInputWidget *d, enum iInputMode mode) {

 d->mode = mode;

}

-static void restoreDefaultScheme_(iString *url) {

+/*static void restoreDefaultScheme_(iString *url) {

     prependCStr_String(url, "gemini:");

 }

-}

+}*/

static const iString *omitDefaultScheme_(iString *url) {

 if (startsWithCase_String(url, "gemini://")) {

 }

 return url;

}

@@ -1026,7 +1016,9 @@ const iString *text_InputWidget(const iInputWidget *d) {

 iString *text = collect_String(d ? text_InputWidget_(d) : new_String());

 if (d && d->inFlags & isUrl_InputWidgetFlag) {

     /* Add the "gemini" scheme back if one is omitted. */

 }

 return text;

}

@@ -1079,6 +1071,10 @@ void setEnterKeyEnabled_InputWidget(iInputWidget *d, iBool enterKeyEnabled) {

 iChangeFlags(d->inFlags, enterKeyEnabled_InputWidgetFlag, enterKeyEnabled);

}

+void setOmitDefaultSchemeIfNarrow_InputWidget(iInputWidget *d, iBool omitDefaultSchemeIfNarrow) {

+}

void setUseReturnKeyBehavior_InputWidget(iInputWidget *d, iBool useReturnKeyBehavior) {

 iChangeFlags(d->inFlags, useReturnKeyBehavior_InputWidgetFlag, useReturnKeyBehavior);

}

@@ -1113,6 +1109,10 @@ static iBool isHintVisible_InputWidget_(const iInputWidget *d) {

 return !isEmpty_String(&d->hint) && isEmpty_InputWidget_(d);

}

+static iBool isNarrow_InputWidget_(const iInputWidget *d) {

+}

static void updateBuffered_InputWidget_(iInputWidget *d) {

 invalidateBuffered_InputWidget_(d);

 if (isHintVisible_InputWidget_(d)) {

@@ -1130,6 +1130,9 @@ static void updateBuffered_InputWidget_(iInputWidget *d) {

     }

#endif

     if (d->inFlags & isUrl_InputWidgetFlag) {

         /* Highlight the host name. */

         iUrl parts;

         init_Url(&parts, visText);

@@ -1159,10 +1162,6 @@ void setText_InputWidget(iInputWidget *d, const iString *text) {

 setTextUndoable_InputWidget(d, text, iFalse);

}

-static iBool isNarrow_InputWidget_(const iInputWidget *d) {

-}

void setTextUndoable_InputWidget(iInputWidget *d, const iString *text, iBool isUndoable) {

 if (!d) return;

#if !LAGRANGE_USE_SYSTEM_TEXT_INPUT

@@ -1186,9 +1185,9 @@ void setTextUndoable_InputWidget(iInputWidget *d, const iString *text, iBool isU

         text = enc;

     }

     /* Omit the default (Gemini) scheme if there isn't much space. */

         text = omitDefaultScheme_(collect_String(copy_String(text)));

 }

 iString *nfcText = collect_String(copy_String(text));

 normalize_String(nfcText);

@@ -1307,9 +1306,11 @@ void begin_InputWidget(iInputWidget *d) {

         (isAllowedToInsertNewline_InputWidget_(d) ? insertNewlines_SystemTextInputFlag : 0) |

         (d->inFlags & selectAllOnFocus_InputWidgetFlag ? selectAll_SystemTextInputFlags : 0));

 setFont_SystemTextInput(d->sysCtrl, d->font);

 if (d->inFlags & isUrl_InputWidgetFlag) {

     restoreDefaultScheme_(&d->oldText);

 }

 setText_SystemTextInput(d->sysCtrl, &d->oldText, iFalse);

 setTextChangedFunc_SystemTextInput(d->sysCtrl, systemInputChanged_InputWidget_, d);

 iConnect(Root, w->root, visualOffsetsChanged, d, updateAfterVisualOffsetChange_InputWidget_);

@@ -1354,9 +1355,10 @@ void end_InputWidget(iInputWidget *d, iBool accept) {

     iDisconnect(Root, w->root, visualOffsetsChanged, d, updateAfterVisualOffsetChange_InputWidget_);

     if (accept) {

         set_String(&d->text, text_SystemTextInput(d->sysCtrl));

         if (d->inFlags & isUrl_InputWidgetFlag && isNarrow_InputWidget_(d)) {

             omitDefaultScheme_(&d->text);

     }

     else {

         set_String(&d->text, &d->oldText);

@@ -1689,9 +1691,11 @@ static iBool copy_InputWidget_(iInputWidget *d, iBool doCut) {

     const iRanges m   = mark_InputWidget_(d);

     iString *     str = collectNew_String();

     mergeLinesRange_(&d->lines, m, str);

     if (d->inFlags & isUrl_InputWidgetFlag) {

         restoreDefaultScheme_(str);

     }

     SDL_SetClipboardText(

         cstr_String(d->inFlags & isUrl_InputWidgetFlag ? canonicalUrl_String(str) : str));

     if (doCut) {

diff --git a/src/ui/inputwidget.h b/src/ui/inputwidget.h

index 6840907d..817552ad 100644

--- a/src/ui/inputwidget.h

+++ b/src/ui/inputwidget.h

@@ -54,6 +54,7 @@ void setLineLimits_InputWidget (iInputWidget *, int minLines, int maxLi

void setValidator_InputWidget (iInputWidget *, iInputWidgetValidatorFunc validator, void *context);

void setLineBreaksEnabled_InputWidget(iInputWidget *, iBool lineBreaksEnabled);

void setEnterKeyEnabled_InputWidget (iInputWidget *, iBool enterKeyEnabled);

+void setOmitDefaultSchemeIfNarrow_InputWidget(iInputWidget *, iBool omitDefaultSchemeIfNarrow);

void setUseReturnKeyBehavior_InputWidget(iInputWidget *, iBool useReturnKeyBehavior);

void setBackupFileName_InputWidget (iInputWidget *, const char *fileName);

void begin_InputWidget (iInputWidget *);

diff --git a/src/ui/root.c b/src/ui/root.c

index a375f974..cef997f1 100644

--- a/src/ui/root.c

+++ b/src/ui/root.c

@@ -1569,6 +1569,7 @@ void createUserInterface_Root(iRoot *d) {

         setLineBreaksEnabled_InputWidget(url, iFalse);

         setUrlContent_InputWidget(url, iTrue);

         setNotifyEdits_InputWidget(url, iTrue);

         setTextCStr_InputWidget(url, "gemini://");

         addChildFlags_Widget(navBar, iClob(url), 0);

         const int64_t embedFlags =

--

2.25.1

Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.10/patch/f2c1405ceb7b8c2f13b6f74d2e11c66f29106023.patch
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
63.34605 milliseconds
Gemini-to-HTML Time
4.145532 milliseconds

This content has been proxied by September (ba2dc).