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());
}
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);
}
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();
}
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;
}
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);
});
}
Aggregations