@Override public void setCaretPosition(int offset) { textArea.setCaretPosition(offset); }
int lineNum = rTextArea.getLineOfOffset(caretPos) - 1; if (lineNum > 1) { rTextArea.setCaretPosition(rTextArea.getLineStartOffset(lineNum)); int pos = SearchEngine.getNextMatchPos(searchText, rTextArea.getText(), forward, matchCase, wholeWord); if (pos != -1) { rTextArea.setCaretPosition(forward ? 0 : rTextArea.getDocument().getLength() - 1); search(direction); searchField.setBackground(COLOR_BG_WARN);
textArea.setCaretPosition(0); textArea.requestFocusInWindow(); textArea.setMarkOccurrences(true);
@Override public void actionPerformed(ActionEvent e) { setText(res); textArea.setCaretPosition(0); textArea.setSyntaxEditingStyle(style); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { RSyntaxTextArea rsta = (RSyntaxTextArea)textArea; bracketInfo = RSyntaxUtilities.getMatchingBracketPosition(rsta, bracketInfo); if (bracketInfo.y>-1) { // Go to the position AFTER the bracket so the previous // bracket (which we were just on) is highlighted. rsta.setCaretPosition(bracketInfo.y+1); } else { UIManager.getLookAndFeel().provideErrorFeedback(rsta); } }
@Override public void mouseClicked(MouseEvent e) { Component source = (Component)e.getSource(); if (source instanceof Marker) { ((Marker)source).mouseClicked(e); return; } int line = yToLine(e.getY()); if (line>-1) { try { int offs = textArea.getLineStartOffset(line); textArea.setCaretPosition(offs); } catch (BadLocationException ble) { // Never happens UIManager.getLookAndFeel().provideErrorFeedback(textArea); } } }
/** * Sets the content in the text area to that in the specified resource. * * @param resource The resource to load. */ private void setText(String resource) { BufferedReader r; try { r = new BufferedReader(new InputStreamReader( getClass().getResourceAsStream(resource), StandardCharsets.UTF_8)); textArea.read(r, null); r.close(); textArea.setCaretPosition(0); textArea.discardAllEdits(); } catch (RuntimeException re) { throw re; // FindBugs } catch (Exception e) { // Never happens textArea.setText("Type here to see syntax highlighting"); } }
textArea.setCaretPosition(0); textArea.addHyperlinkListener(this); textArea.requestFocusInWindow();
return; textArea.setCaretPosition(end-1); textArea.setCaretPosition(dot); textArea.setCaretPosition(dot);
protected void mouseClicked(MouseEvent e) { ParserNotice pn = notices.get(0); int offs = pn.getOffset(); int len = pn.getLength(); if (offs>-1 && len>-1) { // These values are optional DocumentRange range = new DocumentRange(offs, offs + len); RSyntaxUtilities.selectAndPossiblyCenter(textArea, range, true); } else { int line = pn.getLine(); try { offs = textArea.getLineStartOffset(line); textArea.getFoldManager().ensureOffsetNotInClosedFold(offs); textArea.setCaretPosition(offs); } catch (BadLocationException ble) { // Never happens UIManager.getLookAndFeel().provideErrorFeedback(textArea); } } }
String afterText = getAfterTextIndented(s); doc.replace(p0,p1-p0, beforeText+afterText, null); textArea.setCaretPosition(p0+beforeText.length());
textArea.setCaretPosition(dot); // Caret may have moved
sb.append(s.substring(nonWhitespacePos)); sta.replaceRange(sb.toString(), caretPos, end); sta.setCaretPosition(caretPos + leadingWS.length()+1);
@Test public void testGetWordEnd_noSelection_happyPath() { EndWordAction action = new EndWordAction("endWordAction", false); RSyntaxDocument doc = new RSyntaxDocument( SyntaxConstants.SYNTAX_STYLE_JAVA); RSyntaxTextArea textArea = new RSyntaxTextArea(doc); final String TEXT = "This is the best"; textArea.setText(TEXT); for (int i = 0; i < "This".length(); i++) { textArea.setCaretPosition(i); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("This".length(), textArea.getCaretPosition()); } textArea.setCaretPosition("This".length()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("This ".length(), textArea.getCaretPosition()); textArea.setCaretPosition("This ".length()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals("This is".length(), textArea.getCaretPosition()); textArea.setCaretPosition(TEXT.length()); action.actionPerformed(createActionEvent(textArea)); Assert.assertEquals(TEXT.length(), textArea.getCaretPosition()); }
textArea.setCaretPosition(dot);
textArea.setCaretPosition(end); SearchResult res = SearchEngine.markAll(textArea, context); assertEquals(end, textArea.getCaretPosition()); assertEquals(new SearchResult(null, 0, 4), res); textArea.setCaretPosition(3); res = SearchEngine.markAll(textArea, context); assertEquals(3, textArea.getCaretPosition()); textArea.setCaretPosition(end); res = SearchEngine.markAll(textArea, context); assertEquals(end, textArea.getCaretPosition()); assertEquals(new SearchResult(null, 0, 1), res); textArea.setCaretPosition(1); res = SearchEngine.markAll(textArea, context); assertEquals(1, textArea.getCaretPosition()); context.setMatchCase(false); context.setWholeWord(true); textArea.setCaretPosition(end); res = SearchEngine.markAll(textArea, context); assertEquals(end, textArea.getCaretPosition()); assertEquals(new SearchResult(null, 0, 2), res); textArea.setCaretPosition(5); res = SearchEngine.markAll(textArea, context); assertEquals(5, textArea.getCaretPosition()); context.setMatchCase(true); context.setWholeWord(true); textArea.setCaretPosition(end);
textArea.setText(text); String expected = textArea.getText().replaceAll("(?i:" + context.getSearchFor() + ")", context.getReplaceWith()); textArea.setCaretPosition(offs); boolean found = replaceImpl(context); assertTrue(found); context.setWholeWord(false); context.setRegularExpression(false); textArea.setCaretPosition(offs); found = replaceImpl(context); assertTrue(found); context.setWholeWord(true); context.setRegularExpression(false); textArea.setCaretPosition(offs); found = replaceImpl(context); assertTrue(found); context.setWholeWord(true); context.setRegularExpression(false); textArea.setCaretPosition(offs); found = replaceImpl(context); assertTrue(found); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(offs); found = replaceImpl(context); assertTrue(found);
textArea.setCaretPosition(textArea.getText().length()-4); expected = "oo oO oo"; context.setMatchCase(false); expected = "152k 5271143M 3985k"; textArea.setText(expected); textArea.setCaretPosition(8); context.setMatchCase(false); context.setWholeWord(false);
int markedCount = markAll ? 4 : 0; context.setMatchCase(false); textArea.setCaretPosition(end); boolean found = findImpl(context); assertTrue(found); markedCount = markAll ? 1 : 0; context.setMatchCase(true); textArea.setCaretPosition(end); found = findImpl(context); assertTrue(found); context.setMatchCase(false); context.setWholeWord(true); textArea.setCaretPosition(end); found = findImpl(context); assertTrue(found); context.setMatchCase(true); context.setWholeWord(true); textArea.setCaretPosition(end); found = findImpl(context); assertTrue(found); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(end); found = findImpl(context); assertTrue(found);
markedCount = markAll ? 1 : 0; context.setMatchCase(true); textArea.setCaretPosition(0); found = findImpl(context); assertTrue(found); context.setMatchCase(false); context.setWholeWord(true); textArea.setCaretPosition(0); found = findImpl(context); assertTrue(found); context.setMatchCase(true); context.setWholeWord(true); textArea.setCaretPosition(0); found = findImpl(context); assertTrue(found); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(0); found = findImpl(context); assertTrue(found); context.setWholeWord(false); context.setRegularExpression(true); textArea.setCaretPosition(0); found = findImpl(context); assertTrue(found);