From 1abe34f7a061932f4bf433c3e99b804588272536 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 12 Jan 2021 12:18:57 +0200 Subject: Fixed: Percent-encode spaces when copying IssueID #112 --- src/gmutil.c | 6 ++++++ src/gmutil.h | 1 + src/ui/documentwidget.c | 6 +++--- src/ui/inputwidget.c | 6 ++++-- src/ui/sidebarwidget.c | 4 ++-- 5 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gmutil.c b/src/gmutil.c index ab9a8eea..69fa6d9f 100644 --- a/src/gmutil.c +++ b/src/gmutil.c @@ -327,6 +327,12 @@ void urlEncodeSpaces_String(iString *d) { } } +const iString *withSpacesEncoded_String(const iString *d) { + iString *enc = copy_String(d); + urlEncodeSpaces_String(enc); + return collect_String(enc); +} + const iString *feedEntryOpenCommand_String(const iString *url, int newTab) { if (!isEmpty_String(url)) { iString *cmd = collectNew_String(); diff --git a/src/gmutil.h b/src/gmutil.h index 947ff56b..7227a072 100644 --- a/src/gmutil.h +++ b/src/gmutil.h @@ -110,5 +110,6 @@ void urlEncodePath_String (iString *); iString * makeFileUrl_String (const iString *localFilePath); const char * makeFileUrl_CStr (const char *localFilePath); void urlEncodeSpaces_String (iString *); +const iString * withSpacesEncoded_String(const iString *); const iString * feedEntryOpenCommand_String (const iString *url, int newTab); /* checks fragment */ diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 8f2fc437..1ee83a85 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1653,11 +1653,11 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) } else if (equal_Command(cmd, "document.copylink") && document_App() == d) { if (d->contextLink) { - SDL_SetClipboardText(cstr_String( - absoluteUrl_String(d->mod.url, linkUrl_GmDocument(d->doc, d->contextLink->linkId)))); + SDL_SetClipboardText(cstr_String(withSpacesEncoded_String(absoluteUrl_String( + d->mod.url, linkUrl_GmDocument(d->doc, d->contextLink->linkId))))); } else { - SDL_SetClipboardText(cstr_String(d->mod.url)); + SDL_SetClipboardText(cstr_String(withSpacesEncoded_String(d->mod.url))); } return iTrue; } diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 85bd8b8b..6992bbec 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c @@ -514,8 +514,10 @@ static size_t coordIndex_InputWidget_(const iInputWidget *d, iInt2 coord) { static iBool copy_InputWidget_(iInputWidget *d, iBool doCut) { if (!isEmpty_Range(&d->mark)) { const iRanges m = mark_InputWidget_(d); - SDL_SetClipboardText(cstrCollect_String( - newUnicodeN_String(constAt_Array(&d->text, m.start), size_Range(&m)))); + iString *str = collect_String(newUnicodeN_String(constAt_Array(&d->text, m.start), + size_Range(&m))); + SDL_SetClipboardText( + cstr_String(d->inFlags & isUrl_InputWidgetFlag ? withSpacesEncoded_String(str) : str)); if (doCut) { pushUndo_InputWidget_(d); deleteMarked_InputWidget_(d); diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index cde95892..c31e157c 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -753,7 +753,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) else if (isCommand_Widget(w, ev, "bookmark.copy")) { const iSidebarItem *item = d->contextItem; if (d->mode == bookmarks_SidebarMode && item) { - SDL_SetClipboardText(cstr_String(&item->url)); + SDL_SetClipboardText(cstr_String(withSpacesEncoded_String(&item->url))); } return iTrue; } @@ -974,7 +974,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) else if (isCommand_Widget(w, ev, "history.copy")) { const iSidebarItem *item = d->contextItem; if (item && !isEmpty_String(&item->url)) { - SDL_SetClipboardText(cstr_String(&item->url)); + SDL_SetClipboardText(cstr_String(withSpacesEncoded_String(&item->url))); } return iTrue; } -- cgit v1.2.3