Search in sources :

Example 46 with SelectionModel

use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.

the class BlockSelectionEditingTest method testBlockRemovalAndCollapsedFoldRegionsBefore.

public void testBlockRemovalAndCollapsedFoldRegionsBefore() throws IOException {
    // Inspired by IDEA-69371
    String initialText = "fold line #1\n" + "fold line #2\n" + "initialText    line 1\n" + "initialText    line 2\n" + "initialText    line 3";
    init(initialText, TestFileType.TEXT);
    final int foldEndOffset = initialText.indexOf("initialText");
    addCollapsedFoldRegion(0, foldEndOffset, "...");
    int column = "initialText".length();
    final LogicalPosition blockStart = new LogicalPosition(3, column);
    final LogicalPosition blockEnd = new LogicalPosition(4, column);
    final SelectionModel selectionModel = myEditor.getSelectionModel();
    selectionModel.setBlockSelection(blockStart, blockEnd);
    delete();
    delete();
    String expectedText = "fold line #1\n" + "fold line #2\n" + "initialText    line 1\n" + "initialText  line 2\n" + "initialText  line 3";
    assertEquals(expectedText, myEditor.getDocument().getText());
    assertSelectionRanges(new int[][] { { 59, 59 }, { 79, 79 } });
    final FoldRegion foldRegion = getFoldRegion(0);
    assertNotNull(foldRegion);
    assertEquals(0, foldRegion.getStartOffset());
    assertEquals(foldEndOffset, foldRegion.getEndOffset());
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) SelectionModel(com.intellij.openapi.editor.SelectionModel) FoldRegion(com.intellij.openapi.editor.FoldRegion)

Example 47 with SelectionModel

use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.

the class VcsSelectionUtil method getSelectionFromEditor.

@Nullable
private static VcsSelection getSelectionFromEditor(VcsContext context) {
    Editor editor = context.getEditor();
    if (editor == null)
        return null;
    SelectionModel selectionModel = editor.getSelectionModel();
    if (!selectionModel.hasSelection()) {
        return null;
    }
    return new VcsSelection(editor.getDocument(), selectionModel);
}
Also used : SelectionModel(com.intellij.openapi.editor.SelectionModel) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable)

Example 48 with SelectionModel

use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.

the class PsiModificationTrackerTest method replaceSelection.

private void replaceSelection(final String with) {
    SelectionModel sel = getEditor().getSelectionModel();
    getEditor().getDocument().replaceString(sel.getSelectionStart(), sel.getSelectionEnd(), with);
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
}
Also used : SelectionModel(com.intellij.openapi.editor.SelectionModel)

Example 49 with SelectionModel

use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.

the class CompareClipboardWithSelectionAction method createContent.

@NotNull
private static DocumentContent createContent(@NotNull Project project, @NotNull Editor editor, @Nullable FileType type) {
    DocumentContent content = DiffContentFactory.getInstance().create(project, editor.getDocument(), type);
    SelectionModel selectionModel = editor.getSelectionModel();
    if (selectionModel.hasSelection()) {
        TextRange range = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
        content = DiffContentFactory.getInstance().createFragment(project, content, range);
    }
    return content;
}
Also used : DocumentContent(com.intellij.diff.contents.DocumentContent) SelectionModel(com.intellij.openapi.editor.SelectionModel) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with SelectionModel

use of com.intellij.openapi.editor.SelectionModel in project intellij-community by JetBrains.

the class ParameterNameHintsConfigurable method addSelectedText.

private void addSelectedText(@NotNull Language language, @NotNull String newPreselectedPattern) {
    EditorTextField textField = myEditors.get(language);
    String text = textField.getText();
    int startOffset = text.length();
    text += "\n" + newPreselectedPattern;
    int endOffset = text.length();
    textField.setText(text);
    textField.addSettingsProvider((editor) -> {
        SelectionModel model = editor.getSelectionModel();
        model.setSelection(startOffset + 1, endOffset);
    });
}
Also used : EditorTextField(com.intellij.ui.EditorTextField) SelectionModel(com.intellij.openapi.editor.SelectionModel)

Aggregations

SelectionModel (com.intellij.openapi.editor.SelectionModel)76 TextRange (com.intellij.openapi.util.TextRange)21 Document (com.intellij.openapi.editor.Document)19 PsiElement (com.intellij.psi.PsiElement)19 NotNull (org.jetbrains.annotations.NotNull)16 Editor (com.intellij.openapi.editor.Editor)14 Nullable (org.jetbrains.annotations.Nullable)11 CaretModel (com.intellij.openapi.editor.CaretModel)10 PsiFile (com.intellij.psi.PsiFile)8 Project (com.intellij.openapi.project.Project)7 ArrayList (java.util.ArrayList)6 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)3 SurroundDescriptor (com.intellij.lang.surroundWith.SurroundDescriptor)3 Pass (com.intellij.openapi.util.Pass)3 List (java.util.List)3 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)3 EditorWindow (com.intellij.injected.editor.EditorWindow)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)2 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)2