public void replace(@NonNull String replacement) { getControl().getContent().replaceTextRange(this.start, this.length, replacement); }
/** * 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)); } }
/** * 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)); } }
/** * 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); } } }
/** * inserts text at the caret location or replaces a given selection * * @param text */ @SuppressWarnings("null") public void insert(CharSequence text) { if (text == null) throw new NullPointerException(); int start, replaceLength; if (!isSelectionEmpty()) { // replace selection start = this.getSelection().offset; replaceLength = this.getSelection().length; } else { // insert at caret start = this.getCaretOffset(); replaceLength = 0; } String content = text.toString(); if( isInsertSpacesForTab() ) { content = content.replaceAll("\t", Util.createRepeatedString(' ', this.tabAdvance.get())); //$NON-NLS-1$ } this.getContent().replaceTextRange(start, replaceLength, content); this.setCaretOffset(start + content.length()); }
/** * 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$ } }
/** * 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); } } }
getControl().getContent().replaceTextRange(start, replacedText.length(), newText); getControl().setCaretOffset(selectionOffset == caret ? caret - firstLineDelta : caret - removed); getControl().setSelectionRange(selectionOffset - firstLineDelta, selectionLength - removed + firstLineDelta);
/** * default implementation for {@link DefaultTextEditActions#NEW_LINE} */ protected void defaultNewLine() { int offset = getControl().getCaretOffset(); int line = getControl().getContent().getLineAtOffset(offset); int lineOffset = offset - getControl().getContent().getOffsetAtLine(line); String lineContent = getControl().getContent().getLine(line); // Should we make this configurable char[] chars = lineContent.toCharArray(); String prefix = ""; //$NON-NLS-1$ for (int i = 0; i < Math.min(lineOffset, chars.length); i++) { if (chars[i] == ' ' || chars[i] == '\t') { prefix += chars[i]; } else { break; } } if (getControl().getSelection().length > 0) { int caretPos = getControl().getSelection().offset + getControl().getLineSeparator().getValue().length() + prefix.length(); getControl().getContent().replaceTextRange(getControl().getSelection().offset, getControl().getSelection().length, getControl().getLineSeparator().getValue() + prefix); getControl().setCaretOffset( caretPos ); } else { getControl().getContent().replaceTextRange(getControl().getCaretOffset(), 0, getControl().getLineSeparator().getValue() + prefix); getControl().setCaretOffset(offset + getControl().getLineSeparator().getValue().length() + prefix.length()); } }
String replaced = dataBuffer.substring(start,start+length); getControl().getContent().replaceTextRange(start, length-added, replaced); getControl().setCaretOffset(selectionOffset == caret ? caret + indentLength : caret + added); getControl().setSelectionRange(selectionOffset + indentLength, selectionLength + added - indentLength);
/** * 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); } } }
getControl().getContent().replaceTextRange(this.dragMoveTextOffset, this.dragMoveTextLength, ""); //$NON-NLS-1$ getControl().getContent().replaceTextRange(targetOffset, 0, text);
Optional<Integer> lineIndex = content.getLineIndex(coords); if (lineIndex.isPresent() && lineIndex.get() != -1) { getSkinnable().getContent().replaceTextRange(lineIndex.get(), 0, insert); getSkinnable().setCaretOffset(lineIndex.get() + insert.length()); getSkinnable().setSelection(new TextSelection(lineIndex.get(), insert.length()));
getControl().getContent().replaceTextRange(getControl().getCaretOffset(), 0, newLine + prefix); invokeAction(ActionType.DELETE_WORD_NEXT); } else { getControl().getContent().replaceTextRange(getControl().getCaretOffset(), 1, ""); //$NON-NLS-1$ getControl().setCaretOffset(offset); TextSelection selection = getControl().getSelection(); if (selection.length > 0) { getControl().getContent().replaceTextRange(selection.offset, selection.length, ""); //$NON-NLS-1$ getControl().setCaretOffset(selection.offset); } else { getControl().getContent().replaceTextRange(getControl().getCaretOffset() - 1, 1, ""); //$NON-NLS-1$ getControl().setCaretOffset(offset - 1); getControl().getContent().replaceTextRange(getControl().getCaretOffset(), 0, "\t"); //$NON-NLS-1$ getControl().setCaretOffset(offset + 1); break;