Fix scrolling on non-Firefox browsers
Joseph Weston authored on 07/12/2021 05:17:32... | ... |
@@ -31,16 +31,15 @@ |
31 | 31 |
:else {:err (str "Unknown command '" cmdline "'")}))) |
32 | 32 |
|
33 | 33 |
(re-frame/reg-fx |
34 |
- :window/scroll-smoothly-to-bottom |
|
34 |
+ :window/scroll-to-prompt |
|
35 | 35 |
(fn [] |
36 |
- (let [x (.-scrollX js/window) |
|
37 |
- y (.-scrollMaxY js/window)] |
|
38 |
- (.scrollTo js/window (clj->js {:left x :top y :behavior :smooth}))))) |
|
36 |
+ (-> js/document |
|
37 |
+ (.getElementById "prompt") |
|
38 |
+ (.scrollIntoView (clj->js {:behavior :smooth}))))) |
|
39 | 39 |
|
40 | 40 |
(re-frame/reg-event-fx |
41 |
- ::scroll-to-bottom |
|
42 |
- (fn [] |
|
43 |
- {:window/scroll-smoothly-to-bottom []})) |
|
41 |
+ ::scroll-to-prompt |
|
42 |
+ (fn [] {:window/scroll-to-prompt []})) |
|
44 | 43 |
|
45 | 44 |
(re-frame/reg-event-fx |
46 | 45 |
::submit-cmd |
... | ... |
@@ -60,4 +59,4 @@ |
60 | 59 |
{:input cmdline :output output})))) |
61 | 60 |
; dispatch-later to ensure that the DOM has already been updated, |
62 | 61 |
; so that scrollMaxY has been changed appropriately. |
63 |
- :fx [[:dispatch-later {:ms 10 :dispatch [::scroll-to-bottom]}]]}))) |
|
62 |
+ :fx [[:dispatch-later {:ms 10 :dispatch [::scroll-to-prompt]}]]}))) |
... | ... |
@@ -13,7 +13,7 @@ |
13 | 13 |
[::events/update-cmdline (-> % .-target .-value)]) |
14 | 14 |
submit-cmd #(do (.preventDefault %) |
15 | 15 |
(re-frame/dispatch [::events/submit-cmd]))] |
16 |
- [:form {:class (styles/prompt-style) |
|
16 |
+ [:form {:id "prompt" :class (styles/prompt-style) |
|
17 | 17 |
:on-submit submit-cmd} |
18 | 18 |
[:input {:value @cmdline |
19 | 19 |
:on-change update-cmdline |