本文整理匯總了Java中org.eclipse.jface.text.ITextSelection.isEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Java ITextSelection.isEmpty方法的具體用法?Java ITextSelection.isEmpty怎麽用?Java ITextSelection.isEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.ITextSelection
的用法示例。
在下文中一共展示了ITextSelection.isEmpty方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
public void run()
{
VelocityEditor editor = (VelocityEditor) getTextEditor();
if (editor.fMouseListener.fActiveRegion != null)
{
// If the user is using the ctrl-alt mouse click feature, then
// goto the definition under the mouse, and not under the current cursor location
editor.gotoDefinition(editor.fMouseListener.fActiveRegion);
return;
}
ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
if (!selection.isEmpty())
{
editor.gotoDefinition(new Region(selection.getOffset(), selection.getLength()));
}
}
示例2: isValidSelection
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
* Returns if the current selection is valid, i.e. whether it is empty and
* the caret in the whitespace at the start of a line, or covers multiple
* lines.
*
* @return <code>true</code> if the selection is valid for an indent
* operation
*/
private boolean isValidSelection() {
ITextSelection selection = getSelection();
if (selection.isEmpty())
return false;
int offset = selection.getOffset();
int length = selection.getLength();
IDocument document = getDocument();
if (document == null)
return false;
try {
IRegion firstLine = document.getLineInformationOfOffset(offset);
int lineOffset = firstLine.getOffset();
// either the selection has to be empty and the caret in the WS at
// the line start
// or the selection has to extend over multiple lines
if (length == 0)
return document.get(lineOffset, offset - lineOffset).trim().length() == 0;
else
// return lineOffset + firstLine.getLength() < offset + length;
return false; // only enable for empty selections for now
} catch (BadLocationException e) {
}
return false;
}