當前位置: 首頁>>代碼示例>>Java>>正文


Java SelectionModel.selectLineAtCaret方法代碼示例

本文整理匯總了Java中com.intellij.openapi.editor.SelectionModel.selectLineAtCaret方法的典型用法代碼示例。如果您正苦於以下問題:Java SelectionModel.selectLineAtCaret方法的具體用法?Java SelectionModel.selectLineAtCaret怎麽用?Java SelectionModel.selectLineAtCaret使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.openapi.editor.SelectionModel的用法示例。


在下文中一共展示了SelectionModel.selectLineAtCaret方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invoke

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable DataContext dataContext) {
  editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  final SelectionModel model = editor.getSelectionModel();
  if (model.hasSelection()) {
    invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd());
  }
  else {
    final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, editor.getCaretModel().getOffset(), true);
    final Pass<GrExpression> callback = new Callback(project, editor, file);
    if (expressions.size() == 1) {
      callback.pass(expressions.get(0));
    }
    else if (expressions.isEmpty()) {
      model.selectLineAtCaret();
      invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd());
    }
    else {
      IntroduceTargetChooser.showChooser(editor, expressions, callback, GrIntroduceHandlerBase.GR_EXPRESSION_RENDERER);
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:GroovyExtractMethodHandler.java

示例2: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final MCSettingsProvider settings = MCSettingsProvider.getInstance(e.getProject());
    final Editor editor = e.getData(LangDataKeys.EDITOR);
    if (editor == null)
        return;

    final SelectionModel selectionModel = editor.getSelectionModel();
    String selectedText;

    if (selectionModel.hasSelection()) {
        selectedText = selectionModel.getSelectedText();
    }
    else {
        selectionModel.selectLineAtCaret();
        if (selectionModel.hasSelection()) {
            selectedText = selectionModel.getSelectedText();
            selectionModel.removeSelection();
        }
        else { return; }
    }

    MayaCommInterface maya = new MayaCommInterface(settings.getHost(), settings.getPort());
    maya.connectMayaLog();
    maya.sendCodeToMaya(selectedText);
}
 
開發者ID:cmcpasserby,項目名稱:MayaCharm,代碼行數:27,代碼來源:SendSelectionAction.java

