about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-27 17:34:02 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-27 17:34:53 +0200
commit3f5135204c0902e2123194e0319fda7afd57bd81 (patch)
treefc9958a2c405e94419580c837c20564b08d69dd8
parent4b4b95b6e1c366fbd4e73f5bd0c0ea555bf77490 (diff)
downloadchawan-3f5135204c0902e2123194e0319fda7afd57bd81.tar.gz
buffer: add toggleImages
-rw-r--r--res/config.toml2
-rw-r--r--src/local/container.nim9
-rw-r--r--src/server/buffer.nim5
3 files changed, 15 insertions, 1 deletions
diff --git a/res/config.toml b/res/config.toml
index 6f0d6d31..fe1d6963 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -123,6 +123,7 @@ scrollLeft = 'n => pager.scrollLeft(n)'
 scrollRight = 'n => pager.scrollRight(n)'
 click = '() => pager.click()'
 viewImage = '() => pager.gotoURL(pager.hoverImage)'
+toggleImages = '() => pager.toggleImages()'
 markURL = '() => pager.markURL()'
 redraw = '() => pager.redraw()'
 reshape = '() => pager.reshape()'
@@ -346,6 +347,7 @@ m = 'cmd.buffer.mark'
 C-m = 'cmd.buffer.click'
 C-j = 'cmd.buffer.click'
 I = 'cmd.buffer.viewImage'
+M-i = 'cmd.buffer.toggleImages'
 ':' = 'cmd.buffer.markURL'
 r = 'cmd.buffer.redraw'
 R = 'cmd.buffer.reshape'
diff --git a/src/local/container.nim b/src/local/container.nim
index 3a0f1daf..01fd6e5d 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -1367,6 +1367,8 @@ proc getSelectionText(container: Container; hl: Highlight = nil):
   )
 
 proc markURL(container: Container) {.jsfunc.} =
+  if container.iface == nil:
+    return
   var schemes: seq[string] = @[]
   for key in container.mainConfig.external.urimethodmap.map.keys:
     schemes.add(key.until(':'))
@@ -1374,6 +1376,13 @@ proc markURL(container: Container) {.jsfunc.} =
     container.needslines = true
   )
 
+proc toggleImages(container: Container) {.jsfunc.} =
+  if container.iface == nil:
+    return
+  container.iface.toggleImages().then(proc() =
+    container.needslines = true
+  )
+
 proc setLoadInfo(container: Container; msg: string) =
   container.loadinfo = msg
   container.triggerEvent(cetSetLoadInfo)
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 56ad946f..1bdf1c30 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -67,7 +67,7 @@ type
     bcReadCanceled, bcClick, bcFindNextLink, bcFindPrevLink, bcFindNthLink,
     bcFindRevNthLink, bcFindNextMatch, bcFindPrevMatch, bcGetLines,
     bcUpdateHover, bcGotoAnchor, bcCancel, bcGetTitle, bcSelect, bcClone,
-    bcFindPrevParagraph, bcFindNextParagraph, bcMarkURL
+    bcFindPrevParagraph, bcFindNextParagraph, bcMarkURL, bcToggleImages
 
   BufferState = enum
     bsLoadingPage, bsLoadingResources, bsLoaded
@@ -1816,6 +1816,9 @@ proc markURL*(buffer: Buffer; schemes: seq[string]) {.proxy.} =
           stack.add(element)
   buffer.do_reshape()
 
+proc toggleImages*(buffer: Buffer) {.proxy.} =
+  buffer.config.images = not buffer.config.images
+
 macro bufferDispatcher(funs: static ProxyMap; buffer: Buffer;
     cmd: BufferCommand; packetid: int; r: var BufferedReader) =
   let switch = newNimNode(nnkCaseStmt)