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());
}
Aggregations