/** * @param str - if null -> reset current highlights */ private void highlightAllMatches(@Nullable String str) { SearchContext context = new SearchContext(str); context.setMarkAll(true); context.setMatchCase(true); context.setWholeWord(true); SearchEngine.markAll(this, context); }
private Component makeCell(JNode node, int column) { if (column == 0) { JLabel label = new JLabel(node.makeLongString() + " ", node.getIcon(), SwingConstants.LEFT); label.setFont(font); label.setOpaque(true); label.setToolTipText(label.getText()); return label; } if (!node.hasDescString()) { return emptyLabel; } RSyntaxTextArea textArea = CodeArea.getDefaultArea(mainWindow); textArea.setLayout(new GridLayout(1, 1)); textArea.setEditable(false); textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); textArea.setText(" " + node.makeDescString()); textArea.setRows(1); textArea.setColumns(textArea.getText().length() + 1); if (highlightText != null) { SearchContext searchContext = new SearchContext(highlightText); searchContext.setMatchCase(!highlightTextCaseInsensitive); searchContext.setMarkAll(true); SearchEngine.markAll(textArea, searchContext); } return textArea; }
@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"); } } }
boolean wholeWord = wholeWordCB.isSelected(); SearchContext context = new SearchContext(); context.setSearchFor(searchText); context.setMatchCase(matchCase);
@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"); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { String selectedText = textArea.getSelectedText(); if (selectedText == null || selectedText.length() == 0) { selectedText = RTextArea.getSelectedOccurrenceText(); if (selectedText == null || selectedText.length() == 0) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } } SearchContext context = new SearchContext(selectedText); if (!textArea.getMarkAllOnOccurrenceSearches()) { context.setMarkAll(false); } if (!SearchEngine.find(textArea, context).wasFound()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); } RTextArea.setSelectedOccurrenceText(selectedText); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { String selectedText = textArea.getSelectedText(); if (selectedText == null || selectedText.length() == 0) { selectedText = RTextArea.getSelectedOccurrenceText(); if (selectedText == null || selectedText.length() == 0) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } } SearchContext context = new SearchContext(selectedText); if (!textArea.getMarkAllOnOccurrenceSearches()) { context.setMarkAll(false); } context.setSearchForward(false); if (!SearchEngine.find(textArea, context).wasFound()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); } RTextArea.setSelectedOccurrenceText(selectedText); }
@Test(expected = UnsupportedOperationException.class) public void testSetSearchSelectionOnly_true() { SearchContext sc = new SearchContext(); sc.setSearchSelectionOnly(true); }
@Test public void testToString() { final String EXPECTED = "[SearchContext: searchFor=null, " + "replaceWith=null, matchCase=false, wholeWord=false, " + "regex=false, markAll=true]"; SearchContext sc = new SearchContext(); Assert.assertEquals(EXPECTED, sc.toString()); }
@Test public void testFirePropertyChange_booleanArgs() { TestPropertyChangeListener pcl = new TestPropertyChangeListener(); SearchContext sc = new SearchContext(); sc.addPropertyChangeListener(pcl); sc.firePropertyChange("fooProp", false, true); Assert.assertTrue(pcl.called); }
@Test public void testConstructor_2Arg() { SearchContext sc = new SearchContext("foo", true); Assert.assertEquals("foo", sc.getSearchFor()); Assert.assertTrue(sc.getMatchCase()); }
@Test public void testAddPropertyChangeListener() { TestPropertyChangeListener pcl = new TestPropertyChangeListener(); SearchContext sc = new SearchContext(); sc.addPropertyChangeListener(pcl); sc.firePropertyChange("fooProp", false, true); Assert.assertTrue(pcl.called); }
@Test public void testFirePropertyChange_stringArgs() { TestPropertyChangeListener pcl = new TestPropertyChangeListener(); SearchContext sc = new SearchContext(); sc.addPropertyChangeListener(pcl); sc.firePropertyChange("fooProp", "old", "new"); Assert.assertTrue(pcl.called); }
@Test public void testRemovePropertyChangeListener() { TestPropertyChangeListener pcl = new TestPropertyChangeListener(); SearchContext sc = new SearchContext(); sc.addPropertyChangeListener(pcl); sc.removePropertyChangeListener(pcl); sc.firePropertyChange("fooProp", false, true); Assert.assertFalse(pcl.called); }
@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()); }
/** * 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)); }
@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()); }