@@ -23,6 +23,7 @@ import com.itsaky.androidide.R
2323import com.itsaky.androidide.actions.ActionData
2424import com.itsaky.androidide.actions.ActionItem
2525import com.itsaky.androidide.actions.BaseEditorAction
26+ import com.itsaky.androidide.editor.utils.isOperatorToken
2627import com.itsaky.androidide.editor.utils.isXmlAttribute
2728import com.itsaky.androidide.idetooltips.TooltipCategory
2829import com.itsaky.androidide.idetooltips.TooltipManager
@@ -58,29 +59,19 @@ class ShowTooltipAction(private val context: Context, override val order: Int) :
5859 val anchorView = target.getAnchorView() ? : return false
5960 val editor = getEditor(data)
6061
61- val category: String
62- val tag: String
63-
64- if (editor != null ) {
65- val selectedText = target.getSelectedText()
66- category = when (editor.file?.extension) {
67- " java" -> TooltipCategory .CATEGORY_JAVA
68- " kt" -> TooltipCategory .CATEGORY_KOTLIN
69- " xml" -> TooltipCategory .CATEGORY_XML
70- else -> TooltipCategory .CATEGORY_IDE
71- }
72-
73- val useEditorTag = editor.tag != null
74- val textToUse = selectedText ? : " "
75- tag = when {
76- useEditorTag -> editor.tag.toString()
77- category == TooltipCategory .CATEGORY_XML && editor.isXmlAttribute() -> textToUse.substringAfterLast(" :" )
78- else -> textToUse
62+ val categoryAndTag =
63+ if (editor != null ) {
64+ val category = tooltipCategoryForExtension(editor.file?.extension)
65+ resolveTooltipTag(
66+ category = category,
67+ selectedText = target.getSelectedText(),
68+ editorTag = editor.tag?.toString(),
69+ isXmlAttribute = category == TooltipCategory .CATEGORY_XML && editor.isXmlAttribute(),
70+ ).let { tag -> category to tag }
71+ } else {
72+ TooltipCategory .CATEGORY_IDE to TooltipTag .DIALOG_FIND_IN_PROJECT
7973 }
80- } else {
81- category = TooltipCategory .CATEGORY_IDE
82- tag = TooltipTag .DIALOG_FIND_IN_PROJECT
83- }
74+ val (category, tag) = categoryAndTag
8475
8576 if (tag.isEmpty()) return false
8677
@@ -95,4 +86,27 @@ class ShowTooltipAction(private val context: Context, override val order: Int) :
9586 }
9687
9788 override fun retrieveTooltipTag (isAlternateContext : Boolean ) = TooltipTag .EDITOR_TOOLBAR_HELP
89+ }
90+
91+ internal fun tooltipCategoryForExtension (extension : String? ): String =
92+ when (extension) {
93+ " java" -> TooltipCategory .CATEGORY_JAVA
94+ " kt" -> TooltipCategory .CATEGORY_KOTLIN
95+ " xml" -> TooltipCategory .CATEGORY_XML
96+ else -> TooltipCategory .CATEGORY_IDE
97+ }
98+
99+ internal fun resolveTooltipTag (
100+ category : String ,
101+ selectedText : String? ,
102+ editorTag : String? ,
103+ isXmlAttribute : Boolean ,
104+ ): String {
105+ val textToUse = selectedText ? : " "
106+ return when {
107+ ! editorTag.isNullOrEmpty() -> editorTag
108+ category == TooltipCategory .CATEGORY_XML && isXmlAttribute -> textToUse.substringAfterLast(" :" )
109+ category == TooltipCategory .CATEGORY_KOTLIN && isOperatorToken(textToUse) -> " kotlin.operator.$textToUse "
110+ else -> textToUse
111+ }
98112}
0 commit comments