Example usage for javax.swing.text Caret getMark

List of usage examples for javax.swing.text Caret getMark

Introduction

In this page you can find the example usage for javax.swing.text Caret getMark.

Prototype

public int getMark();

Source Link

Document

Fetches the current position of the mark.

Usage

From source file:org.domainmath.gui.MainFrame.java

public void deleteText() {
    RSyntaxTextArea textArea = commandArea;
    boolean beep = true;
    if ((textArea != null) && (textArea.isEditable())) {
        try {/*  www  .j ava 2 s  . c  om*/
            Document doc = textArea.getDocument();
            Caret caret = textArea.getCaret();
            int dot = caret.getDot();
            int mark = caret.getMark();
            if (dot != mark) {
                doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
                beep = false;
            } else if (dot < doc.getLength()) {
                int delChars = 1;
                if (dot < doc.getLength() - 1) {
                    String dotChars = doc.getText(dot, 2);
                    char c0 = dotChars.charAt(0);
                    char c1 = dotChars.charAt(1);
                    if (c0 >= '\uD800' && c0 <= '\uDBFF' && c1 >= '\uDC00' && c1 <= '\uDFFF') {
                        delChars = 2;
                    }
                }
                doc.remove(dot, delChars);
                beep = false;
            }
        } catch (Exception bl) {
        }
    }

    if (beep) {
        UIManager.getLookAndFeel().provideErrorFeedback(textArea);
    }

    textArea.requestFocusInWindow();
}