@Override public int getCaretOffset() { return viewer.getTextWidget().getCaretOffset(); } });
/** * Update the caret */ public void updateCaret() { int caretPosition = getSkinnable().getCaretOffset(); if (caretPosition < 0) { return; } }
private void moveCaretRelative(int deltaOffset, boolean select) { int offset = getControl().getCaretOffset() + deltaOffset; moveCaretAbsolute(offset, select); }
/** * Reveal the current caret location * @since 2.4.0 */ public void revealCaret() { if (getSkin() != null) { ((StyledTextSkin)getSkin()).scrollOffsetIntoView(getCaretOffset(), 2, 2); } }
/** * @return the current selection */ public @NonNull TextSelection getSelection() { TextSelection textSelection = this.currentSelection.get(); if (textSelection == null) { textSelection = new TextSelection(getCaretOffset(), 0); } return textSelection; }
/** * @return the current selection */ public @NonNull TextSelection getSelection() { TextSelection textSelection = this.currentSelection.get(); if (textSelection == null) { textSelection = new TextSelection(getCaretOffset(), 0); } return textSelection; }
private int computeCurrentLineNumber() { final int offset = getControl().getCaretOffset(); return getControl().getLineAtOffset(offset); }
/** * default implementation for {@link DefaultTextEditActions#DELETE_WORD_NEXT} */ protected void defaultDeleteWordNext() { int offset = getControl().getCaretOffset(); int following = TextUtil.findWordEndOffset( getControl().getContent(), offset, true); if (following != BreakIterator.DONE) { getControl().getContent().replaceTextRange(getControl().getCaretOffset(), following - offset, ""); //$NON-NLS-1$ } }
/** * default implementation for {@link DefaultTextEditActions#SELECT_WORD_NEXT} */ protected void defaultSelectWordNext() { int following = TextUtil.findWordEndOffset( getControl().getContent(), getControl().getCaretOffset(), true); if (following != BreakIterator.DONE) { moveCaretAbsolute(following, true); } }
/** * default implementation for {@link DefaultTextEditActions#SELECT_WORD_PREVIOUS} */ protected void defaultSelectWordPrevious() { int previous = TextUtil.findWordStartOffset( getControl().getContent(), getControl().getCaretOffset(), true); if (previous != BreakIterator.DONE) { moveCaretAbsolute(previous, true); } }
/** * default implementation for {@link DefaultTextEditActions#WORD_NEXT} */ protected void defaultNavigateWordNext() { int following = TextUtil.findWordEndOffset(getControl().getContent(), getControl().getCaretOffset(), true); if (following != BreakIterator.DONE) { moveCaretAbsolute(following); } }
/** * default implementation for {@link DefaultTextEditActions#WORD_PREVIOUS} */ protected void defaultNavigateWordPrevious() { int previous = TextUtil.findWordStartOffset(getControl().getContent(), getControl().getCaretOffset(), true); if (previous != BreakIterator.DONE) { moveCaretAbsolute(previous); } }
/** * Paste the clipboard content */ public void paste() { final Clipboard clipboard = Clipboard.getSystemClipboard(); if (clipboard.hasString()) { final String text = clipboard.getString(); if (text != null) { // TODO Once we have a real selection we need getContent().replaceTextRange(getCaretOffset(), 0, text); } } }
/** * default implementation for {@link DefaultTextEditActions#SELECT_WORD} */ protected void defaultSelectWord() { IntTuple bounds = TextUtil.findWordBounds(getControl().getContent(), getControl().getCaretOffset(), true); int previous = bounds.value1; int next = bounds.value2; if (previous != BreakIterator.DONE && next != BreakIterator.DONE) { moveCaretAbsolute(previous); moveCaretAbsolute(next, true); } }
private int calculatePageUpOffset() { final int linesPerPage = ((StyledTextSkin)getControl().getSkin()).getVisibleLineCount(); final int globalOffset = getControl().getCaretOffset(); final int lineIndex = getControl().getContent().getLineAtOffset(globalOffset); final int lineLocalOffset = globalOffset - getControl().getContent().getOffsetAtLine(lineIndex); final int newLineIndex = Math.max(0, lineIndex - linesPerPage); final int newLineLocalOffset = Math.min(getControl().getContent().getLine(newLineIndex).length(), lineLocalOffset); return getControl().getOffsetAtLine(newLineIndex) + newLineLocalOffset; }
/** * default implementation for {@link DefaultTextEditActions#LINE_END} */ protected void defaultSelectLineEnd() { int caretLine = getControl().getContent().getLineAtOffset(getControl().getCaretOffset()); int end = getControl().getContent().getOffsetAtLine(caretLine) + getControl().getContent().getLine(caretLine).length(); moveCaretAbsolute(end, true); }
private int calculatePageDownOffset() { final int linesPerPage = ((StyledTextSkin)getControl().getSkin()).getVisibleLineCount(); final int globalOffset = getControl().getCaretOffset(); final int lineIndex = getControl().getContent().getLineAtOffset(globalOffset); final int lineLocalOffset = globalOffset - getControl().getContent().getOffsetAtLine(lineIndex); final int newLineIndex = Math.min(getControl().getContent().getLineCount()-1, lineIndex + linesPerPage); final int newLineLocalOffset = Math.min(getControl().getContent().getLine(newLineIndex).length(), lineLocalOffset); return getControl().getOffsetAtLine(newLineIndex) + newLineLocalOffset; }
/** * default implementation for {@link DefaultTextEditActions#DELETE_WORD_PREVIOUS} */ protected void defaultDeleteWordPrevious() { int offset = getControl().getCaretOffset(); int previous = TextUtil.findWordStartOffset(getControl().getContent(), offset, true); if (previous != BreakIterator.DONE) { getControl().setCaretOffset(previous); getControl().getContent().replaceTextRange(previous, offset - previous, ""); //$NON-NLS-1$ } }
@Focus void focused() { if( activeInput != null ) { activeInput.setValue(input); } viewer.getTextWidget().requestFocus(); //TODO We should remember the caret offset if( viewer.getTextWidget().getCaretOffset() == -1 && viewer.getTextWidget().getContent().getCharCount() > 0 ) { viewer.getTextWidget().setCaretOffset(0); } }
@Focus void focused() { if( activeInput != null ) { activeInput.setValue(input); } viewer.getTextWidget().requestFocus(); //TODO We should remember the caret offset if( viewer.getTextWidget().getCaretOffset() == -1 && viewer.getTextWidget().getContent().getCharCount() > 0 ) { viewer.getTextWidget().setCaretOffset(0); } }