@Override public void run() { SelectionProcessor processor= new SelectionProcessor(TextViewer.this); try { /* Use the selection instead of the event's coordinates. Is this dangerous? */ ISelection selection= getSelection(); int length= e.text.length(); if (length == 0 && e.character == '\0') { // backspace in StyledText block selection mode... TextEdit edit= processor.backspace(selection); edit.apply(fDocument, TextEdit.UPDATE_REGIONS); ISelection empty= processor.makeEmpty(selection, true); setSelection(empty); } else { int lines= processor.getCoveredLines(selection); String delim= fDocument.getLegalLineDelimiters()[0]; StringBuffer text= new StringBuffer(lines * length + (lines - 1) * delim.length()); text.append(e.text); for (int i= 0; i < lines - 1; i++) { text.append(delim); text.append(e.text); } processor.doReplace(selection, text.toString()); } } catch (BadLocationException x) { if (TRACE_ERRORS) System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.verifyText")); //$NON-NLS-1$ } } });
ISelection empty= processor.makeEmpty(selection, true); setSelection(empty); } else {
/** * Convenience method that applies the edit returned from {@link #delete(ISelection)} to the * underlying document. * * @param selection the selection to delete * @throws BadLocationException if accessing the document failed */ public void doDelete(ISelection selection) throws BadLocationException { TextEdit edit= delete(selection); boolean complex= edit.hasChildren(); if (complex && fRewriteTarget != null) fRewriteTarget.beginCompoundChange(); try { edit.apply(fDocument, TextEdit.UPDATE_REGIONS); if (fSelectionProvider != null) { ISelection empty= makeEmpty(selection, true); fSelectionProvider.setSelection(empty); } } finally { if (complex && fRewriteTarget != null) fRewriteTarget.endCompoundChange(); } }
/** * Convenience method that applies the edit returned from {@link #delete(ISelection)} to the * underlying document. * * @param selection the selection to delete * @throws BadLocationException if accessing the document failed */ public void doDelete(ISelection selection) throws BadLocationException { TextEdit edit= delete(selection); boolean complex= edit.hasChildren(); if (complex && fRewriteTarget != null) fRewriteTarget.beginCompoundChange(); try { edit.apply(fDocument, TextEdit.UPDATE_REGIONS); if (fSelectionProvider != null) { ISelection empty= makeEmpty(selection, true); fSelectionProvider.setSelection(empty); } } finally { if (complex && fRewriteTarget != null) fRewriteTarget.endCompoundChange(); } }