package com.jetbrains.python.psi.impl;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.AbstractElementManipulator;
import com.jetbrains.python.PythonStringUtil;
import com.jetbrains.python.psi.PyElementGenerator;

/**
 * @author traff
 */
public class PyStringLiteralExpressionManipulator extends AbstractElementManipulator<PyStringLiteralExpressionImpl> {
  private static final Logger LOG = Logger.getInstance(PyStringLiteralExpressionManipulator.class);

  public PyStringLiteralExpressionImpl handleContentChange(PyStringLiteralExpressionImpl element, TextRange range, String newContent) {
    Pair<String, String> quotes = PythonStringUtil.getQuotes(range.substring(element.getText()));

    if (quotes != null) {
      range = TextRange.create(range.getStartOffset() + quotes.first.length(), range.getEndOffset() - quotes.second.length());
    }

    String newName = range.replace(element.getText(), newContent);

    return (PyStringLiteralExpressionImpl)element
      .replace(PyElementGenerator.getInstance(element.getProject()).createStringLiteralAlreadyEscaped(newName));
  }
}

@@ -37,55 +37,8 @@
 l;%0A%0A
-import com.intellij.openapi.diagnostic.Logger;%0A
 impo
@@ -72,16 +72,16 @@
 l.Pair;%0A
+
 import c
@@ -413,108 +413,8 @@
 l%3E %7B
-%0A  private static final Logger LOG = Logger.getInstance(PyStringLiteralExpressionManipulator.class);
 %0A%0A  
@@ -924,16 +924,16 @@
 element%0A
-
       .r
@@ -1040,11 +1040,380 @@
 e));%0A  %7D
+%0A%0A  @Override%0A  public TextRange getRangeInElement(PyStringLiteralExpressionImpl element) %7B%0A    Pair%3CString, String%3E pair = PythonStringUtil.getQuotes(element.getText());%0A    if (pair != null) %7B%0A      return TextRange.from(pair.first.length(), element.getTextLength() - pair.first.length() - pair.second.length());%0A    %7D%0A    return super.getRangeInElement(element);%0A  %7D
 %0A%7D%0A

implement getRangeInElement: fixes inject language action