use of com.intellij.openapi.editor.VisualPosition in project intellij-community by JetBrains.
the class XmlSyncTagCommunityTest method testMultiCaretAdding.
public void testMultiCaretAdding() {
doTest("<div<caret>></div>\n" + "<div></div>\n", "\b\b\biii", "<iii></iii>\n" + "<div></div>\n");
myFixture.getEditor().getCaretModel().addCaret(new VisualPosition(1, 4));
type("\b");
myFixture.checkResult("<ii></ii>\n" + "<di></di>\n");
}
use of com.intellij.openapi.editor.VisualPosition in project intellij-community by JetBrains.
the class SearchSupport method getPopupLocation.
protected Point getPopupLocation() {
VisualPosition visualPosition = getEditor().offsetToVisualPosition(getEditor().getCaretModel().getOffset());
Point point = getEditor().visualPositionToXY(visualPosition);
SwingUtilities.convertPointToScreen(point, getEditor().getComponent());
point.y += 2;
return point;
}
use of com.intellij.openapi.editor.VisualPosition in project ideavim by JetBrains.
the class MotionActionTest method testUpDownMove.
// |j| |k|
public void testUpDownMove() {
final Editor editor = typeTextInFile(parseKeys("2j", "k"), "one\n" + "tw<caret>o\n" + "three\n" + "four\n");
final VisualPosition position = editor.getCaretModel().getVisualPosition();
assertEquals(new VisualPosition(2, 2), position);
}
use of com.intellij.openapi.editor.VisualPosition in project intellij-community by JetBrains.
the class SoftWrapHelper method isCaretAfterSoftWrap.
/**
* Every soft wrap implies that multiple visual positions correspond to the same document offset. We can classify
* such positions by the following criteria:
* <pre>
* <ul>
* <li>positions from visual line with soft wrap start;</li>
* <li>positions from visual line with soft wrap end;</li>
* </ul>
* </pre>
* <p/>
* This method allows to answer if caret offset of the given editor points to soft wrap and visual caret position
* belongs to the visual line where soft wrap end is located.
*
* @return <code>true</code> if caret offset of the given editor points to visual position that belongs to
* visual line where soft wrap end is located
*/
public static boolean isCaretAfterSoftWrap(CaretImpl caret) {
if (!caret.isUpToDate()) {
return false;
}
EditorImpl editor = caret.getEditor();
SoftWrapModel softWrapModel = editor.getSoftWrapModel();
int offset = caret.getOffset();
SoftWrap softWrap = softWrapModel.getSoftWrap(offset);
if (softWrap == null) {
return false;
}
VisualPosition afterWrapPosition = editor.offsetToVisualPosition(offset, false, false);
VisualPosition caretPosition = caret.getVisualPosition();
return caretPosition.line == afterWrapPosition.line && caretPosition.column <= afterWrapPosition.column;
}
use of com.intellij.openapi.editor.VisualPosition in project intellij-community by JetBrains.
the class ReassignVariableUtil method reassign.
@VisibleForTesting
public static boolean reassign(final Editor editor) {
final SmartPsiElementPointer<PsiDeclarationStatement> pointer = editor.getUserData(DECLARATION_KEY);
final PsiDeclarationStatement declaration = pointer != null ? pointer.getElement() : null;
final PsiType type = getVariableType(declaration);
if (type != null) {
VariablesProcessor proc = findVariablesOfType(declaration, type);
if (proc.size() > 0) {
List<PsiVariable> vars = new ArrayList<>();
for (int i = 0; i < proc.size(); i++) {
final PsiVariable variable = proc.getResult(i);
PsiElement outerCodeBlock = PsiUtil.getVariableCodeBlock(variable, null);
if (outerCodeBlock == null)
continue;
if (ReferencesSearch.search(variable, new LocalSearchScope(outerCodeBlock)).forEach(reference -> {
final PsiElement element = reference.getElement();
if (element != null) {
return HighlightControlFlowUtil.getInnerClassVariableReferencedFrom(variable, element) == null;
}
return true;
})) {
vars.add(variable);
}
}
if (vars.isEmpty()) {
return true;
}
if (vars.size() == 1) {
replaceWithAssignment(declaration, proc.getResult(0), editor);
return true;
}
final DefaultListModel<PsiVariable> model = new DefaultListModel<>();
for (PsiVariable var : vars) {
model.addElement(var);
}
final JBList list = new JBList(model);
list.setCellRenderer(new ListCellRendererWrapper<PsiVariable>() {
@Override
public void customize(JList list, PsiVariable value, int index, boolean selected, boolean hasFocus) {
if (value != null) {
setText(value.getName());
setIcon(value.getIcon(0));
}
}
});
final VisualPosition visualPosition = editor.getCaretModel().getVisualPosition();
final Point point = editor.visualPositionToXY(new VisualPosition(visualPosition.line + 1, visualPosition.column));
JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose variable to reassign").setRequestFocus(true).setItemChoosenCallback(() -> replaceWithAssignment(declaration, (PsiVariable) list.getSelectedValue(), editor)).createPopup().show(new RelativePoint(editor.getContentComponent(), point));
}
return true;
}
return false;
}
Aggregations