Example usage for com.google.gwt.user.client.ui TextArea getSelectionLength

List of usage examples for com.google.gwt.user.client.ui TextArea getSelectionLength

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui TextArea getSelectionLength.

Prototype

@Override
    public int getSelectionLength() 

Source Link

Usage

From source file:ch.heftix.mailxel.client.OrgTextArea.java

License:Open Source License

public OrgTextArea() {

    KeyboardListener kl = new KeyboardListener() {

        Duration sinceEscapePressed = null;

        public void onKeyDown(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KeyboardListener.KEY_ESCAPE) {
                sinceEscapePressed = new Duration();
            }/* w  w w .j a  v  a2 s. c o  m*/
        }

        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
        }

        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            if ('q' == keyCode) {
                // System.out.println(sinceEscapePressed.elapsedMillis());
                if (null != sinceEscapePressed && (sinceEscapePressed.elapsedMillis() < 300)) {
                    // format region
                    TextArea ta = (TextArea) sender;
                    String text = ta.getText();
                    int pos = ta.getCursorPos();
                    int len = ta.getSelectionLength();
                    String replacement = om.prefixSelection(text, "> ", pos, len);
                    ta.setText(replacement);
                    cancelKey();
                }
            }
        }

    };

    addKeyboardListener(kl);

}

From source file:us.softoption.infrastructure.TGWTUtilities.java

License:Open Source License

static public void writeOverJournalSelection(TextArea journal, String message) {

    int current = journal.getCursorPos(); //if there isn't one it's dot which is the old one

    int selLength = journal.getSelectionLength();

    int messageLength = message.length();

    String text = journal.getText();

    text = text.substring(0, current) + message + text.substring(current + selLength);

    journal.setText(text);/*from w w w  .j  ava 2 s .  c om*/

    journal.setCursorPos(current + messageLength);
    journal.setSelectionRange(current + messageLength, 0);
    journal.setFocus(true);

}

From source file:us.softoption.infrastructure.TGWTUtilities.java

License:Open Source License

static public void writeToJournal(TextArea journal, String message, boolean highlight) {

    int oldCaretPos = journal.getCursorPos();

    int oldSelLength = journal.getSelectionLength();

    int newCaretPos = oldCaretPos + oldSelLength;

    int messageLength = message.length();

    String text = journal.getText();
    String before = text.substring(0, oldCaretPos);
    String after = text.substring(oldCaretPos + oldSelLength);

    text = before + message + after; // we con't want to include the original selection

    journal.setText(text);/*from  w w  w . j a v  a 2  s. c om*/

    if (messageLength > 0) {

        // before aaa<sel>bbb
        // after aaa<new>Ibbb or
        // after aaa<new>bbb with new selected

        // journal.setSelectionRange(newCaretPos,messageLength); new Nov 11
        // journal.setSelectionRange(newCaretPos,0);
        // journal.setCursorPos(newCaretPos);    //leave existing selection and do everything after;

        if (highlight) {
            newCaretPos = oldCaretPos;
            journal.setCursorPos(newCaretPos);
            journal.setSelectionRange(newCaretPos, messageLength);
            journal.setFocus(true);
        } else {
            newCaretPos = oldCaretPos + messageLength;
            journal.setCursorPos(newCaretPos);
            journal.setSelectionRange(newCaretPos, 0);
        }
    }
}