Skip to content

Commit

Permalink
Add one-pass search
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaaad committed Jul 5, 2020
1 parent e51d2a3 commit 18e1971
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 144 deletions.
21 changes: 4 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,9 @@ alive.

## To do
- structural navigation
- text search (triggered either just by typing or with a shortcut)
- do I need to scroll back if I want to cancel the search? yes, accidental searches should
be reversible!
- jumps to first match when it's found
- direction of search? from the cursor (or top of the screen if no cursor) in both
directions
- enter/down/right to next occurrence, shift+enter/up/left to prev occurrence, esc to
abort search
- starts a process that scans lines in both direction
- what about changes to output view? new lines can be added: they need to be searched
too. output might be cleared for watcher views
- an alternative can be searching one item at a time synchronously. might have bad
performance.
- text-field or custom view? custom view requires more effort for text input, text field
requires more effort for focus management
- search is a part of output panel, not layout!
- text search (triggered either just by typing or with a shortcut):
- should be reversible: escape scrolls to the place of search start if there is
a highlight
- contextual eval:
- alt+up/down for history (persist history? per what?)
- auto-insert closing brackets
Expand All @@ -128,6 +115,6 @@ alive.
- improve datafy/nav support
- remember window position and size
- popup might appear in weird locations
- very long lines have poor performance
- *very* long lines have poor performance
- `vlaaad.reveal/-main`
- sometimes popup does not disappear
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{:deps {org.clojure/clojure {:mvn/version "1.10.1"}
cljfx {:mvn/version "1.7.3"}
cljfx/css {:mvn/version "1.1.0"}
org.apache.commons/commons-lang3 {:mvn/version "3.10"}
com.vladsch.flexmark/flexmark {:mvn/version "0.62.0"}
com.vladsch.flexmark/flexmark-ext-wikilink {:mvn/version "0.62.0"}
com.vladsch.flexmark/flexmark-ext-autolink {:mvn/version "0.62.0"}}
Expand Down
6 changes: 6 additions & 0 deletions src/vlaaad/reveal/event.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
(.setDaemon true))))]
(Executors/newCachedThreadPool factory)))

(defn daemon-future-call [f]
(.submit daemon-executor ^Callable (bound-fn* f)))

(defmacro daemon-future [& body]
`(daemon-future-call (^{:once true} fn* [] ~@body)))

(defmulti handle "[*state event]" (fn [*state e] (::type e)))

(defmethod handle :default [_ e]
Expand Down
26 changes: 5 additions & 21 deletions src/vlaaad/reveal/font.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@

(deftype Font [^javafx.scene.text.Font font ^double line-height ^double ascent char-width-cache])

(def ^:private ^:const min-cached-char-width
-42)

(def ^:private ^:const max-cached-char-width
Double/MAX_VALUE)

(defmacro ^:private if-class [class-name then else]
`(try
(Class/forName ^String ~class-name)
Expand All @@ -39,18 +33,8 @@
(def ^double ^:const line-height (Math/ceil (.getLineHeight metrics)))
(def ^double ^:const ascent (.getAscent metrics)))

(let [strike (.getStrike ^PGFont (get-native-font font)
BaseTransform/IDENTITY_TRANSFORM
FontResource/AA_GREYSCALE)
cache (double-array (inc (int Character/MAX_VALUE)) Double/MIN_VALUE)]
(defn char-width ^double [^Character character]
(let [ch (unchecked-char character)
i (unchecked-int ch)
cached-width (aget cache i)]
(if (= cached-width Double/MIN_VALUE)
(let [width (.getCharAdvance strike ch)]
(when (and (<= min-cached-char-width width)
(<= width max-cached-char-width))
(aset cache i width))
width)
cached-width))))
(def ^double ^:const char-width
(-> font
^PGFont get-native-font
(.getStrike BaseTransform/IDENTITY_TRANSFORM FontResource/AA_GREYSCALE)
(.getCharAdvance \a)))
1 change: 1 addition & 0 deletions src/vlaaad/reveal/fx.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- id from `:id` prop
- args from `:args` prop
- event handler
If returns a function, it will be called when process is stopped
- `:desc (required)` that will additionally receive the state"
(reify fx.lifecycle/Lifecycle
(create [_ {:keys [desc start args id] :or {id ::undefined}} opts]
Expand Down
22 changes: 14 additions & 8 deletions src/vlaaad/reveal/layout.clj
Original file line number Diff line number Diff line change
Expand Up @@ -530,17 +530,23 @@
start)]
(- scroll (- region-start start))))

(defn ensure-cursor-visible [layout]
(let [{:keys [lines cursor canvas-width canvas-height]} layout
[row col] cursor
line (lines row)
region-size (region-width (line col))
region-start (transduce (map region-width) + (subvec line 0 col))]
(defn ensure-rect-visible [layout {:keys [x y width height]}]
(let [{:keys [canvas-width canvas-height]} layout]
(-> layout
(update :scroll-y adjust-scroll canvas-height (* font/line-height (cursor/row cursor)) font/line-height)
(update :scroll-x adjust-scroll canvas-width region-start region-size)
(update :scroll-y adjust-scroll canvas-height y height)
(update :scroll-x adjust-scroll canvas-width x width)
make)))

(defn ensure-cursor-visible [layout]
(let [{:keys [lines cursor]} layout
[row col] cursor
line (lines row)]
(ensure-rect-visible layout
{:x (transduce (map region-width) + (subvec line 0 col))
:y (* font/line-height (cursor/row cursor))
:width (region-width (line col))
:height font/line-height})))

(defn cursor->canvas-bounds ^Bounds [layout]
(let [{:keys [lines cursor scroll-x scroll-y]} layout
[row col] cursor
Expand Down
3 changes: 2 additions & 1 deletion src/vlaaad/reveal/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
(defn- show-output [ui request message]
(when-let [code (:code request)]
(when-not (or (str/starts-with? code "(cursive.repl.runtime/")
(:done (:status message)))
(:done (:status message))
(= 0 (:pprint request)))
(let [{:keys [out value err nrepl.middleware.caught/throwable]
:or {out ::not-found
value ::not-found
Expand Down
Loading

0 comments on commit 18e1971

Please sign in to comment.