/** * default implementation for {@link DefaultTextEditActions#TEXT_START} */ protected void defaultNavigateTextStart() { getControl().setCaretOffset(0); }
@Override public void setCaretOffset(int offset) { viewer.getTextWidget().setCaretOffset(offset); }
void moveCaretAbsolute(int absoluteOffset) { int offset = Math.max(0, absoluteOffset); offset = Math.min(getControl().getCharCount(), offset); getControl().setCaretOffset(offset); }
/** * Set the current selection * * @param selection * the selection */ public void setSelection(@NonNull TextSelection selection) { if (selection.length == 0) { setCaretOffset(selection.offset); } else { // this.caretOffsetProperty.set(selection.offset+selection.length); this.currentSelection.set(selection); } }
/** * Set the current selection * * @param selection * the selection */ public void setSelection(@NonNull TextSelection selection) { if (selection.length == 0) { setCaretOffset(selection.offset); } else { // this.caretOffsetProperty.set(selection.offset+selection.length); this.currentSelection.set(selection); } }
/** * default implementation for {@link DefaultTextEditActions#TEXT_END} */ protected void defaultNavigateTextEnd() { getControl().setCaretOffset(getControl().getContent().getCharCount()); }
/** * navigates to specified line * * @param lineIndex */ public void navigateToLine(int lineIndex) { if (lineIndex >= 0 && lineIndex <= getContent().getLineCount()) { int offset = getContent().getOffsetAtLine(lineIndex); setCaretOffset(offset); } }
/** * Setting the caret offset and updateing the selection if requested * * @param offset * the offset * @param selection * <code>true</code> to update the current selection * @deprecated internal API for now */ @Deprecated public void impl_setCaretOffset(int offset, boolean selection) { if (selection) { caretOffsetProperty().set(offset); if (offset > this.anchor) { setSelectionRange(this.anchor, offset - this.anchor); } else { setSelectionRange(offset, this.anchor - offset); } } else { setCaretOffset(offset); } }
/** * Setting the caret offset and updateing the selection if requested * * @param offset * the offset * @param selection * <code>true</code> to update the current selection * @deprecated internal API for now */ @Deprecated public void impl_setCaretOffset(int offset, boolean selection) { if (selection) { caretOffsetProperty().set(offset); if (offset > this.anchor) { setSelectionRange(this.anchor, offset - this.anchor); } else { setSelectionRange(offset, this.anchor - offset); } } else { setCaretOffset(offset); } }
/** * Cut the current selection into the clipboard */ public void cut() { TextSelection selection = getSelection(); if (selection.length > 0) { final Clipboard clipboard = Clipboard.getSystemClipboard(); String content = getContent().getTextRange(selection.offset, selection.length); setCaretOffset(selection.offset); getContent().replaceTextRange(selection.offset, content.length(), ""); //$NON-NLS-1$ clipboard.setContent(Collections.singletonMap(DataFormat.PLAIN_TEXT, content)); } }
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 */); }
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 */); }
/** * 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$ } }
private void doLink(QuickLink link) { if (link instanceof SimpleQuickLink) { SimpleQuickLink simple = (SimpleQuickLink) link; getControl().setCaretOffset(simple.getRegion().upperEndpoint()); getControl().setSelection(new TextSelection(simple.getRegion().lowerEndpoint(), simple.getRegion().upperEndpoint() - simple.getRegion().lowerEndpoint())); } else if (link instanceof CustomQuickLink) { CustomQuickLink custom = (CustomQuickLink) link; custom.getAction().run(); } }
private void onSourceSelect(SourceSelection data) { if (((URIProvider)input).getURI().equals(data.uri)) { getSourceViewer().getTextWidget().setCaretOffset(data.selection.getOffset() + data.selection.getLength()); getSourceViewer().getTextWidget().setSelection(new TextSelection(data.selection.getOffset(), data.selection.getLength())); getSourceViewer().getTextWidget().revealCaret(); } }
@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); } }
/** * default implementation for {@link DefaultTextEditActions#DELETE_PREVIOUS} */ protected void defaultDeletePrevious() { 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 start = getControl().getCaretOffset() - 1; int del = 1; if (start - 1 >= 0) { if ("\r\n".equals(getControl().getContent().getTextRange(getControl().getCaretOffset()-2, 2))) { //$NON-NLS-1$ start = start - 1; del = 2; } } if( start >= 0 ) { getControl().getContent().replaceTextRange(start, del, ""); //$NON-NLS-1$ getControl().setCaretOffset(offset - del); } } }
private void _keyTyped(KeyEvent event) { if (getControl().getEditable()) { String character = event.getCharacter(); if (character.length() == 0) { return; } // check the modifiers // - OS-X: ALT+L ==> @ // - win32/linux: ALTGR+Q ==> @ if (event.isControlDown() || event.isAltDown() || (Util.isMacOS() && event.isMetaDown())) { if (!((event.isControlDown() || Util.isMacOS()) && event.isAltDown())) return; } if (character.charAt(0) > 31 // No ascii control chars && character.charAt(0) != 127 // no delete key && !event.isMetaDown()) { final int offset = getControl().getCaretOffset(); getControl().getContent().replaceTextRange(getControl().getCaretOffset(), 0, character); getControl().setCaretOffset(offset + 1); } } }
/** * 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); } } }