int caretPos = rTextArea.getCaretPosition(); int lineNum = rTextArea.getLineOfOffset(caretPos) - 1; if (lineNum > 1) {
/** * Restarts this timer, and stores a new offset to paint. * * @param matchedBracketOffs The offset of the new matched bracket. */ public void restart(int matchedBracketOffs) { this.origDot = getCaretPosition(); this.matchedBracketOffs = matchedBracketOffs; this.restart(); }
/** * Returns the template that should be inserted at the current caret * position, assuming the trigger character was pressed. * * @param textArea The text area that's getting text inserted into it. * @return A template that should be inserted, if appropriate, or * <code>null</code> if no template should be inserted. */ public synchronized CodeTemplate getTemplate(RSyntaxTextArea textArea) { int caretPos = textArea.getCaretPosition(); int charsToGet = Math.min(caretPos, maxTemplateIDLength); try { Document doc = textArea.getDocument(); doc.getText(caretPos-charsToGet, charsToGet, s); @SuppressWarnings("unchecked") int index = Collections.binarySearch(templates, s, comparator); return index>=0 ? (CodeTemplate)templates.get(index) : null; } catch (BadLocationException ble) { ble.printStackTrace(); throw new InternalError("Error in CodeTemplateManager"); } }
protected Fold getClosestFold(RSyntaxTextArea textArea) { int offs = textArea.getCaretPosition(); int line = textArea.getCaretLineNumber(); FoldManager fm = textArea.getFoldManager(); Fold fold = fm.getFoldForLine(line); if (fold==null) { fold = fm.getDeepestOpenFoldContaining(offs); } return fold; }
int dot = textArea.getCaretPosition(); if (dot>=start && dot<start+leadingWS.length()+mlcMarker.length()) { textArea.replaceSelection("\n" + header); if (nested) { dot = textArea.getCaretPosition(); // Has changed textArea.insert("\n" + leadingWS + " */", dot); textArea.setCaretPosition(dot);
int dot = textArea.getCaretPosition(); int end = textArea.getLineEndOffsetOfCurrentLine();
int caretPos = sta.getCaretPosition(); Document doc = sta.getDocument(); Element map = doc.getDefaultRootElement();
@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()); }
private void centralizarCodigoFonte() { SwingUtilities.invokeLater(() -> { rolarAtePosicao(textArea.getCaretPosition()); }); }
/** * Restarts this timer, and stores a new offset to paint. * * @param matchedBracketOffs The offset of the new matched bracket. */ public void restart(int matchedBracketOffs) { this.origDot = getCaretPosition(); this.matchedBracketOffs = matchedBracketOffs; this.restart(); }
int dot = textArea.getCaretPosition(); Token t = textArea.getTokenListForLine(textArea.getCaretLineNumber()); Token toMark = null;
dot = rsta.getCaretPosition() - 1; // Start before '}' int line = root.getElementIndex(dot); Element elem = root.getElement(line);
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()); assertEquals(new SearchResult(null, 0, 4), res); 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()); assertEquals(new SearchResult(null, 0, 1), res); 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()); assertEquals(new SearchResult(null, 0, 2), res); textArea.setCaretPosition(end); res = SearchEngine.markAll(textArea, context);
int caretPosition = textArea.getCaretPosition() - 1; RSyntaxDocument doc = (RSyntaxDocument)textArea.getDocument(); char bracket = 0;
@Override public void actionPerformed(ActionEvent e) { try { int caretPosition = textArea.getCaretPosition(); String codigoFormatado = FormatadorCodigo.formata(textArea.getText()); textArea.setText(codigoFormatado); textArea.setCaretPosition(caretPosition); } catch (ErroCompilacao ex) { Logger.getLogger(Editor.class.getName()).log(Level.SEVERE, null, ex); } } };
public int[] getBoundsOfCurrentSQLStatement() { int[] bounds = new int[2]; bounds[0] = scriptPanel.getSelectionStart(); bounds[1] = scriptPanel.getSelectionEnd(); if (bounds[0] == bounds[1]) { bounds = getSqlBoundsBySeparatorRule(scriptPanel.getCaretPosition()); } return bounds; }
protected Fold getClosestFold(RSyntaxTextArea textArea) { int offs = textArea.getCaretPosition(); int line = textArea.getCaretLineNumber(); FoldManager fm = textArea.getFoldManager(); Fold fold = fm.getFoldForLine(line); if (fold==null) { fold = fm.getDeepestOpenFoldContaining(offs); } return fold; }
private String getCurrentLineText() { int caretPosition = textArea.getCaretPosition(); Element root = textArea.getDocument().getDefaultRootElement(); int line= root.getElementIndex(caretPosition); Element elem = root.getElement(line); int endOffset = elem.getEndOffset(); int lineStart = elem.getStartOffset(); String text = ""; try { text = textArea.getText(lineStart, endOffset-lineStart).trim(); } catch (BadLocationException e) { e.printStackTrace(); } return text; }
public void iniciarExecucao(boolean depurar) { limparErroExecucao(); depurando = depurar; ultimaPosicaoCursor = textArea.getCaretPosition(); textArea.setEditable(false); textArea.setFocusable(false); textArea.setRequestFocusEnabled(false); textArea.setHighlightCurrentLine(false); resetaSelecaoDoTexto(); // corrige o problema descrito na issue #157 linhasCodigoDobradas = getLinhasCodigoDobradas(); }
assertEquals(0, count); assertEquals(expected, textArea.getText()); assertEquals(8, textArea.getCaretPosition()); // Caret doesn't move