File tree Expand file tree Collapse file tree 11 files changed +308
-339
lines changed Expand file tree Collapse file tree 11 files changed +308
-339
lines changed Original file line number Diff line number Diff line change 27
27
[renderer.history.subs]
28
28
[renderer.notification.events]
29
29
[renderer.notification.subs]
30
- [renderer.reepl.core]
31
30
[renderer.reepl.replumb :as replumb]
32
31
[renderer.ruler.subs]
33
32
[renderer.snap.events]
Original file line number Diff line number Diff line change 9
9
[" codemirror/mode/clojure/clojure.js" ]
10
10
[" codemirror/mode/javascript/javascript.js" ]
11
11
[" react" :as react]
12
+ [cljs.tools.reader :as reader]
12
13
[clojure.string :as str]
13
14
[reagent.core :as r]))
14
15
30
31
:end #js {:line lno
31
32
:ch (+ cno (count forward))}}))
32
33
34
+ (defn is-valid-cljs?
35
+ [source]
36
+ (try
37
+ (fn []
38
+ (reader/read-string source)
39
+ true )
40
+ (catch js/Error _
41
+ false )))
42
+
43
+ (def default-opts
44
+ {:style {:height " auto"
45
+ :flex 1 }
46
+
47
+ :should-go-up
48
+ (fn [_source inst]
49
+ (let [pos (.getCursor inst)]
50
+ (= 0 (.-line pos))))
51
+
52
+ :should-go-down
53
+ (fn [_source inst]
54
+ (let [pos (.getCursor inst)
55
+ last-line (.lastLine inst)]
56
+ (= last-line (.-line pos))))
57
+
58
+ ; ; TODO: if the cursor is inside a list, and the function doesn't have enought
59
+ ; ; arguments yet, then return false
60
+ ; ; e.g. (map |) <- map needs at least one argument.
61
+ :should-eval
62
+ (fn [source inst evt]
63
+ (if (.-shiftKey evt)
64
+ false
65
+ (if (.-metaKey evt)
66
+ true
67
+ (let [lines (.lineCount inst)
68
+ in-place (or (= 1 lines)
69
+ (let [pos (.getCursor inst)
70
+ last-line (dec lines)]
71
+ (and
72
+ (= last-line (.-line pos))
73
+ (= (.-ch pos)
74
+ (count (.getLine inst last-line))))))]
75
+ (and in-place
76
+ (is-valid-cljs? source))))))})
77
+
33
78
(defn cm-current-word
34
79
" Find the current 'word' according to CodeMirror's `wordChars' list"
35
80
[cm]
148
193
149
194
:on-cm-init (fn [cm] -> nil)
150
195
called with the CodeMirror instance, for whatever extra fiddling you want to do."
151
- [value-atom {:keys [style
152
- on-change
153
- on-eval
154
- on-up
155
- on-down
156
- complete-atom
157
- complete-word
158
- should-go-up
159
- should-go-down
160
- should-eval
161
- js-cm-opts
162
- on-cm-init]}]
163
-
196
+ [value-atom options]
164
197
(let [cm (atom nil )
165
- ref (react/createRef )]
198
+ ref (react/createRef )
199
+ options (merge default-opts options)
200
+ {:keys [style
201
+ on-change
202
+ on-eval
203
+ on-up
204
+ on-down
205
+ complete-atom
206
+ complete-word
207
+ should-go-up
208
+ should-go-down
209
+ should-eval
210
+ js-cm-opts
211
+ on-cm-init]} options]
166
212
(r/create-class
167
213
{:component-did-mount
168
214
(fn [_this]
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ (ns renderer.reepl.db )
2
+
3
+ (def initial-state
4
+ {:items []
5
+ :hist-pos 0
6
+ :history [" " ]})
Original file line number Diff line number Diff line change 62
62
0
63
63
(dec pos))]
64
64
(assoc db :hist-pos new-pos)))
65
+
66
+ ; ; TODO: is there a macro or something that could do this cleaner?
67
+ (defn make-handlers
68
+ [state]
69
+ {:add-input (partial swap! state add-input)
70
+ :add-result (partial swap! state add-result)
71
+ :go-up (partial swap! state go-up)
72
+ :go-down (partial swap! state go-down)
73
+ :clear-items (partial swap! state clear-items)
74
+ :set-text (partial swap! state set-text)
75
+ :add-log (partial swap! state add-log)})
You can’t perform that action at this time.
0 commit comments