Skip to content

Commit

Permalink
[properties] unescape action preview friendly
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 8589f0b1ae78162eeea446613f7e816b0f9e1168
  • Loading branch information
akozlova authored and intellij-monorepo-bot committed Jan 23, 2023
1 parent 630b9cb commit d209f39
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.intellij.lang.properties;

import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.lang.ASTNode;
import com.intellij.lang.annotation.AnnotationBuilder;
import com.intellij.lang.annotation.AnnotationHolder;
Expand Down Expand Up @@ -86,6 +87,7 @@ private static void highlightTokens(final Property property, final ASTNode node,
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
AnnotationBuilder builder = holder.newAnnotation(severity, displayName).range(textRange).enforcedTextAttributes(attributes);

int startOffset = textRange.getStartOffset();
if (key == PropertiesComponent.PROPERTIES_INVALID_STRING_ESCAPE.getTextAttributesKey()) {
builder = builder.withFix(new IntentionAction() {
@Override
Expand All @@ -102,18 +104,16 @@ public String getFamilyName() {

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!property.isValid() || !property.getManager().isInProject(property)) return false;
if (!BaseIntentionAction.canModify(file)) return false;

String text = property.getPropertiesFile().getContainingFile().getText();
int startOffset = textRange.getStartOffset();
String text = file.getText();
return text.length() > startOffset && text.charAt(startOffset) == '\\';
}

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
int offset = textRange.getStartOffset();
if (property.getPropertiesFile().getContainingFile().getText().charAt(offset) == '\\') {
editor.getDocument().deleteString(offset, offset+1);
if (file.getText().charAt(startOffset) == '\\') {
editor.getDocument().deleteString(startOffset, startOffset + 1);
}
}

Expand Down

0 comments on commit d209f39

Please sign in to comment.