/** * Get the initial offset of the line * * @param lineNumber * the line number * @return the offset */ public int getOffsetAtLine(int lineNumber) { return getContent().getOffsetAtLine(lineNumber); }
/** * Get the line index for the caret * * @param caretOffset * the caret offset * @return the line index */ public int getLineAtOffset(int caretOffset) { return getContent().getLineAtOffset(caretOffset); }
/** * Get the line index for the caret * * @param caretOffset * the caret offset * @return the line index */ public int getLineAtOffset(int caretOffset) { return getContent().getLineAtOffset(caretOffset); }
/** * navigates to specified line * * @param lineIndex */ public void navigateToLine(int lineIndex) { if (lineIndex >= 0 && lineIndex <= getContent().getLineCount()) { int offset = getContent().getOffsetAtLine(lineIndex); setCaretOffset(offset); } }
/** * Get the text for the given range * * @param start * the start * @param end * the end * @return the text */ public @NonNull String getText(int start, int end) { return getContent().getTextRange(start, end - start + 1); }
/** * Get the text for the given range * * @param start * the start * @param end * the end * @return the text */ public @NonNull String getText(int start, int end) { return getContent().getTextRange(start, end - start + 1); }
public LineRegion(int firstLine, int lastLine) { super(computeStart(getControl().getContent(), firstLine), computeLength(getControl().getContent(), firstLine, lastLine)); this.firstLine = firstLine; this.lastLine = lastLine; }
/** * default implementation for {@link DefaultTextEditActions#LINE_END} */ protected void defaultNavigateLineEnd() { final int caretLine = computeCurrentLineNumber(); moveCaretAbsolute(getControl().getContent().getOffsetAtLine(caretLine) + getControl().getContent().getLine(caretLine).length()); }
/** * 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; }
/** * Cut the current selection into the clipboard */ public void cut() { if( getSelection().length > 0 ) { final Clipboard clipboard = Clipboard.getSystemClipboard(); String content = getContent().getTextRange(getSelection().offset, getSelection().length); getContent().replaceTextRange(getSelection().offset, content.length(), ""); //$NON-NLS-1$ clipboard.setContent(Collections.singletonMap(DataFormat.PLAIN_TEXT, content)); } }
/** * @return the line offset */ public int getLineOffset() { int idx = StyledTextSkin.this.lineList.indexOf(this); return getSkinnable().getContent().getOffsetAtLine(idx); }
/** * default implementation for {@link DefaultTextEditActions#TEXT_END} */ protected void defaultNavigateTextEnd() { getControl().setCaretOffset(getControl().getContent().getCharCount()); }
/** * 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$ } }
/** * 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$ } }
/** * @return the current text */ @Override public String getText() { return removeLineending(getSkinnable().getContent().getLine(StyledTextSkin.this.lineList.indexOf(this))); }
/** * Copy the current selection into the clipboard */ @SuppressWarnings("null") public void copy() { if (getSelection().length > 0) { final Clipboard clipboard = Clipboard.getSystemClipboard(); clipboard.setContent(Collections.singletonMap(DataFormat.PLAIN_TEXT, getContent().getTextRange(getSelection().offset, getSelection().length))); } }
/** * Copy the current selection into the clipboard */ @SuppressWarnings("null") public void copy() { if (getSelection().length > 0) { final Clipboard clipboard = Clipboard.getSystemClipboard(); clipboard.setContent(Collections.singletonMap(DataFormat.PLAIN_TEXT, getContent().getTextRange(getSelection().offset, getSelection().length))); } }
/** * 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); } }