Skip to content

Commit

Permalink
Method shortcut display fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
maozhen520 committed Oct 12, 2024
1 parent 59a32e8 commit f531dad
Showing 1 changed file with 2 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,15 @@ private void groupRenderPopupPresentation(InlayHintsSink inlayHintsSink, PsiElem
int offset = getAnchorOffset(psiElement);
int line = document.getLineNumber(offset);
int startOffset = document.getLineStartOffset(line);

InlayPresentation finalPresentation = createPopupPresentation(factory, editor, psiElement, startOffset, offset);
inlayHintsSink.addBlockElement(startOffset, true, true, 300, finalPresentation);
}

private InlayPresentation createPopupPresentation(PresentationFactory factory, Editor editor,
PsiElement psiElement, int startOffset, int offset) {
String linePrefix = editor.getDocument().getText(new TextRange(startOffset, offset));
int column = offset - startOffset + findOffsetBySpace(editor, linePrefix);

int gap = computeInitialWhitespace(editor, psiElement);
List<InlayPresentation> presentations = new SmartList<>();
presentations.add(factory.textSpacePlaceholder(column, true));
presentations.add(factory.textSpacePlaceholder(gap, true));
presentations.add(factory.smallScaledIcon(DevPilotIcons.SYSTEM_ICON_INLAY));
presentations.add(factory.smallScaledIcon(AllIcons.Actions.FindAndShowNextMatchesSmall));
presentations.add(factory.textSpacePlaceholder(1, true));
Expand Down Expand Up @@ -210,18 +207,6 @@ private static int getAnchorOffset(@NotNull PsiElement psiElement) {
return anchorOffset;
}

private int findOffsetBySpace(@NotNull Editor editor, String linePrefix) {
int tabWidth = editor.getSettings().getTabSize(editor.getProject());
int totalOffset = 0;

for (int i = 0; i < linePrefix.length(); ++i) {
if (linePrefix.charAt(i) == '\t') {
totalOffset += tabWidth;
}
}
return totalOffset;
}

private int computeInitialWhitespace(Editor editor, PsiElement psiElement) {
int lineNum = editor.getDocument().getLineNumber(psiElement.getTextRange().getStartOffset());
String textOnLine = editor.getDocument().getText(new TextRange(editor.getDocument().getLineStartOffset(lineNum),
Expand Down

0 comments on commit f531dad

Please sign in to comment.