use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class EditorView method isRtlLocation.
public boolean isRtlLocation(@NotNull VisualPosition visualPosition) {
assertIsDispatchThread();
if (myDocument.getTextLength() == 0)
return false;
LogicalPosition logicalPosition = visualToLogicalPosition(visualPosition);
int offset = logicalPositionToOffset(logicalPosition);
if (myEditor.getSoftWrapModel().getSoftWrap(offset) != null) {
VisualPosition beforeWrapPosition = offsetToVisualPosition(offset, true, true);
if (visualPosition.line == beforeWrapPosition.line && (visualPosition.column > beforeWrapPosition.column || visualPosition.column == beforeWrapPosition.column && visualPosition.leansRight)) {
return false;
}
VisualPosition afterWrapPosition = offsetToVisualPosition(offset, false, false);
if (visualPosition.line == afterWrapPosition.line && (visualPosition.column < afterWrapPosition.column || visualPosition.column == afterWrapPosition.column && !visualPosition.leansRight)) {
return false;
}
}
int line = myDocument.getLineNumber(offset);
LineLayout layout = myTextLayoutCache.getLineLayout(line);
return layout.isRtlLocation(offset - myDocument.getLineStartOffset(line), logicalPosition.leansForward);
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class IndentsModelImpl method getCaretIndentGuide.
@Override
public IndentGuideDescriptor getCaretIndentGuide() {
final LogicalPosition pos = myEditor.getCaretModel().getLogicalPosition();
final int column = pos.column;
final int line = pos.line;
if (column > 0) {
for (IndentGuideDescriptor indent : myIndents) {
if (column == indent.indentLevel && line >= indent.startLine && line < indent.endLine) {
return indent;
}
}
}
return null;
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class ExtractMethodHandler method highlightPrepareError.
public static void highlightPrepareError(PrepareFailedException e, PsiFile file, Editor editor, final Project project) {
if (e.getFile() == file) {
final TextRange textRange = e.getTextRange();
final HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, null);
final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(textRange.getStartOffset());
editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
WindowManager.getInstance().getStatusBar(project).setInfo(RefactoringBundle.message("press.escape.to.remove.the.highlighting"));
}
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class ExtractMethodProcessor method doRefactoring.
/**
* Invoked in command and in atomic action
*/
public void doRefactoring() throws IncorrectOperationException {
initDuplicates();
chooseAnchor();
LogicalPosition pos1;
if (myEditor != null) {
int col = myEditor.getCaretModel().getLogicalPosition().column;
int line = myEditor.getCaretModel().getLogicalPosition().line;
pos1 = new LogicalPosition(line, col);
LogicalPosition pos = new LogicalPosition(0, 0);
myEditor.getCaretModel().moveToLogicalPosition(pos);
} else {
pos1 = null;
}
final SearchScope processConflictsScope = myMethodVisibility.equals(PsiModifier.PRIVATE) ? new LocalSearchScope(myTargetClass) : GlobalSearchScope.projectScope(myProject);
final Map<PsiMethodCallExpression, PsiMethod> overloadsResolveMap = new HashMap<>();
final Runnable collectOverloads = () -> ApplicationManager.getApplication().runReadAction(() -> {
Map<PsiMethodCallExpression, PsiMethod> overloads = ExtractMethodUtil.encodeOverloadTargets(myTargetClass, processConflictsScope, myMethodName, myCodeFragmentMember);
overloadsResolveMap.putAll(overloads);
});
final Runnable extract = () -> {
doExtract();
ExtractMethodUtil.decodeOverloadTargets(overloadsResolveMap, myExtractedMethod, myCodeFragmentMember);
};
if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
collectOverloads.run();
extract.run();
} else {
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(collectOverloads, "Collect overloads...", true, myProject))
return;
ApplicationManager.getApplication().runWriteAction(extract);
}
if (myEditor != null) {
myEditor.getCaretModel().moveToLogicalPosition(pos1);
int offset = myMethodCall.getMethodExpression().getTextRange().getStartOffset();
myEditor.getCaretModel().moveToOffset(offset);
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
myEditor.getSelectionModel().removeSelection();
}
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class CodeInsightTestCase method checkResult.
@Override
protected void checkResult(String dataName) throws Exception {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
super.checkResult(dataName);
CodeInsightTestData data = (CodeInsightTestData) myTestDataAfter;
if (data.getColumnNumber() >= 0) {
assertEquals(dataName + ":caretColumn", data.getColumnNumber(), myEditor.getCaretModel().getLogicalPosition().column + 1);
}
if (data.getLineNumber() >= 0) {
assertEquals(dataName + ":caretLine", data.getLineNumber(), myEditor.getCaretModel().getLogicalPosition().line + 1);
}
int selectionStart = myEditor.getSelectionModel().getSelectionStart();
int selectionEnd = myEditor.getSelectionModel().getSelectionEnd();
LogicalPosition startPosition = myEditor.offsetToLogicalPosition(selectionStart);
LogicalPosition endPosition = myEditor.offsetToLogicalPosition(selectionEnd);
if (data.getSelectionStartColumnNumber() >= 0) {
assertEquals(dataName + ":selectionStartColumn", data.getSelectionStartColumnNumber(), startPosition.column + 1);
}
if (data.getSelectionStartLineNumber() >= 0) {
assertEquals(dataName + ":selectionStartLine", data.getSelectionStartLineNumber(), startPosition.line + 1);
}
if (data.getSelectionEndColumnNumber() >= 0) {
assertEquals(dataName + ":selectionEndColumn", data.getSelectionEndColumnNumber(), endPosition.column + 1);
}
if (data.getSelectionEndLineNumber() >= 0) {
assertEquals(dataName + ":selectionEndLine", data.getSelectionEndLineNumber(), endPosition.line + 1);
}
}
Aggregations