String beforeText = getBeforeTextIndented(s); String afterText = getAfterTextIndented(s); doc.replace(p0,p1-p0, beforeText+afterText, null); textArea.setCaretPosition(p0+beforeText.length());
@Test public void testFireDocumentEvent_RemoveWithinOneLine() throws Exception { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); insertHelloWorldC(doc); TestDocumentListener l = new TestDocumentListener(); doc.addDocumentListener(l); doc.replace(52, 3, null, null); // Replace "main" with "m" // Two events sent - A change/remove pair. Assert.assertEquals(2, l.events.size()); DocumentEvent e = l.events.get(0); // offset and length == start and end lines AFTER remove with new EOL // tokens. In this case a new line was "added" by this change. assertDocumentEvent(e, DocumentEvent.EventType.CHANGE, 3, 3); e = l.events.get(1); assertDocumentEvent(e, DocumentEvent.EventType.REMOVE, 52, 3); }
@Test public void testFireDocumentEvent_InsertWithTwoNewLinesOneReplaced() throws Exception { String syntaxStyle = SyntaxConstants.SYNTAX_STYLE_C; doc = new RSyntaxDocument(syntaxStyle); insertHelloWorldC(doc); TestDocumentListener l = new TestDocumentListener(); doc.addDocumentListener(l); int oldLen = doc.getLength(); String text = "// Inserted line 1\nprintf(\"This is working\n\");"; doc.replace(oldLen - 4, 1, text, null); // Four events sent - One change/remove pair and one change/insert // pair. Remove is the one line replaced. Assert.assertEquals(4, l.events.size()); DocumentEvent e = l.events.get(0); // offset and length == start and end lines AFTER remove with new EOL // tokens. In this case a new line was "added" by this change. assertDocumentEvent(e, DocumentEvent.EventType.CHANGE, 6, 6); e = l.events.get(1); assertDocumentEvent(e, DocumentEvent.EventType.REMOVE, oldLen - 4, 1); e = l.events.get(2); // offset and length == start and end lines AFTER insert with new EOL // tokens. In this case a new line was "added" by this change. assertDocumentEvent(e, DocumentEvent.EventType.CHANGE, 8, 8); e = l.events.get(3); assertDocumentEvent(e, DocumentEvent.EventType.INSERT, oldLen - 4, text.length()); }
/** * Verifies that using an {@link RSyntaxDocument}'s iterator returns the * same set of tokens as manually getting the token list for each line. */ @Test public void testBasicIteration() throws Exception { RSyntaxDocument doc = null; // A well-formed Java document. doc = loadResource("TokenIteratorTest_JavaBasic.txt", SyntaxConstants.SYNTAX_STYLE_JAVA); assertIteratorMatchesList(doc); // An unterminated Javadoc comment. doc = loadResource("TokenIteratorTest_UnterminatedJavadoc.txt", SyntaxConstants.SYNTAX_STYLE_JAVA); assertIteratorMatchesList(doc); // A single line. doc.replace(0, doc.getLength(), "one two three", null); assertIteratorMatchesList(doc); // A single-line unterminated MLC. doc.replace(0, doc.getLength(), "/* Unterminated MLC", null); assertIteratorMatchesList(doc); }
String beforeText = getBeforeTextIndented(s); String afterText = getAfterTextIndented(s); doc.replace(p0,p1-p0, beforeText+ placeholder + afterText, null); textArea.setCaretPosition(p0+beforeText.length()); textArea.moveCaretPosition(p0+beforeText.length() + placeholder.length());
String beforeText = getBeforeTextIndented(s); String afterText = getAfterTextIndented(s); doc.replace(p0,p1-p0, beforeText+afterText, null); textArea.setCaretPosition(p0+beforeText.length());
String beforeText = getBeforeTextIndented(s); String afterText = getAfterTextIndented(s); doc.replace(p0,p1-p0, beforeText+afterText, null); textArea.setCaretPosition(p0+beforeText.length());
String beforeText = getBeforeTextIndented(s); String afterText = getAfterTextIndented(s); doc.replace(p0,p1-p0, beforeText+afterText, null); textArea.setCaretPosition(p0+beforeText.length());
Assert.assertEquals(7, action.getWordStart(textArea, 7)); doc.replace(0, doc.getLength(), "", null); Assert.assertEquals(0, action.getWordStart(textArea, 0));
Assert.assertEquals(7, action.getWordEnd(textArea, 7)); doc.replace(0, doc.getLength(), "", null); Assert.assertEquals(0, action.getWordEnd(textArea, 0));