1
0
Fork 0

- [GUI] fixed crash when zooming or unzooming a gemtext window with inlined images.

This commit is contained in:
cage 2024-07-27 17:36:26 +02:00
parent 36e380f31e
commit 83e24a1fda
2 changed files with 31 additions and 6 deletions

View File

@ -489,9 +489,11 @@
(defun inline-possible-p (link-value) (defun inline-possible-p (link-value)
(inline-image-p link-value)) (inline-image-p link-value))
(defun inline-type (link-value) (a:define-constant +inline-ir-type+ :inline-image :test #'eq)
(defun link-contains-inline-type-p (link-value)
(when (inline-image-p link-value) (when (inline-image-p link-value)
:inline-image)) +inline-ir-type+))
(defun scale-pixmap (main-window file type) (defun scale-pixmap (main-window file type)
(let* ((pixmap (nodgui.pixmap:slurp-pixmap type file)) (let* ((pixmap (nodgui.pixmap:slurp-pixmap type file))
@ -536,7 +538,7 @@
(gui:move-cursor-to gemtext-widget coordinates) (gui:move-cursor-to gemtext-widget coordinates)
(gui:insert-text gemtext-widget (format nil "~%")) (gui:insert-text gemtext-widget (format nil "~%"))
(gui:insert-image gemtext-widget image coordinates) (gui:insert-image gemtext-widget image coordinates)
(setf (getf new-line :type) (inline-type link-value)) (setf (getf new-line :type) (link-contains-inline-type-p link-value))
(setf ir-lines (setf ir-lines
(fresh-vector-insert@ ir-lines (fresh-vector-insert@ ir-lines
new-line new-line
@ -564,6 +566,10 @@ local file paths."
(inline-single-image (ir-lines main-window) (+ line-number 1))))))) (inline-single-image (ir-lines main-window) (+ line-number 1)))))))
(inline-single-image (ir-lines main-window) 1))) (inline-single-image (ir-lines main-window) 1)))
(defun ir-lines-contains-inlined-images-p (main-window)
(find-if (lambda (a) (string= (getf a :type) +inline-ir-type+))
(ir-lines main-window)))
(defun inline-all-images-clsr (main-window) (defun inline-all-images-clsr (main-window)
(lambda () (lambda ()
(inline-all-images main-window))) (inline-all-images main-window)))
@ -1847,20 +1853,39 @@ local file paths."
(restart-rendering ,main-window) (restart-rendering ,main-window)
,@body))) ,@body)))
(defun uninline-all-images (main-window)
(with-accessors ((ir-rendered-lines ir-rendered-lines)
(ir-lines ir-lines)) main-window
(loop with i = 0 do
(if (< i
(length ir-lines))
(let ((ir-line (elt ir-lines i)))
(if (string= (getf ir-line :type) +inline-ir-type+)
(progn
(setf (ir-lines main-window) (misc:delete@ (ir-lines main-window) i))
(setf (ir-rendered-lines main-window)
(misc:delete@ (ir-rendered-lines main-window) i)))
(incf i)))
(return-from uninline-all-images t)))))
(defun scale-gemtext (main-window offset) (defun scale-gemtext (main-window offset)
(let ((saved-active-stream (find-streaming-stream-url))) (let ((saved-active-stream (find-streaming-stream-url)))
(interrupt-rendering main-window) (interrupt-rendering main-window)
(maybe-stop-streaming-stream-thread) (maybe-stop-streaming-stream-thread)
(when saved-active-stream (when saved-active-stream
(open-iri (streaming-url saved-active-stream) main-window t)) (open-iri (streaming-url saved-active-stream) main-window t))
(ev:with-enqueued-process-and-unblock (program-events:+minimum-event-priority+) (let ((contains-inlined-images (ir-lines-contains-inlined-images-p main-window)))
(when contains-inlined-images
(uninline-all-images main-window))
(restart-rendering main-window) (restart-rendering main-window)
(clear-gemtext main-window) (clear-gemtext main-window)
(setf (gemtext-font-scaling main-window) (setf (gemtext-font-scaling main-window)
(if offset (if offset
(max 0.1 (+ (gemtext-font-scaling main-window) offset)) (max 0.1 (+ (gemtext-font-scaling main-window) offset))
1.0)) 1.0))
(render-ir-lines (get-address-bar-text main-window) main-window)))) (render-ir-lines (get-address-bar-text main-window) main-window)
(when contains-inlined-images
(inline-all-images main-window)))))
(defun initialize-keybindings (main-window target) (defun initialize-keybindings (main-window target)
(gui:bind target (gui:bind target

View File

@ -2098,7 +2098,7 @@
(write-sequence text stream)) (write-sequence text stream))
(croatoan:end-screen) (croatoan:end-screen)
(tui:with-notify-errors (tui:with-notify-errors
(os-utils:open-with-editor temp-file)) (os-utils:open-with-editor temp-file))
(when (> (fs:file-size temp-file) (when (> (fs:file-size temp-file)
0) 0)
(let ((new-content (fs:slurp-file temp-file))) (let ((new-content (fs:slurp-file temp-file)))