summaryrefslogtreecommitdiff
path: root/lisp/xwidget.el
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2021-12-30 15:04:18 +0800
committerPo Lu <luangruo@yahoo.com>2021-12-30 15:05:39 +0800
commit37ad776b9e6c90b2c289dd2413868066608594a7 (patch)
treeef9c53b9f1a9fe299e38bf29b3f69ecacb027ee2 /lisp/xwidget.el
parenta3129af331b8893cec3036f8baec26d49e339b5f (diff)
downloademacs-37ad776b9e6c90b2c289dd2413868066608594a7.tar.gz
Make xwidget motion commands hscroll the window of wide widgets
* lisp/xwidget.el (xwidget-info): New function declaration. (xwidget-webkit-scroll-forward): (xwidget-webkit-scroll-backward): Hscroll the window if the widget is wider than the text area. (bug#52885) * src/xwidget.c (xwidget_scroll, xwidget_motion_notify): Apply clip offsets to coordinates.
Diffstat (limited to 'lisp/xwidget.el')
-rw-r--r--lisp/xwidget.el38
1 files changed, 26 insertions, 12 deletions
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index ce9839ebd34..12ee5975040 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -60,6 +60,7 @@
(declare-function xwidget-webkit-set-cookie-storage-file "xwidget.c" (xwidget file))
(declare-function xwidget-live-p "xwidget.c" (xwidget))
(declare-function xwidget-webkit-stop-loading "xwidget.c" (xwidget))
+(declare-function xwidget-info "xwidget.c" (xwidget))
(defgroup xwidget nil
"Displaying native widgets in Emacs buffers."
@@ -347,23 +348,36 @@ If N is omitted or nil, scroll down by one line."
(defun xwidget-webkit-scroll-forward (&optional n)
"Scroll webkit horizontally by N chars.
-The width of char is calculated with `window-font-width'.
-If N is omitted or nil, scroll forwards by one char."
+If the widget is larger than the window, hscroll by N columns
+instead. The width of char is calculated with
+`window-font-width'. If N is omitted or nil, scroll forwards by
+one char."
(interactive "p" xwidget-webkit-mode)
- (xwidget-webkit-execute-script
- (xwidget-webkit-current-session)
- (format "window.scrollBy(%d, 0);"
- (* n (window-font-width)))))
+ (let ((session (xwidget-webkit-current-session)))
+ (if (> (- (aref (xwidget-info session) 2)
+ (window-text-width nil t))
+ (window-font-width))
+ (set-window-hscroll nil (+ (window-hscroll) n))
+ (xwidget-webkit-execute-script session
+ (format "window.scrollBy(%d, 0);"
+ (* n (window-font-width)))))))
(defun xwidget-webkit-scroll-backward (&optional n)
"Scroll webkit back by N chars.
-The width of char is calculated with `window-font-width'.
-If N is omitted or nil, scroll backwards by one char."
+If the widget is larger than the window, hscroll backwards by N
+columns instead. The width of char is calculated with
+`window-font-width'. If N is omitted or nil, scroll backwards by
+one char."
(interactive "p" xwidget-webkit-mode)
- (xwidget-webkit-execute-script
- (xwidget-webkit-current-session)
- (format "window.scrollBy(-%d, 0);"
- (* n (window-font-width)))))
+ (let ((session (xwidget-webkit-current-session)))
+ (if (and (> (- (aref (xwidget-info session) 2)
+ (window-text-width nil t))
+ (window-font-width))
+ (> (window-hscroll) 0))
+ (set-window-hscroll nil (- (window-hscroll) n))
+ (xwidget-webkit-execute-script session
+ (format "window.scrollBy(%-d, 0);"
+ (* n (window-font-width)))))))
(defun xwidget-webkit-scroll-top ()
"Scroll webkit to the very top."