Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: in the demo the 'evaluation at cursor' only worked for Mac users #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions demo/src/nextjournal/clojure_mode/demo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,27 @@
(.of view/keymap cm-clj/complete-keymap)
(.of view/keymap historyKeymap)])

(defn linux? []
(some? (re-find #"(Linux)|(X11)" js/navigator.userAgent)))

(defn mac? []
(and (not (linux?))
(some? (re-find #"(Mac)|(iPhone)|(iPad)|(iPod)" js/navigator.platform))))

(defn editor [source {:keys [eval?]}]
(r/with-let [!view (r/atom nil)
last-result (when eval? (r/atom (demo.sci/eval-string source)))
modifier (if (mac?)
"Meta"
"Ctrl")
mount! (fn [el]
(when el
(reset! !view (new EditorView
(j/obj :state
(test-utils/make-state
(cond-> #js [extensions]
eval? (.concat #js [(eval-region/extension {:modifier "Meta"})
(demo.sci/extension {:modifier "Meta"
eval? (.concat #js [(eval-region/extension {:modifier modifier})
(demo.sci/extension {:modifier modifier
:on-result (partial reset! last-result)})]))
source)
:parent el)))))]
Expand Down Expand Up @@ -121,13 +130,6 @@
n))"]]
[editor source {:eval? true}])))

(defn linux? []
(some? (re-find #"(Linux)|(X11)" js/navigator.userAgent)))

(defn mac? []
(and (not (linux?))
(some? (re-find #"(Mac)|(iPhone)|(iPad)|(iPod)" js/navigator.platform))))

(defn key-mapping []
(cond-> {"ArrowUp" "↑"
"ArrowDown" "↓"
Expand Down