Browse files

When finding text (cmd+F), if text is selected in the source editor i…

…t wil be inserted into the search field to help the user search for his current selection.
  • Loading branch information...
1 parent 845e64c commit fc408d42017dc70f8d1482e5d76f0c2e312fb87f @casperc committed Jan 8, 2012
Showing with 10 additions and 3 deletions.
  1. +7 −3 src/clooj/search.clj
  2. +3 −0 src/clooj/utils.clj
@@ -7,7 +7,7 @@
(:import (java.awt Color)
(java.util.regex Pattern Matcher))
(:use [clooj.highlighting :only (highlight remove-highlights)]
- [clooj.utils :only (scroll-to-pos set-selection get-text-str)]))
+ [clooj.utils :only (scroll-to-pos set-selection get-text-str get-selected-text)]))
(def case-insensitive-search
(reduce bit-or
@@ -64,12 +64,16 @@
(defn start-find [app]
(let [sta (app :search-text-area)
- arg (app :arglist-label)]
+ arg (app :arglist-label)
+ dta (:doc-text-area app)
+ sel-text (get-selected-text dta)]
(.setVisible arg false)
(doto sta
(.setVisible true)
- (.selectAll))))
+ (.selectAll))
+ (if (not (empty? sel-text))
+ (.setText sta sel-text))))
(defn stop-find [app]
(let [sta (app :search-text-area)
@@ -203,6 +203,9 @@
(.requestFocusInWindow text-comp)
(scroll-to-caret text-comp))
+(defn get-selected-text [text-comp]
+ (.getText text-comp (.getSelectionStart text-comp) (- (.getSelectionEnd text-comp) (.getSelectionStart text-comp))))
(defn get-selected-lines [text-comp]
(let [row1 (get-line-of-offset text-comp (.getSelectionStart text-comp))
row2 (inc (get-line-of-offset text-comp (.getSelectionEnd text-comp)))]

0 comments on commit fc408d4

Please sign in to comment.