Search in sources :

Example 1 with BlockTextSelection

use of org.eclipse.jface.text.BlockTextSelection in project eclipse.platform.text by eclipse.

the class SourceViewer method restoreSelection.

/**
 * 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
        }
    }
}
Also used : Position(org.eclipse.jface.text.Position) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument) BlockTextSelection(org.eclipse.jface.text.BlockTextSelection) IBlockTextSelection(org.eclipse.jface.text.IBlockTextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

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