|
29 | 29 |
|
30 | 30 | package org.scijava.ui.swing.script; |
31 | 31 |
|
| 32 | +import java.awt.Color; |
32 | 33 | import java.awt.Component; |
33 | 34 | import java.awt.Container; |
34 | 35 | import java.awt.Dimension; |
35 | 36 | import java.awt.Font; |
36 | 37 | import java.awt.Graphics2D; |
37 | 38 | import java.awt.event.ActionEvent; |
| 39 | +import java.awt.event.MouseAdapter; |
| 40 | +import java.awt.event.MouseEvent; |
38 | 41 | import java.awt.image.BufferedImage; |
39 | 42 | import java.io.BufferedReader; |
40 | 43 | import java.io.BufferedWriter; |
|
71 | 74 | import org.fife.ui.rtextarea.RTextArea; |
72 | 75 | import org.fife.ui.rtextarea.RTextScrollPane; |
73 | 76 | import org.fife.ui.rtextarea.RecordableTextAction; |
| 77 | +import org.fife.ui.rtextarea.SearchContext; |
| 78 | +import org.fife.ui.rtextarea.SearchEngine; |
74 | 79 | import org.scijava.Context; |
75 | 80 | import org.scijava.log.LogService; |
76 | 81 | import org.scijava.platform.PlatformService; |
@@ -164,6 +169,42 @@ public void hyperlinkUpdate(final HyperlinkEvent hle) { |
164 | 169 | wordMovement(-1, true)); |
165 | 170 | ToolTipManager.sharedInstance().registerComponent(this); |
166 | 171 | getDocument().addDocumentListener(this); |
| 172 | + |
| 173 | + addMouseListener(new MouseAdapter() { |
| 174 | + |
| 175 | + SearchContext context; |
| 176 | + |
| 177 | + @Override |
| 178 | + public void mousePressed(final MouseEvent me) { |
| 179 | + |
| 180 | + // 2022.02 TF: 'Mark All' occurrences is quite awkward. What is |
| 181 | + // marked is language-specific and the defaults are restricted |
| 182 | + // to certain identifiers. We'll hack things so that it works |
| 183 | + // for any selection by double-click. See |
| 184 | + // https://github.com/bobbylight/RSyntaxTextArea/issues/88 |
| 185 | + if (getMarkOccurrences() && 2 == me.getClickCount()) { |
| 186 | + |
| 187 | + // Do nothing if getMarkOccurrences() is unset or no selection exists |
| 188 | + final String str = getSelectedText(); |
| 189 | + if (str == null) return; |
| 190 | + |
| 191 | + if (context != null && str.equals(context.getSearchFor())) { |
| 192 | + // Selection is the previously 'marked all' scope. Clear it |
| 193 | + SearchEngine.markAll(EditorPane.this, new SearchContext()); |
| 194 | + context = null; |
| 195 | + } else { |
| 196 | + // Use SearchEngine for 'mark all' |
| 197 | + final Color stashedColor = getMarkAllHighlightColor(); |
| 198 | + setMarkAllHighlightColor(getMarkOccurrencesColor()); |
| 199 | + context = new SearchContext(str, true); |
| 200 | + context.setMarkAll(true); |
| 201 | + context.setWholeWord(true); |
| 202 | + SearchEngine.markAll(EditorPane.this, context); |
| 203 | + setMarkAllHighlightColor(stashedColor); |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | + }); |
167 | 208 | } |
168 | 209 |
|
169 | 210 | @Override |
|
0 commit comments