MCPcopy Create free account
hub / github.com/benfry/processing4 / find

Method find

app/src/processing/app/ui/FindReplace.java:252–391  ·  view source on GitHub ↗
(boolean wrap, boolean backwards)

Source from the content-addressed store, hash-verified

250 // look for the next instance of the find string to be found
251 // once found, select it (and go to that line)
252 private boolean find(boolean wrap, boolean backwards) {
253 String searchTerm = findField.getText();
254
255 // this will catch "find next" being called when no search yet
256 if (searchTerm.length() != 0) {
257 String text = editor.getText();
258
259 // Started work on find/replace across tabs. These two variables
260 // store the original tab and selection position so that it knew
261 // when to stop rotating through.
262 Sketch sketch = editor.getSketch();
263 int tabIndex = sketch.getCurrentCodeIndex();
264
265 if (ignoreCase) {
266 searchTerm = searchTerm.toLowerCase();
267 text = text.toLowerCase();
268 }
269
270 int nextIndex;
271 if (!backwards) {
272 //int selectionStart = editor.textarea.getSelectionStart();
273 int selectionEnd = editor.getSelectionStop();
274
275 nextIndex = text.indexOf(searchTerm, selectionEnd);
276 if (nextIndex == -1 && wrap && !allTabs) {
277 // if wrapping, a second chance is ok, start from beginning
278 nextIndex = text.indexOf(searchTerm);
279
280 } else if (nextIndex == -1 && allTabs) {
281 // For searching in all tabs, wrapping always happens.
282
283 int tempIndex = tabIndex;
284 // Look for search term in all tabs.
285 while (tabIndex <= sketch.getCodeCount() - 1) {
286 if (tabIndex == sketch.getCodeCount() - 1) {
287 // System.out.println("wrapping.");
288 tabIndex = -1;
289 // removing for 4.1.2, this was never being run, but is it hiding a bug? [fry 230116]
290// } else if (tabIndex == sketch.getCodeCount() - 1) {
291// break;
292 }
293
294 try {
295 Document doc = sketch.getCode(tabIndex + 1).getDocument();
296 if(doc != null) {
297 text = doc.getText(0, doc.getLength()); // this thing has the latest changes
298 }
299 else {
300 text = sketch.getCode(tabIndex + 1).getProgram(); // not this thing.
301 }
302 } catch (BadLocationException e) {
303 e.printStackTrace();
304 }
305 tabIndex++;
306 if (ignoreCase) {
307 text = text.toLowerCase();
308 }
309 nextIndex = text.indexOf(searchTerm);

Callers 15

replaceAllMethod · 0.95
findNextMethod · 0.95
findPreviousMethod · 0.95
parsePolyMethod · 0.80
matchMethod · 0.80
matchAllMethod · 0.80
markDownLinksToHtmlMethod · 0.80
parseProgramImportsMethod · 0.80
replaceHexLiteralsMethod · 0.80
replaceColorRegexMethod · 0.80
fixFloatsRegexMethod · 0.80

Calls 13

getCurrentCodeIndexMethod · 0.95
getCodeCountMethod · 0.95
getCodeMethod · 0.95
setCurrentCodeMethod · 0.95
setFoundMethod · 0.95
getSketchMethod · 0.80
getProgramMethod · 0.80
setSelectionMethod · 0.80
getTextMethod · 0.45
getSelectionStopMethod · 0.45
getDocumentMethod · 0.45
printStackTraceMethod · 0.45

Tested by

no test coverage detected