@Override TextEdit delete(ISelection selection) throws BadLocationException { if (isEmpty(selection)) { IBlockTextSelection cts= (IBlockTextSelection)selection; selection= new BlockTextSelection(fDocument, cts.getStartLine(), cts.getStartColumn(), cts.getEndLine(), cts.getEndColumn() + 1, fTabWidth); } return replace(selection, "", true); //$NON-NLS-1$ }
/** * Creates a column selection for the given lines and columns. * * @param document the document that this selection refers to * @param startLine the start line * @param startColumn the possibly virtual start column, measured in characters from the start * of <code>startLine</code> * @param endLine the inclusive end line * @param endColumn the exclusive and possibly virtual end column, measured in characters from * the start of <code>endLine</code> * @param tabWidth the tabulator width used to compute the visual offsets from character offsets */ public BlockTextSelection(IDocument document, int startLine, int startColumn, int endLine, int endColumn, int tabWidth) { super(document, computeOffset(document, startLine, startColumn), computeOffset(document, endLine, endColumn) - computeOffset(document, startLine, startColumn)); Assert.isLegal(startLine >= 0); Assert.isLegal(startColumn >= 0); Assert.isLegal(endLine >= startLine); Assert.isLegal(endColumn >= 0); Assert.isLegal(tabWidth >= 0); fStartLine= startLine; fStartColumn= startColumn; fEndLine= endLine; fEndColumn= endColumn; fTabWidth= tabWidth > 0 ? tabWidth : 8; // seems to be the default when StyledText.getTabs returns 0 }
@Override public IRegion[] getRegions() { IDocument document= getDocument(); if (document != null) { try { return new SelectionProcessor(document, fTabWidth).getRanges(this); } catch (BadLocationException x) { // default to single region behavior } } return new IRegion[] {new Region(getOffset(), getLength())}; } }
@Override public String getText() { IDocument document= getDocument(); if (document != null) { try { return new SelectionProcessor(document, fTabWidth).getText(this); } catch (BadLocationException x) { // ignore and default to super implementation } } return super.getText(); }
@Override public String getText() { IDocument document= getDocument(); if (document != null) { try { return new SelectionProcessor(document, fTabWidth).getText(this); } catch (BadLocationException x) { // ignore and default to super implementation } } return super.getText(); }
@Override public IRegion[] getRegions() { IDocument document= getDocument(); if (document != null) { try { return new SelectionProcessor(document, fTabWidth).getRanges(this); } catch (BadLocationException x) { // default to single region behavior } } return new IRegion[] {new Region(getOffset(), getLength())}; } }
@Override ISelection makeReplaceSelection(ISelection selection, String replacement) throws BadLocationException { IBlockTextSelection bts= (IBlockTextSelection)selection; String[] delimiters= fDocument.getLegalLineDelimiters(); int[] index= TextUtilities.indexOf(delimiters, replacement, 0); int length; if (index[0] == -1) length= replacement.length(); else length= index[0]; int startLine= bts.getStartLine(); int column= bts.getStartColumn() + length; int endLine= bts.getEndLine(); int endColumn= computeCharacterColumn(endLine, computeVisualColumn(startLine, column)); return new BlockTextSelection(fDocument, startLine, column, endLine, endColumn, fTabWidth); }
/** * Creates a column selection for the given lines and columns. * * @param document the document that this selection refers to * @param startLine the start line * @param startColumn the possibly virtual start column, measured in characters from the start * of <code>startLine</code> * @param endLine the inclusive end line * @param endColumn the exclusive and possibly virtual end column, measured in characters from * the start of <code>endLine</code> * @param tabWidth the tabulator width used to compute the visual offsets from character offsets */ public BlockTextSelection(IDocument document, int startLine, int startColumn, int endLine, int endColumn, int tabWidth) { super(document, computeOffset(document, startLine, startColumn), computeOffset(document, endLine, endColumn) - computeOffset(document, startLine, startColumn)); Assert.isLegal(startLine >= 0); Assert.isLegal(startColumn >= 0); Assert.isLegal(endLine >= startLine); Assert.isLegal(endColumn >= 0); Assert.isLegal(tabWidth >= 0); fStartLine= startLine; fStartColumn= startColumn; fEndLine= endLine; fEndColumn= endColumn; fTabWidth= tabWidth > 0 ? tabWidth : 8; // seems to be the default when StyledText.getTabs returns 0 }
@Override ISelection makeReplaceSelection(ISelection selection, String replacement) throws BadLocationException { IBlockTextSelection bts= (IBlockTextSelection)selection; String[] delimiters= fDocument.getLegalLineDelimiters(); int[] index= TextUtilities.indexOf(delimiters, replacement, 0); int length; if (index[0] == -1) length= replacement.length(); else length= index[0]; int startLine= bts.getStartLine(); int column= bts.getStartColumn() + length; int endLine= bts.getEndLine(); int endColumn= computeCharacterColumn(endLine, computeVisualColumn(startLine, column)); return new BlockTextSelection(fDocument, startLine, column, endLine, endColumn, fTabWidth); }
@Override TextEdit delete(ISelection selection) throws BadLocationException { if (isEmpty(selection)) { IBlockTextSelection cts= (IBlockTextSelection)selection; selection= new BlockTextSelection(fDocument, cts.getStartLine(), cts.getStartColumn(), cts.getEndLine(), cts.getEndColumn() + 1, fTabWidth); } return replace(selection, "", true); //$NON-NLS-1$ }
@Override TextEdit backspace(ISelection selection) throws BadLocationException { IBlockTextSelection cts= (IBlockTextSelection)selection; if (isEmpty(selection) && cts.getStartColumn() > 0) { selection= new BlockTextSelection(fDocument, cts.getStartLine(), cts.getStartColumn() - 1, cts.getEndLine(), cts.getEndColumn(), fTabWidth); } return replace(selection, ""); //$NON-NLS-1$ }
@Override TextEdit backspace(ISelection selection) throws BadLocationException { IBlockTextSelection cts= (IBlockTextSelection)selection; if (isEmpty(selection) && cts.getStartColumn() > 0) { selection= new BlockTextSelection(fDocument, cts.getStartLine(), cts.getStartColumn() - 1, cts.getEndLine(), cts.getEndColumn(), fTabWidth); } return replace(selection, ""); //$NON-NLS-1$ }
@Override ISelection makeEmpty(ISelection selection, boolean beginning) throws BadLocationException { IBlockTextSelection cts= (IBlockTextSelection)selection; int startLine, startColumn, endLine, endColumn; if (beginning) { startLine= cts.getStartLine(); startColumn= cts.getStartColumn(); endLine= cts.getEndLine(); endColumn= computeCharacterColumn(endLine, computeVisualColumn(startLine, startColumn)); } else { endLine= cts.getEndLine(); endColumn= cts.getEndColumn(); startLine= cts.getStartLine(); startColumn= computeCharacterColumn(startLine, computeVisualColumn(endLine, endColumn)); } return new BlockTextSelection(fDocument, startLine, startColumn, endLine, endColumn, fTabWidth); }
@Override ISelection makeEmpty(ISelection selection, boolean beginning) throws BadLocationException { IBlockTextSelection cts= (IBlockTextSelection)selection; int startLine, startColumn, endLine, endColumn; if (beginning) { startLine= cts.getStartLine(); startColumn= cts.getStartColumn(); endLine= cts.getEndLine(); endColumn= computeCharacterColumn(endLine, computeVisualColumn(startLine, startColumn)); } else { endLine= cts.getEndLine(); endColumn= cts.getEndColumn(); startLine= cts.getStartLine(); startColumn= computeCharacterColumn(startLine, computeVisualColumn(endLine, endColumn)); } return new BlockTextSelection(fDocument, startLine, startColumn, endLine, endColumn, fTabWidth); }
/** * Restores a previously saved selection in the document. * <p> * If no selection was previously saved, nothing happens. * * @since 3.0 */ protected void restoreSelection() { if (!fSelections.isEmpty()) { final IDocument document= getDocument(); final Position position= fSelections.pop(); try { document.removePosition(fSelectionCategory, position); Point currentSelection= getSelectedRange(); if (currentSelection == null || currentSelection.x != position.getOffset() || currentSelection.y != position.getLength()) { if (position instanceof ColumnPosition && getTextWidget().getBlockSelection()) { setSelection(new BlockTextSelection(document, document.getLineOfOffset(position.getOffset()), ((ColumnPosition) position).fStartColumn, document.getLineOfOffset(position.getOffset() + position.getLength()), ((ColumnPosition) position).fEndColumn, getTextWidget().getTabs())); } else { setSelectedRange(position.getOffset(), position.getLength()); } } if (fSelections.isEmpty()) clearRememberedSelection(); } catch (BadPositionCategoryException exception) { // Should not happen } catch (BadLocationException x) { // Should not happen } } }
/** * Restores a previously saved selection in the document. * <p> * If no selection was previously saved, nothing happens. * * @since 3.0 */ protected void restoreSelection() { if (!fSelections.isEmpty()) { final IDocument document= getDocument(); final Position position= fSelections.pop(); try { document.removePosition(fSelectionCategory, position); Point currentSelection= getSelectedRange(); if (currentSelection == null || currentSelection.x != position.getOffset() || currentSelection.y != position.getLength()) { if (position instanceof ColumnPosition && getTextWidget().getBlockSelection()) { setSelection(new BlockTextSelection(document, document.getLineOfOffset(position.getOffset()), ((ColumnPosition) position).fStartColumn, document.getLineOfOffset(position.getOffset() + position.getLength()), ((ColumnPosition) position).fEndColumn, getTextWidget().getTabs())); } else { setSelectedRange(position.getOffset(), position.getLength()); } } if (fSelections.isEmpty()) clearRememberedSelection(); } catch (BadPositionCategoryException exception) { // Should not happen } catch (BadLocationException x) { // Should not happen } } }
if (startLine == -1 || endLine == -1) return TextSelection.emptySelection(); return new BlockTextSelection(document, startLine, startColumn, endLine, endColumn, fTextWidget.getTabs()); } catch (BadLocationException e) { return TextSelection.emptySelection();
if (startLine == -1 || endLine == -1) return TextSelection.emptySelection(); return new BlockTextSelection(document, startLine, startColumn, endLine, endColumn, fTextWidget.getTabs()); } catch (BadLocationException e) { return TextSelection.emptySelection();
int startColumn= fSelection.getOffset() - startLineOffset + cp.fStartColumn; int endColumn= selectionEnd - endLineOffset + cp.fEndColumn; setSelection(new BlockTextSelection(document, startLine, startColumn, endLine, endColumn, tabs)); } catch (BadLocationException e) {
int startColumn= fSelection.getOffset() - startLineOffset + cp.fStartColumn; int endColumn= selectionEnd - endLineOffset + cp.fEndColumn; setSelection(new BlockTextSelection(document, startLine, startColumn, endLine, endColumn, tabs)); } catch (BadLocationException e) {