Search in sources :

Example 1 with NonDeletingPositionUpdater

use of org.eclipse.jface.internal.text.NonDeletingPositionUpdater in project eclipse.platform.text by eclipse.

the class SourceViewer method rememberSelection.

/**
 * Remembers and returns the current selection. The saved selection can be restored
 * by calling <code>restoreSelection()</code>.
 *
 * @return the current selection
 * @see org.eclipse.jface.text.ITextViewer#getSelectedRange()
 * @since 3.0
 */
protected Point rememberSelection() {
    final ITextSelection selection = (ITextSelection) getSelection();
    final IDocument document = getDocument();
    if (fSelections.isEmpty()) {
        fSelectionCategory = _SELECTION_POSITION_CATEGORY + hashCode();
        fSelectionUpdater = new NonDeletingPositionUpdater(fSelectionCategory);
        document.addPositionCategory(fSelectionCategory);
        document.addPositionUpdater(fSelectionUpdater);
    }
    try {
        final Position position;
        if (selection instanceof IBlockTextSelection)
            position = new ColumnPosition(selection.getOffset(), selection.getLength(), ((IBlockTextSelection) selection).getStartColumn(), ((IBlockTextSelection) selection).getEndColumn());
        else
            position = new Position(selection.getOffset(), selection.getLength());
        document.addPosition(fSelectionCategory, position);
        fSelections.push(position);
    } catch (BadLocationException exception) {
    // Should not happen
    } catch (BadPositionCategoryException exception) {
    // Should not happen
    }
    return new Point(selection.getOffset(), selection.getLength());
}
Also used : Position(org.eclipse.jface.text.Position) NonDeletingPositionUpdater(org.eclipse.jface.internal.text.NonDeletingPositionUpdater) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) IBlockTextSelection(org.eclipse.jface.text.IBlockTextSelection) Point(org.eclipse.swt.graphics.Point) ITextSelection(org.eclipse.jface.text.ITextSelection) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

NonDeletingPositionUpdater (org.eclipse.jface.internal.text.NonDeletingPositionUpdater)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)1 IBlockTextSelection (org.eclipse.jface.text.IBlockTextSelection)1 IDocument (org.eclipse.jface.text.IDocument)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 Position (org.eclipse.jface.text.Position)1 Point (org.eclipse.swt.graphics.Point)1