about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-09-10 17:42:10 +0200
committerbptato <nincsnevem662@gmail.com>2024-09-10 17:45:38 +0200
commite03ba666ece8ae810f697f0cbd6e7f0391e4f241 (patch)
tree3575f4a480afdaed6c7d8a9b0105946fd822fdcc
parent55e98ed332ac9b10fdd22d24f39413fc4e916ac4 (diff)
downloadchawan-e03ba666ece8ae810f697f0cbd6e7f0391e4f241.tar.gz
pager: fix saveSource
Welp. The fence was needed after all.

The keybinding was broken anyway; fix that too.
-rw-r--r--res/config.toml2
-rw-r--r--src/local/container.nim4
-rw-r--r--src/local/pager.nim10
3 files changed, 10 insertions, 6 deletions
diff --git a/res/config.toml b/res/config.toml
index b74b54f8..f4e76ca3 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -361,6 +361,7 @@ K = 'cmd.buffer.scrollUp'
 sE = 'cmd.buffer.sourceEdit'
 sC-m = 'cmd.buffer.saveLink'
 sC-j = 'cmd.buffer.saveLink'
+sS = 'cmd.buffer.saveSource'
 m = 'cmd.buffer.mark'
 '`' = 'cmd.buffer.gotoMark'
 "'" = 'cmd.buffer.gotoMarkY'
@@ -395,7 +396,6 @@ C-v = 'cmd.buffer.cursorToggleSelectionBlock'
 # pager commands
 q = 'cmd.pager.quit'
 C-z = 'cmd.pager.suspend'
-sS = 'cmd.pager.saveSource'
 M-u = 'cmd.pager.dupeBuffer'
 C-l = 'cmd.pager.load'
 C-k = 'cmd.pager.webSearch'
diff --git a/src/local/container.nim b/src/local/container.nim
index 7e1326a6..4a31d054 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -61,6 +61,7 @@ type
     of cetOpen:
       request*: Request
       save*: bool
+      url*: URL
     of cetAnchor, cetNoAnchor:
       anchor*: string
     of cetAlert:
@@ -1892,7 +1893,8 @@ proc saveSource*(container: Container) {.jsfunc.} =
   container.triggerEvent(ContainerEvent(
     t: cetOpen,
     request: newRequest(newURL("cache:" & $container.cacheId).get),
-    save: true
+    save: true,
+    url: container.url
   ))
 
 proc windowChange*(container: Container; attrs: WindowAttributes) =
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 87c2e9d2..4640cf6a 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -1218,14 +1218,14 @@ proc applySiteconf(pager: Pager; url: var URL; charsetOverride: Charset;
 proc gotoURL(pager: Pager; request: Request; prevurl = none(URL);
     contentType = none(string); cs = CHARSET_UNKNOWN; replace: Container = nil;
     replaceBackup: Container = nil; redirectDepth = 0;
-    referrer: Container = nil; save = false): Container =
+    referrer: Container = nil; save = false; url: URL = nil): Container =
   pager.navDirection = ndNext
   if referrer != nil and referrer.config.refererFrom:
     request.referrer = referrer.url
   var loaderConfig: LoaderClientConfig
   var bufferConfig = pager.applySiteconf(request.url, cs, loaderConfig)
   if prevurl.isNone or not prevurl.get.equals(request.url, true) or
-      request.url.hash == "" or request.httpMethod != hmGet:
+      request.url.hash == "" or request.httpMethod != hmGet or save:
     # Basically, we want to reload the page *only* when
     # a) we force a reload (by setting prevurl to none)
     # b) or the new URL isn't just the old URL + an anchor
@@ -1244,7 +1244,9 @@ proc gotoURL(pager: Pager; request: Request; prevurl = none(URL);
       redirectDepth = redirectDepth,
       contentType = contentType,
       flags = flags,
-      url = request.url
+      # override the URL so that the file name is correct for saveSource
+      # (but NOT up above, so that rewrite-url works too)
+      url = if url != nil: url else: request.url
     )
     if replace != nil:
       pager.replace(replace, container)
@@ -2085,7 +2087,7 @@ proc handleEvent0(pager: Pager; container: Container; event: ContainerEvent):
       )
     else:
       discard pager.gotoURL(event.request, some(container.url),
-        referrer = pager.container, save = event.save)
+        referrer = pager.container, save = event.save, url = event.url)
   of cetStatus:
     if pager.container == container:
       pager.showAlerts()