/** Apply style when the selection is inside a text node. */ private void doTestStyleWhenSelectionIsInsideText() { String text = "123"; rta.setHTML(text); Range range = ((Document) rta.getDocument()).createRange(); range.setStart(getBody().getFirstChild(), 1); range.setEnd(getBody().getFirstChild(), 2); select(range); assertFalse(executable.isExecuted()); assertTrue(executable.execute(null)); assertTrue(executable.isExecuted()); assertEquals("1<em>2</em>3", rta.getHTML().toLowerCase()); assertTrue(executable.execute(null)); assertFalse(executable.isExecuted()); assertEquals(text, rta.getHTML().toLowerCase()); }
/** Apply style when the caret is at the beginning of a text node. */ private void doTestStyleWhenCaretIsBeforeText() { rta.setHTML("d"); Range range = ((Document) rta.getDocument()).createRange(); range.setStart(getBody().getFirstChild(), 0); range.collapse(true); select(range); assertFalse(executable.isExecuted()); assertTrue(executable.execute(null)); assertTrue(executable.isExecuted()); assertTrue(executable.execute(null)); assertFalse(executable.isExecuted()); insertHTML("c"); assertFalse(executable.isExecuted()); assertEquals("cd", rta.getHTML().toLowerCase()); }
/** Apply style when the caret is before an image. */ private void doTestStyleWhenCaretIsBeforeImage() { rta.setHTML("<img/>*"); Range range = ((Document) rta.getDocument()).createRange(); range.setStartBefore(getBody().getFirstChild()); range.collapse(true); select(range); assertFalse(executable.isExecuted()); assertTrue(executable.execute(null)); assertTrue(executable.isExecuted()); insertHTML("y"); assertTrue(executable.isExecuted()); assertEquals("<em>y</em><img>*", rta.getHTML().toLowerCase()); assertTrue(executable.execute(null)); assertFalse(executable.isExecuted()); assertEquals("<em></em>y<em></em><img>*", rta.getHTML().toLowerCase()); }
/** Apply style when the selection spans two paragraphs. */ private void doTestStyleCrossParagraphSelection() { String html = "<p>abc</p><p>xyz</p>"; rta.setHTML(html); Range range = ((Document) rta.getDocument()).createRange(); range.setStart(getBody().getFirstChild().getFirstChild(), 2); range.setEnd(getBody().getLastChild().getFirstChild(), 2); select(range); String selectedText = "cxy"; assertEquals(selectedText, rta.getDocument().getSelection().toString()); assertFalse(executable.isExecuted()); assertTrue(executable.execute(null)); assertTrue(executable.isExecuted()); assertEquals(selectedText, rta.getDocument().getSelection().toString()); assertTrue(executable.execute(null)); assertFalse(executable.isExecuted()); assertEquals(selectedText, rta.getDocument().getSelection().toString()); assertEquals(html, clean(rta.getHTML())); }
/** Apply style when the caret is after an image. */ private void doTestStyleWhenCaretIsAfterImage() { // NOTE: In IE8 with the document rendered in standards mode we can't place the caret after an // image if it's the // last child of its parent.. rta.setHTML("#<img/><em>$</em>"); Range range = ((Document) rta.getDocument()).createRange(); range.setStartAfter(getBody().getChildNodes().getItem(1)); range.collapse(true); select(range); assertFalse(executable.isExecuted()); assertTrue(executable.execute(null)); assertTrue(executable.isExecuted()); assertTrue(executable.execute(null)); assertFalse(executable.isExecuted()); insertHTML("x"); assertFalse(executable.isExecuted()); assertEquals("#<img>x<em>$</em>", rta.getHTML().toLowerCase()); }