当前位置: 首页>>代码示例>>Java>>正文


Java ITextSelection.isEmpty方法代码示例

本文整理汇总了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()));
    }
}
 
开发者ID:ninneko,项目名称:velocity-edit,代码行数:19,代码来源:GotoDefinitionAction.java

示例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;
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:39,代码来源:IndentAction.java


注:本文中的org.eclipse.jface.text.ITextSelection.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。