本文整理匯總了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);
}
}
}
示例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);
}
示例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);
}
}
}
示例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");
}
}
示例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());
}
}
示例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;
}
示例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);
}
}
示例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());
}
示例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();
}
}