Package org.eclipse.jface.text
Class TextSelection
java.lang.Object
org.eclipse.jface.text.TextSelection
- All Implemented Interfaces:
IMultiTextSelection
,ITextSelection
,ISelection
- Direct Known Subclasses:
BlockTextSelection
Standard implementation of
ITextSelection
.
Takes advantage of the weak contract of correctness of its interface. If generated from a selection provider, it only remembers its offset and length and computes the remaining information on request.
-
Constructor Summary
ConstructorDescriptionTextSelection
(int offset, int length) Creates a text selection for the given range.TextSelection
(IDocument document, int offset, int length) Creates a text selection for the given range of the given document. -
Method Summary
Modifier and TypeMethodDescriptionstatic ITextSelection
Returns the shared instance of the empty text selection.boolean
protected IDocument
Returns the document underlying the receiver, possiblynull
.int
Returns the number of the line containing the last character of the selected text.int
Returns the length of the selected text.int
Returns the offset of the selected text.IRegion[]
Returns a non-empty array containing the selected text range for each line covered by the selection.int
Returns number of the line containing the offset of the selected text.getText()
Returns the selected text.int
hashCode()
boolean
isEmpty()
Tells whether this text selection is the empty selection.toString()
-
Constructor Details
-
TextSelection
public TextSelection(int offset, int length) Creates a text selection for the given range. This selection object describes generically a text range and is intended to be an argument for thesetSelection
method of selection providers.- Parameters:
offset
- the offset of the range, must not be negativelength
- the length of the range, must not be negative
-
TextSelection
Creates a text selection for the given range of the given document. This selection object is created by selection providers in respondsgetSelection
.- Parameters:
document
- the document whose text range is selected in a vieweroffset
- the offset of the selected range, must not be negativelength
- the length of the selected range, must not be negative
-
-
Method Details
-
emptySelection
Returns the shared instance of the empty text selection.- Returns:
- the shared instance of an empty text selection
-
isEmpty
public boolean isEmpty()Tells whether this text selection is the empty selection.A selection of length 0 is not an empty text selection as it describes, e.g., the cursor position in a viewer.
- Specified by:
isEmpty
in interfaceISelection
- Returns:
true
if this selection is empty- See Also:
-
getOffset
public int getOffset()Description copied from interface:ITextSelection
Returns the offset of the selected text.- Specified by:
getOffset
in interfaceITextSelection
- Returns:
- the offset of the selected text or -1 if there is no valid text information
-
getLength
public int getLength()Description copied from interface:ITextSelection
Returns the length of the selected text.- Specified by:
getLength
in interfaceITextSelection
- Returns:
- the length of the selected text or -1 if there is no valid text information
-
getStartLine
public int getStartLine()Description copied from interface:ITextSelection
Returns number of the line containing the offset of the selected text. If the underlying text has been changed between the creation of this selection object and the call of this method, the value returned might differ from what it would have been at the point of creation.- Specified by:
getStartLine
in interfaceITextSelection
- Returns:
- the start line of this selection or -1 if there is no valid line information
-
getEndLine
public int getEndLine()Description copied from interface:ITextSelection
Returns the number of the line containing the last character of the selected text. If the underlying text has been changed between the creation of this selection object and the call of this method, the value returned might differ from what it would have been at the point of creation.- Specified by:
getEndLine
in interfaceITextSelection
- Returns:
- the end line of this selection or -1 if there is no valid line information
-
getText
Description copied from interface:ITextSelection
Returns the selected text. If the underlying text has been changed between the creation of this selection object and the call of this method, the value returned might differ from what it would have been at the point of creation.- Specified by:
getText
in interfaceITextSelection
- Returns:
- the selected text or
null
if there is no valid text information
-
equals
-
hashCode
public int hashCode() -
getDocument
Returns the document underlying the receiver, possiblynull
.- Returns:
- the document underlying the receiver, possibly
null
- Since:
- 3.5
-
toString
-
getRegions
Description copied from interface:IMultiTextSelection
Returns a non-empty array containing the selected text range for each line covered by the selection.- Specified by:
getRegions
in interfaceIMultiTextSelection
- Returns:
- an array containing a the covered text range for each line covered by the receiver
-