lordpretzel / mu4e-views

GNU General Public License v3.0
107 stars 6 forks source link

require mu4e-views, which cause space key in article not work. #24

Closed zw963 closed 2 years ago

zw963 commented 2 years ago

When open a email from mu4e and focus on article buffer, the traditional process is to pressing 'SPACE' key repeatly.

space will scroll own mail in current article buffer, when reach current article end, i will open next article automatically.

but, after (require 'mu4e-view), broken this behavior.

zw963 commented 2 years ago

here is the document for this space feature, mu4e-views broken this.

lordpretzel commented 2 years ago

Hi,

note that we are using xwidgets. I can bind SPACE to "page down", but I'll have to check whether there is a function in xwidgets to determine that we have reached the end of the html doc. If such a function exists, then I can easily fix this behavior. Otherwise, I am not sure we can handle this (maybe with some javascript in xwidgets).

lordpretzel commented 2 years ago

ok, turns out this can be done with callbacks from javascript in xwidgets. I have a fix that I will push after some testing.

In the meanwhile you can use this snippet:

(defun mu4e-views--xwidget-callback-if-is-at-bottom (callback)
  (xwidget-webkit-execute-script
   (xwidget-webkit-current-session)
   "(function() {
        if((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
          return \"TRUE\"
        }
        else {
          return \"FALSE\"
        }
      })()"
     callback))

(defun mu4e-views-scroll-up-or-next ()
  "Wrapper around mu4e method for scrolling down and jumping to next mail if we reached the end of the current mail. For xwidgets we have to use javascript to detect when we reached the end."
  (interactive)
  (let ((is-xwidget (pcase (mu4e-views--get-current-viewing-method-name)
                      ("html" t)
                      ("html-block" t)
                      ("html-nonblock" t)
                      (_ nil))))
    ;; in xwidgets window using xwidgets scroll method and jump to next message if we reached end
    (if is-xwidget
      (mu4e-views--xwidget-callback-if-is-at-bottom
       (lambda (res) (progn (message "it is %s" res)
                            (if (string-equal res "TRUE")
                                (when mu4e-view-scroll-to-next
                                  (message "move to next!")
                                  (mu4e-view-headers-next))
                              (xwidget-webkit-scroll-up)))))
      (scroll-up))))

and bind this to SPC