@@ -4,10 +4,10 @@ import com.intellij.codeInsight.intention.impl.QuickEditAction
4
4
import com.intellij.ide.BrowserUtil
5
5
import com.intellij.ide.plugins.PluginManagerCore
6
6
import com.intellij.lang.Language
7
+ import com.intellij.lang.injection.InjectedLanguageManager
7
8
import com.intellij.openapi.editor.Editor
8
9
import com.intellij.openapi.project.Project
9
10
import com.intellij.openapi.util.Iconable
10
- import com.intellij.openapi.util.text.StringUtil
11
11
import com.intellij.psi.PsiElement
12
12
import com.intellij.psi.PsiFile
13
13
import org.intellij.lang.regexp.RegExpLanguage
@@ -36,8 +36,10 @@ class OpenRegex101Intention : QuickEditAction(), Iconable {
36
36
return
37
37
}
38
38
39
+ val injectedLanguageManager = InjectedLanguageManager .getInstance(project)
40
+ val text = injectedLanguageManager.getUnescapedText(element)
39
41
val flavor = element.language.toFlavor()
40
- val regex = urlEncode(getText(element) )
42
+ val regex = urlEncode(text )
41
43
val url = " $domain /?regex=$regex &flavor=$flavor "
42
44
43
45
if (PluginManagerCore .isUnitTestMode) {
@@ -51,14 +53,9 @@ class OpenRegex101Intention : QuickEditAction(), Iconable {
51
53
return getRangePair(file, editor)?.first ? : file
52
54
}
53
55
54
- private fun getText (element : PsiElement ): String = when (element.language.id) {
55
- " RegExp" , " XsdRegExp" -> StringUtil .unescapeBackSlashes(element.text)
56
- else -> element.text
57
- }
58
-
59
56
private fun urlEncode (text : String ): String = URLEncoder .encode(text, Charsets .UTF_8 .name())
60
57
61
- private fun Language.toFlavor (): String = when (this . id) {
58
+ private fun Language.toFlavor (): String = when (id) {
62
59
" JSRegexp" , " JSUnicodeRegexp" -> " javascript"
63
60
" PythonRegExp" , " PythonVerboseRegExp" -> " python"
64
61
" GoRegExp" -> " golang"
0 commit comments