@Override public void actionPerformed(ActionEvent event) { if (textField.getText().length() == 0) return; RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea(); if (pane == null) return; SearchContext context = new SearchContext(); context.setSearchFor(textField.getText()); context.setMatchCase(mcase.isSelected()); context.setRegularExpression(regex.isSelected()); context.setSearchForward(!reverse.isSelected()); context.setWholeWord(wholew.isSelected()); if (!SearchEngine.find(pane, context).wasFound()) { if (wrap.isSelected()) { pane.setSelectionStart(0); pane.setSelectionEnd(0); } else { mainWindow.getLabel().setText("Search Complete"); } } }
@Override public void actionPerformed(ActionEvent e) { if (textField.getText().length() == 0) return; RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea(); if (pane == null) return; SearchContext context = new SearchContext(); context.setSearchFor(textField.getText()); context.setMatchCase(mcase.isSelected()); context.setRegularExpression(regex.isSelected()); context.setSearchForward(direction); context.setWholeWord(wholew.isSelected()); if (!SearchEngine.find(pane, context).wasFound()) { if (wrap.isSelected()) { pane.setSelectionStart(0); pane.setSelectionEnd(0); } else { mainWindow.getLabel().setText("Search Complete"); } } }
context.setSearchFor(searchText); context.setMatchCase(matchCase); context.setRegularExpression(regex); context.setSearchForward(forward); context.setWholeWord(wholeWord);
@Override public void actionPerformed(ActionEvent e) { // "FindNext" => search forward, "FindPrev" => search backward String command = e.getActionCommand(); boolean forward = "FindNext".equals(command); // Create an object defining our search parameters. SearchContext context = new SearchContext(); String text = searchField.getText(); if (text.length() == 0) { return; } context.setSearchFor(text); context.setMatchCase(matchCaseCB.isSelected()); context.setRegularExpression(regexCB.isSelected()); context.setSearchForward(forward); context.setWholeWord(false); boolean found = SearchEngine.find(textArea, context).wasFound(); if (!found) { JOptionPane.showMessageDialog(this, "Text not found"); } }
@Test public void testSearchEngineReplaceAll_zeroLengthMatches_emptyText() { textArea.setText(""); SearchContext context = new SearchContext(); context.setSearchFor(".*"); context.setReplaceWith(""); context.setRegularExpression(true); int count = replaceAllImpl(context); // The goal here is simply to not go into an infinite loop assertEquals(1, count); }
@Test public void testSearchEngineReplaceAll_zeroLengthMatches() { textArea.setText("one two three"); SearchContext context = new SearchContext(); context.setSearchFor(".*"); context.setReplaceWith(""); context.setRegularExpression(true); int count = replaceAllImpl(context); // The goal here is simply to not go into an infinite loop assertEquals(1, count); }
@Test public void testSearchEngineReplaceAll_zeroLengthMatches_multiMatch() { textArea.setText("a\nba\n\na"); SearchContext context = new SearchContext(); context.setSearchFor("(?=a)"); context.setReplaceWith("CCC"); context.setRegularExpression(true); int count = replaceAllImpl(context); assertEquals(3, count); assertEquals("CCCa\nbCCCa\n\nCCCa", textArea.getText()); }
context.setMatchCase(true); context.setWholeWord(false); context.setRegularExpression(false); count = replaceAllImpl(context); assertEquals(3, count); context.setMatchCase(false); context.setWholeWord(true); context.setRegularExpression(false); count = replaceAllImpl(context); assertEquals(2, count); context.setMatchCase(true); context.setWholeWord(true); context.setRegularExpression(false); count = replaceAllImpl(context); assertEquals(1, count); context.setMatchCase(false); context.setWholeWord(false); context.setRegularExpression(true); count = replaceAllImpl(context); assertEquals(5, count); context.setMatchCase(true); context.setWholeWord(false); context.setRegularExpression(true); count = replaceAllImpl(context); assertEquals(3, count);
/** * Click on the replace all button */ public void onReplaceAll() { String text = findTF.getText(); if (text.length() == 0) { return; } String textReplace = replaceTF.getText(); if (!textReplace.equals(text)) { boolean matchCase = matchCaseCB.isSelected(); boolean wholeWord = wholeWrdsCB.isSelected(); boolean regex = regexCB.isSelected(); SearchContext c = new SearchContext(); c.setMatchCase(matchCase); c.setSearchFor(text); c.setWholeWord(wholeWord); c.setRegularExpression(regex); c.setReplaceWith(textReplace); SearchEngine.replaceAll(rSyntaxTextArea, c); } }
/** * Click on the replace all button */ public void onReplaceAll() { String text = findTF.getText(); if (text.length() == 0) { return; } String textReplace = replaceTF.getText(); if (!textReplace.equals(text)) { boolean matchCase = matchCaseCB.isSelected(); boolean wholeWord = wholeWrdsCB.isSelected(); boolean regex = regexCB.isSelected(); SearchContext c = new SearchContext(); c.setMatchCase(matchCase); c.setSearchFor(text); c.setWholeWord(wholeWord); c.setRegularExpression(regex); c.setReplaceWith(textReplace); SearchEngine.replaceAll(rSyntaxTextArea, c); } }
/** * Click on the find next button */ public void onFindNext() { String text = findTF.getText(); if (text.length() == 0) { return; } boolean markAll = markAllCB.isSelected(); boolean forward = downCB.isSelected(); boolean matchCase = matchCaseCB.isSelected(); boolean wholeWord = wholeWrdsCB.isSelected(); boolean regex = regexCB.isSelected(); SearchContext c = new SearchContext(); c.setMarkAll(markAll); c.setMatchCase(matchCase); c.setSearchFor(text); c.setWholeWord(wholeWord); c.setRegularExpression(regex); c.setSearchForward(forward); boolean found = SearchEngine.find(rSyntaxTextArea, c).wasFound(); if (!found) { LOGGER.info(I18N.tr("Text not found !")); } }
context.setMatchCase(true); context.setWholeWord(false); context.setRegularExpression(false); textArea.setCaretPosition(offs); found = replaceImpl(context); context.setMatchCase(false); context.setWholeWord(true); context.setRegularExpression(false); textArea.setCaretPosition(offs); found = replaceImpl(context); context.setMatchCase(true); context.setWholeWord(true); context.setRegularExpression(false); textArea.setCaretPosition(offs); found = replaceImpl(context); context.setMatchCase(false); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(offs); found = replaceImpl(context); context.setMatchCase(true); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(offs); found = replaceImpl(context);
private void findFirst() { textArea.setCaretPosition(0); // Create an object defining our search parameters. SearchContext context = new SearchContext(); String text = searchField.getText(); if (text.length() == 0) { return; } context.setSearchFor(text); context.setMatchCase(matchCaseCB.isSelected()); context.setRegularExpression(regexCB.isSelected()); context.setSearchForward(true); context.setWholeWord(false); // if not found if (!SearchEngine.find(textArea, context).wasFound()) { searchField.setInvalidState(true); searchField.repaint(); nextButton.setEnabled(false); prevButton.setEnabled(false); replaceButton.setEnabled(false); } else { searchField.setInvalidState(false); searchField.repaint(); nextButton.setEnabled(true); prevButton.setEnabled(true); replaceButton.setEnabled(true); } revalidate(); getMainCanvas().revalidate(); }
/** * https://github.com/bobbylight/RSyntaxTextArea/issues/38 */ @Test public void testSearchEngineRegexFindEmptyString() throws Exception { textArea.setText("how the who for what is it howhow"); String searchFor = "[how]{3}|"; SearchContext context = new SearchContext(searchFor); context.setRegularExpression(true); assertTrue(findImpl(context)); assertResult(new SearchResult(new DocumentRange(0, 3), 1, 4)); assertTrue(findImpl(context)); assertResult(new SearchResult(new DocumentRange(8, 11), 1, 4)); assertTrue(findImpl(context)); assertResult(new SearchResult(new DocumentRange(27, 30), 1, 4)); assertTrue(findImpl(context)); assertResult(new SearchResult(new DocumentRange(30, 33), 1, 4)); assertFalse(findImpl(context)); }
private SearchContext createSearchContext(String text, boolean forward, boolean matchCase, boolean isRegex) { SearchContext context = new SearchContext(); context.setSearchFor(text); context.setMatchCase(matchCase); context.setRegularExpression(isRegex); context.setSearchForward(forward); context.setMarkAll(false); context.setSearchSelectionOnly(false); context.setWholeWord(false); return context; } }
@Test public void testClone() { String searchFor = "foo"; boolean matchCase = true; boolean markAll = false; boolean regex = true; String replaceWith = "bar"; boolean forward = false; boolean selectionOnly = false;//true; // "true" not yet supported boolean wholeWord = true; SearchContext sc = new SearchContext(searchFor, matchCase); sc.setMarkAll(markAll); sc.setRegularExpression(regex); sc.setReplaceWith(replaceWith); sc.setSearchForward(forward); sc.setSearchSelectionOnly(selectionOnly); sc.setWholeWord(wholeWord); SearchContext sc2 = sc.clone(); Assert.assertEquals(sc2.getSearchFor(), sc.getSearchFor()); Assert.assertEquals(sc2.getMatchCase(), sc.getMatchCase()); Assert.assertEquals(sc2.getMarkAll(), sc.getMarkAll()); Assert.assertEquals(sc2.isRegularExpression(), sc.isRegularExpression()); Assert.assertEquals(sc2.getReplaceWith(), sc.getReplaceWith()); Assert.assertEquals(sc2.getSearchForward(), sc.getSearchForward()); Assert.assertEquals(sc2.getSearchSelectionOnly(), sc.getSearchSelectionOnly()); Assert.assertEquals(sc2.getWholeWord(), sc.getWholeWord()); }
context.setRegularExpression(true);
context.setMatchCase(false); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(end); res = SearchEngine.markAll(textArea, context); context.setMatchCase(true); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(end); res = SearchEngine.markAll(textArea, context); context.setMatchCase(false); context.setWholeWord(true); context.setRegularExpression(true); textArea.setCaretPosition(end); res = SearchEngine.markAll(textArea, context); context.setMatchCase(true); context.setWholeWord(true); context.setRegularExpression(true); textArea.setCaretPosition(end); res = SearchEngine.markAll(textArea, context);
context.setMatchCase(false); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(end); found = findImpl(context); context.setMatchCase(true); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(end); found = findImpl(context); context.setMatchCase(false); context.setWholeWord(true); context.setRegularExpression(true); textArea.setCaretPosition(end); found = findImpl(context); context.setMatchCase(true); context.setWholeWord(true); context.setRegularExpression(true); textArea.setCaretPosition(end); found = findImpl(context);
context.setMatchCase(false); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(0); found = findImpl(context); context.setMatchCase(true); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(0); found = findImpl(context); context.setMatchCase(false); context.setWholeWord(true); context.setRegularExpression(true); textArea.setCaretPosition(0); found = findImpl(context); context.setMatchCase(true); context.setWholeWord(true); context.setRegularExpression(true); textArea.setCaretPosition(0); found = findImpl(context);