about summary refs log tree commit diff stats
path: root/src/local
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-28 21:48:44 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-28 21:51:10 +0100
commit074e2089d909e4f7ef85df89698875ec2b8935c3 (patch)
treeea6d20ba741234a849542419359b3e52133197a0 /src/local
parent7eeef1700eee50a2e80910ba0b07138ea1d39d55 (diff)
downloadchawan-074e2089d909e4f7ef85df89698875ec2b8935c3.tar.gz
pager: improve URL loading procs
Split up load into loadSubmit, gotoURL: loadSubmit is a replacement for
load(s + '\n'), and gotoURL is a load that does no URL expansion.

Also, fix a bug where load("\n") would crash the browser.
Diffstat (limited to 'src/local')
-rw-r--r--src/local/pager.nim19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/local/pager.nim b/src/local/pager.nim
index a1ebaeb8..f74cf798 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -23,6 +23,7 @@ import extern/stdio
 import extern/tempfile
 import io/promise
 import io/socketstream
+import js/error
 import js/javascript
 import js/jstypes
 import js/regex
@@ -886,15 +887,23 @@ proc updateReadLine*(pager: Pager) =
     if pager.lineedit.get == lineedit:
       pager.clearLineEdit()
 
+# Same as load(s + '\n')
+proc loadSubmit(pager: Pager, s: string) {.jsfunc.} =
+  pager.loadURL(s)
+
 # Open a URL prompt and visit the specified URL.
 proc load(pager: Pager, s = "") {.jsfunc.} =
   if s.len > 0 and s[^1] == '\n':
-    pager.loadURL(s[0..^2])
+    if s.len > 1:
+      pager.loadURL(s[0..^2])
+  elif s == "":
+    pager.setLineEdit("URL: ", LOCATION, $pager.container.location)
   else:
-    var url = s
-    if url == "":
-      url = pager.container.location.serialize()
-    pager.setLineEdit("URL: ", LOCATION, url)
+    pager.setLineEdit("URL: ", LOCATION, s)
+
+# Go to specific URL (for JS)
+proc jsGotoURL(pager: Pager, s: string): JSResult[void] {.jsfunc: "gotoURL".} =
+  pager.gotoURL(newRequest(?newURL(s)))
 
 # Reload the page in a new buffer, then kill the previous buffer.
 proc reload(pager: Pager) {.jsfunc.} =