@Override public default int length() { return getCharCount(); }
/** * @return the current char count */ public int getCharCount() { return getContent().getCharCount(); }
/** * @return the current char count */ public int getCharCount() { return getContent().getCharCount(); }
private double computeLongestLine() { if( this.cachedLongestLine != 0.0 ) { if( this.lastContentLength == getContent().getCharCount() ) { return Math.max(this.cachedLongestLine,getWidth()); } } OptionalInt longestLine = IntStream.range(0, getNumberOfLines()) .map( index -> this.lineHelper.getLengthCountTabsAsChars(index)) .max(); if( longestLine.isPresent() ) { int lineLength = longestLine.getAsInt() + 2; this.cachedLongestLine = lineLength * getCharWidth(); this.lastContentLength = getContent().getCharCount(); return Math.max(getWidth(), this.cachedLongestLine); } else { this.cachedLongestLine = 0.0; } return getWidth(); }
/** * default implementation for {@link DefaultTextEditActions#TEXT_END} */ protected void defaultNavigateTextEnd() { getControl().setCaretOffset(getControl().getContent().getCharCount()); }
/** * default implementation for {@link DefaultTextEditActions#SELECT_ALL} */ protected void defaultSelectAll() { int length = getControl().getContent().getCharCount(); getControl().setSelectionRange(0, length); }
/** * Find the offset at a specific position * * @param x * the x coordinate * @param y * the y coordinate * @return the offset */ public int getOffsetAtPosition(double x, double y) { if (this.content.getBoundsInLocal().getMinY() <= y && this.content.getBoundsInLocal().getMaxY() >= y) { return this.content.getLineIndex(new Point2D(x, y)).orElse(Integer.valueOf(getSkinnable().getContent().getCharCount())).intValue(); } else { return -1; } }
void setStyleRanges(int start, int length, int[] ranges, StyleRange[] styles, boolean reset) { int charCount = getContent().getCharCount(); int end = start + length; if (start > end || start < 0) {
void handleTextChanging(TextChangingEvent event) { this.changingEvent = event; this.renderer.textChanging(event); if (event.replaceCharCount < 0) { event.offset += event.replaceCharCount; event.replaceCharCount *= -1; } // this.lastTextChangeStart = event.offset; // this.lastTextChangeNewLineCount = event.newLineCount; this.lastTextChangeNewCharCount = event.newCharCount; // this.lastTextChangeReplaceLineCount = event.replaceLineCount; this.lastTextChangeReplaceCharCount = event.replaceCharCount; // Update the caret offset if it is greater than the length of the // content. // This is necessary since style range API may be called between the // handleTextChanging and handleTextChanged events and this API sets the // caretOffset. int newEndOfText = getContent().getCharCount() - event.replaceCharCount + event.newCharCount; if (getCaretOffset() > newEndOfText) setCaretOffset(newEndOfText/* , SWT.DEFAULT */); }
void setStyleRanges(int start, int length, int[] ranges, StyleRange[] styles, boolean reset) { int charCount = getContent().getCharCount(); int end = start + length; if (start > end || start < 0) {
void handleTextChanging(TextChangingEvent event) { if (event.replaceCharCount < 0) { event.offset += event.replaceCharCount; event.replaceCharCount *= -1; } this.lastTextChangeStart = event.offset; // this.lastTextChangeNewLineCount = event.newLineCount; this.lastTextChangeNewCharCount = event.newCharCount; // this.lastTextChangeReplaceLineCount = event.replaceLineCount; this.lastTextChangeReplaceCharCount = event.replaceCharCount; this.renderer.textChanging(event); // Update the caret offset if it is greater than the length of the // content. // This is necessary since style range API may be called between the // handleTextChanging and handleTextChanged events and this API sets the // caretOffset. int newEndOfText = getContent().getCharCount() - event.replaceCharCount + event.newCharCount; if (getCaretOffset() > newEndOfText) setCaretOffset(newEndOfText/* , SWT.DEFAULT */); }
@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); } }
private void onTextPositionPressed(TextPositionEvent event) { if( event.getButton() != MouseButton.PRIMARY ) { return; } this.mousePressedOffset = event.getOffset(); if( this.mousePressedOffset < 0 ) { this.mousePressedOffset = getControl().getContent().getCharCount(); } if (isInSelection(this.mousePressedOffset)) { this.pressedInSelection = true; event.consume(); } else { moveCaretAbsolute(this.mousePressedOffset, event.isShiftDown()); event.consume(); } }
/** * default implementation for {@link DefaultTextEditActions#DELETE} */ protected void defaultDelete() { int offset = getControl().getCaretOffset(); TextSelection selection = getControl().getSelection(); if (selection.length > 0) { getControl().getContent().replaceTextRange(selection.offset, selection.length, ""); //$NON-NLS-1$ getControl().setCaretOffset(selection.offset); } else { int del = 1; if (getControl().getCaretOffset() + 2 <= getControl().getContent().getCharCount()) { if ("\r\n".equals(getControl().getContent().getTextRange(getControl().getCaretOffset(), 2))) { //$NON-NLS-1$ del = 2; } } if (getControl().getCaretOffset() + del <= getControl().getContent().getCharCount()) { getControl().getContent().replaceTextRange(getControl().getCaretOffset(), del, ""); //$NON-NLS-1$ getControl().setCaretOffset(offset); } } }
event.consume(); } else { if (offset + 1 > getControl().getContent().getCharCount()) { break;