Search in sources :

Example 1 with Position

use of javax.swing.text.Position in project intellij-community by JetBrains.

the class HtmlPanel method getSelectedText.

@Override
public String getSelectedText() {
    Document doc = getDocument();
    int start = getSelectionStart();
    int end = getSelectionEnd();
    try {
        Position p0 = doc.createPosition(start);
        Position p1 = doc.createPosition(end);
        StringWriter sw = new StringWriter(p1.getOffset() - p0.getOffset());
        getEditorKit().write(sw, doc, p0.getOffset(), p1.getOffset() - p0.getOffset());
        return StringUtil.removeHtmlTags(sw.toString());
    } catch (BadLocationException | IOException ignored) {
    }
    return super.getSelectedText();
}
Also used : StringWriter(java.io.StringWriter) Position(javax.swing.text.Position) IOException(java.io.IOException) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 BadLocationException (javax.swing.text.BadLocationException)1 Document (javax.swing.text.Document)1 Position (javax.swing.text.Position)1