Skip to content

Commit

Permalink
fixed caret on opening a file
Browse files Browse the repository at this point in the history
  • Loading branch information
saikyun committed Jun 4, 2021
1 parent 70ca328 commit 4d57323
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/.janet-usages
/.judge
/init.janet
/janet_libs
58 changes: 27 additions & 31 deletions misc/frp4.janet
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,21 @@
(i/handle-keyboard2
(self :gb)
k)
(put self :event/changed true)
)
(put self :event/changed true))
[:char k]
(do
(i/handle-keyboard-char
(self :gb)
k)
(put self :event/changed true)
)
(i/handle-keyboard-char
(self :gb)
k)
(put self :event/changed true))
[:scroll n mp]
(when (in-rec? mp
(i/gb-rec (self :gb)))

(push-callback! ev (fn []
(i/handle-scroll-event (self :gb) n)
(put self :event/changed true)
)))

(when (in-rec? mp
(i/gb-rec (self :gb)))

(push-callback! ev (fn []
(i/handle-scroll-event (self :gb) n)
(put self :event/changed true))))

['(mouse-events (first ev)) _]
(i/handle-mouse-event
(self :gb)
Expand All @@ -141,9 +138,7 @@
(push-callback! ev (fn []
(f)
(e/put! state/focus123 :focus self)
(put (self :gb) :event/changed true)

))))))
(put (self :gb) :event/changed true)))))))

(merge-into state/file-open-data {:binds i/file-open-binds})

Expand Down Expand Up @@ -189,9 +184,9 @@
[props]
(let [search-term (string (content props))]
(put-caret state/gb-data (if (state/gb-data :selection)
(max (state/gb-data :selection)
(state/gb-data :caret))
(state/gb-data :caret)))
(max (state/gb-data :selection)
(state/gb-data :caret))
(state/gb-data :caret)))
(when-let [i (gb-find-forward! state/gb-data search-term)]
(-> state/gb-data
(reset-blink)
Expand All @@ -203,9 +198,9 @@
[props]
(let [search-term (string (content props))]
(put-caret state/gb-data (if (state/gb-data :selection)
(min (state/gb-data :selection)
(state/gb-data :caret))
(state/gb-data :caret)))
(min (state/gb-data :selection)
(state/gb-data :caret))
(state/gb-data :caret)))
(when-let [i (gb-find-backward! state/gb-data search-term)]
(-> state/gb-data
(reset-blink)
Expand Down Expand Up @@ -293,28 +288,29 @@

(def caret
@{:draw (fn [self]
(when-let [gb (self :gb)]
(when-let [gb (and (self :on)
(self :gb))]
(render-cursor gb)))

:on true

:on-event (fn [self ev]

(match ev
{:focus state/focus123}
(do
(when (get-in state/focus123 [:gb :caret-pos])
(when (get-in state/focus123 [:gb :gap])
(put self :gb (state/focus123 :gb))
(set ((self :gb) :blink) 0)
(put self :on true)))
(put self :on true))

[:dt dt]
(when (self :gb)
(when (and (> ((self :gb) :blink) 30)
(update (self :gb) :blink + dt)

(when (and (> ((self :gb) :blink) 0.6)
(self :on))
(put self :on false))

(when (> ((self :gb) :blink) 60)
(when (> ((self :gb) :blink) 1.0)
(set ((self :gb) :blink) 0)
(put self :on true)))))})

Expand Down
7 changes: 0 additions & 7 deletions new_menu.janet
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,6 @@
:draw menu-draw
:on-event menu-event})

(def dependencies
@{frp/mouse @[frp/text-area frp/search-area frp/file-open-area]
frp/keyboard @[|(:on-event (state/focus123 :focus) $)]
frp/chars @[|(:on-event (state/focus123 :focus) $)]
state/focus123 @[frp/caret]
frp/callbacks @[frp/handle-callbacks]})

(def dependencies
@{frp/mouse @[frp/text-area frp/search-area frp/file-open-area menu]
frp/keyboard @[#pp
Expand Down
2 changes: 1 addition & 1 deletion src/input.janet
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@

(defn quit
[props]
(put (tracev (props :context)) :quit true))
(put (props :context) :quit true))

(defn open-file
[props]
Expand Down
3 changes: 1 addition & 2 deletions src/render_new_gap_buffer.janet
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,7 @@ This function is pretty expensive since it redoes all word wrapping."

# (rl-scalef 2 2 1)

(when-let [[x y] (and (< (gb :blink) 30)
(gb :caret-pos))
(when-let [[x y] (gb :caret-pos)
cx (abs-text-x gb x)
cy (abs-text-y gb (+ y scroll -2))]

Expand Down

0 comments on commit 4d57323

Please sign in to comment.