示例3: invoke

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, @Nullable DataContext dataContext) {
  editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  final SelectionModel model = editor.getSelectionModel();
  if (model.hasSelection()) {
    invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd());
  }
  else {
    final List<GrExpression> expressions = GrIntroduceHandlerBase.collectExpressions(file, editor, editor.getCaretModel().getOffset(), true);
    final Pass<GrExpression> callback = new Callback(project, editor, file);
    if (expressions.size() == 1) {
      callback.pass(expressions.get(0));
    }
    else if (expressions.isEmpty()) {
      model.selectLineAtCaret();
      invokeImpl(project, editor, file, model.getSelectionStart(), model.getSelectionEnd());
    }
    else {
      IntroduceTargetChooser.showChooser(editor, expressions, callback, GrIntroduceHandlerBase.GR_EXPRESSION_RENDERER);
    }
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:22,代碼來源:GroovyExtractMethodHandler.java

示例4: invoke

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection()) {
    selectionModel.selectLineAtCaret();
  }

  ZenCodingTemplate emmetCustomTemplate = CustomLiveTemplate.EP_NAME.findExtension(ZenCodingTemplate.class);
  if (emmetCustomTemplate != null) {
    new WrapWithCustomTemplateAction(emmetCustomTemplate, editor, file, ContainerUtil.<Character>newHashSet()).actionPerformed(null);
  }
  else if (!ApplicationManager.getApplication().isUnitTestMode()) {
    HintManager.getInstance().showErrorHint(editor, "Cannot invoke Surround with Emmet in the current context");
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:SurroundWithEmmetAction.java

示例5: updateSelectionForVariable

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
public static void updateSelectionForVariable(Editor editor, PsiFile file, SelectionModel selectionModel, int offset) {
  final GrVariable variable = findVariableAtCaret(file, editor, offset);
  if (variable == null || variable instanceof GrField || variable instanceof GrParameter) {
    selectionModel.selectLineAtCaret();
  }
  else {
    final TextRange textRange = variable.getTextRange();
    selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:GrIntroduceHandlerBase.java

示例6: selectSomethingUnderCaret

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
protected boolean selectSomethingUnderCaret(Editor editor, DataContext dataContext, SelectionModel selectionModel) {
	selectionModel.selectLineAtCaret();
	String selectedText = selectionModel.getSelectedText();
	if (selectedText != null && selectedText.endsWith("\n")) {
		selectionModel.setSelection(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd() - 1);
	}
	return true;
}
 
開發者ID:krasa,項目名稱:StringManipulation,代碼行數:9,代碼來源:AbstractStringManipAction.java

示例7: executeWriteAction

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
  Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(editor.getContentComponent()));
  if (project == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, dataContext);
    }
    return;
  }

  final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());

  if (file == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, dataContext);
    }
    return;
  }

  SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection() && !selectionModel.hasBlockSelection()) {
    if (Registry.is(CopyAction.SKIP_COPY_AND_CUT_FOR_EMPTY_SELECTION_KEY)) {
      return;
    }
    selectionModel.selectLineAtCaret();
    if (!selectionModel.hasSelection()) return;
  }

  int start = selectionModel.getSelectionStart();
  int end = selectionModel.getSelectionEnd();

  EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_COPY).execute(editor, dataContext);

  if (start != end) {
    // There is a possible case that 'sticky selection' is active. It's automatically removed on copying then, so, we explicitly
    // remove the text.
    editor.getDocument().deleteString(start, end);
  }
  else {
    EditorModificationUtil.deleteSelectedText(editor);
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:43,代碼來源:CutHandler.java

示例8: selectText

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
@Override
protected void selectText(Editor editor) {
  SelectionModel selectionModel = editor.getSelectionModel();
  selectionModel.selectLineAtCaret();
  selectionModel.setSelection(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
}
 
開發者ID:asciidoctor,項目名稱:asciidoctor-intellij-plugin,代碼行數:7,代碼來源:MakeTitle.java

示例9: invoke

import com.intellij.openapi.editor.SelectionModel; //導入方法依賴的package包/類
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, DataContext dataContext)
{
	final SelectionModel selectionModel = editor.getSelectionModel();
	if(!selectionModel.hasSelection())
	{
		final int offset = editor.getCaretModel().getOffset();
		final PsiElement[] statementsInRange = findStatementsAtOffset(editor, file, offset);

		//try line selection
		if(statementsInRange.length == 1 && (!PsiUtil.isStatement(statementsInRange[0]) ||
				statementsInRange[0].getTextRange().getStartOffset() > offset ||
				statementsInRange[0].getTextRange().getEndOffset() < offset ||
				isPreferStatements()))
		{
			selectionModel.selectLineAtCaret();
			final PsiExpression expressionInRange = findExpressionInRange(project, file, selectionModel.getSelectionStart(),
					selectionModel.getSelectionEnd());
			if(expressionInRange == null || getErrorMessage(expressionInRange) != null)
			{
				selectionModel.removeSelection();
			}
		}

		if(!selectionModel.hasSelection())
		{
			final List<PsiExpression> expressions = collectExpressions(file, editor, offset);
			if(expressions.isEmpty())
			{
				selectionModel.selectLineAtCaret();
			}
			else if(expressions.size() == 1)
			{
				final TextRange textRange = expressions.get(0).getTextRange();
				selectionModel.setSelection(textRange.getStartOffset(), textRange.getEndOffset());
			}
			else
			{
				int selection;
				if(statementsInRange.length == 1 &&
						statementsInRange[0] instanceof PsiExpressionStatement &&
						PsiUtilCore.hasErrorElementChild(statementsInRange[0]))
				{
					selection = expressions.indexOf(((PsiExpressionStatement) statementsInRange[0]).getExpression());
				}
				else
				{
					PsiExpression expression = expressions.get(0);
					if(expression instanceof PsiReferenceExpression && ((PsiReferenceExpression) expression).resolve() instanceof
							PsiLocalVariable)
					{
						selection = 1;
					}
					else
					{
						selection = -1;
					}
				}
				IntroduceTargetChooser.showChooser(editor, expressions, new Pass<PsiExpression>()
				{
					public void pass(final PsiExpression selectedValue)
					{
						invoke(project, editor, file, selectedValue.getTextRange().getStartOffset(), selectedValue.getTextRange().getEndOffset
								());
					}
				}, new PsiExpressionTrimRenderer.RenderFunction(), "Expressions", selection, ScopeHighlighter.NATURAL_RANGER);
				return;
			}
		}
	}
	if(invoke(project, editor, file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()) && LookupManager.getActiveLookup
			(editor) == null)
	{
		selectionModel.removeSelection();
	}
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:76,代碼來源:IntroduceVariableBase.java


注:本文中的com.intellij.openapi.editor.SelectionModel.selectLineAtCaret方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。