use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class ExtractIncludeFileBase method highlightInEditor.
private static void highlightInEditor(final Project project, final IncludeDuplicate pair, final Editor editor) {
final HighlightManager highlightManager = HighlightManager.getInstance(project);
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
final int startOffset = pair.getStart().getTextRange().getStartOffset();
final int endOffset = pair.getEnd().getTextRange().getEndOffset();
highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, null);
final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset);
editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class ExtractMethodHelper method highlightInEditor.
private static void highlightInEditor(@NotNull final Project project, @NotNull final SimpleMatch match, @NotNull final Editor editor, Map<SimpleMatch, RangeHighlighter> highlighterMap) {
final List<RangeHighlighter> highlighters = new ArrayList<>();
final HighlightManager highlightManager = HighlightManager.getInstance(project);
final EditorColorsManager colorsManager = EditorColorsManager.getInstance();
final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
final int startOffset = match.getStartElement().getTextRange().getStartOffset();
final int endOffset = match.getEndElement().getTextRange().getEndOffset();
highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, highlighters);
highlighterMap.put(match, highlighters.get(0));
final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset);
editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE);
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class SliceTestUtil method message.
private static String message(int startOffset, SliceUsage usage) {
PsiFile file = usage.getElement().getContainingFile();
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
Editor editor = FileEditorManager.getInstance(file.getProject()).getSelectedTextEditor();
LogicalPosition position = editor.offsetToLogicalPosition(startOffset);
return position + ": '" + StringUtil.first(file.getText().substring(startOffset), 100, true) + "'";
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class SmartIndentingBackspaceHandler method doBeforeCharDeleted.
@Override
protected void doBeforeCharDeleted(char c, PsiFile file, Editor editor) {
Project project = file.getProject();
Document document = editor.getDocument();
CharSequence charSequence = document.getImmutableCharSequence();
CaretModel caretModel = editor.getCaretModel();
int caretOffset = caretModel.getOffset();
LogicalPosition pos = caretModel.getLogicalPosition();
int lineStartOffset = document.getLineStartOffset(pos.line);
int beforeWhitespaceOffset = CharArrayUtil.shiftBackward(charSequence, caretOffset - 1, " \t") + 1;
if (beforeWhitespaceOffset != lineStartOffset) {
myReplacement = null;
return;
}
PsiDocumentManager.getInstance(project).commitDocument(document);
CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
myReplacement = codeStyleFacade.getLineIndent(document, lineStartOffset);
if (myReplacement == null) {
return;
}
int tabSize = codeStyleFacade.getTabSize(file.getFileType());
int targetColumn = getWidth(myReplacement, tabSize);
int endOffset = CharArrayUtil.shiftForward(charSequence, caretOffset, " \t");
LogicalPosition logicalPosition = caretOffset < endOffset ? editor.offsetToLogicalPosition(endOffset) : pos;
int currentColumn = logicalPosition.column;
if (currentColumn > targetColumn) {
myStartOffset = lineStartOffset;
} else if (logicalPosition.line == 0) {
myStartOffset = 0;
myReplacement = "";
} else {
int prevLineEndOffset = document.getLineEndOffset(logicalPosition.line - 1);
myStartOffset = CharArrayUtil.shiftBackward(charSequence, prevLineEndOffset - 1, " \t") + 1;
if (myStartOffset != document.getLineStartOffset(logicalPosition.line - 1)) {
int spacing = CodeStyleManager.getInstance(project).getSpacing(file, endOffset);
myReplacement = StringUtil.repeatSymbol(' ', Math.max(0, spacing));
}
}
}
use of com.intellij.openapi.editor.LogicalPosition in project intellij-community by JetBrains.
the class BackspaceHandler method deleteToTargetPosition.
public static void deleteToTargetPosition(@NotNull Editor editor, @NotNull LogicalPosition pos) {
LogicalPosition logicalPosition = editor.getCaretModel().getLogicalPosition();
if (logicalPosition.line != pos.line) {
LOGGER.error("Unexpected caret position: " + logicalPosition + ", target indent position: " + pos);
return;
}
if (pos.column < logicalPosition.column) {
int targetOffset = editor.logicalPositionToOffset(pos);
int offset = editor.getCaretModel().getOffset();
editor.getSelectionModel().setSelection(targetOffset, offset);
EditorModificationUtil.deleteSelectedText(editor);
editor.getCaretModel().moveToLogicalPosition(pos);
} else if (pos.column > logicalPosition.column) {
EditorModificationUtil.insertStringAtCaret(editor, StringUtil.repeatSymbol(' ', pos.column - logicalPosition.column));
}
}
Aggregations