mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Add internal action for reference shortening by selection
#KTIJ-28116 GitOrigin-RevId: b82e2477fcd3469894765a1480425bf1592bcbd6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
24cd0a3f63
commit
c315c0be49
+6
@@ -24,6 +24,12 @@
|
||||
<inlineActionHandler implementation="org.jetbrains.kotlin.idea.k2.refactoring.inline.KotlinInlinePropertyHandler"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
<action class="org.jetbrains.kotlin.idea.k2.refactoring.internal.ShortenSelectionAction" internal="true" text="Shorten Selection">
|
||||
<add-to-group group-id="KotlinInternalGroup"/>
|
||||
</action>
|
||||
</actions>
|
||||
|
||||
<extensions defaultExtensionNs="org.jetbrains.kotlin">
|
||||
<codeinsight.quickfix.registrar implementation="org.jetbrains.kotlin.idea.k2.refactoring.changeSignature.quickFix.ChangeSignatureQuickFixesRegistrar"/>
|
||||
</extensions>
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.k2.refactoring.internal
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import org.jetbrains.kotlin.analysis.api.KtAllowAnalysisFromWriteAction
|
||||
import org.jetbrains.kotlin.analysis.api.KtAllowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisFromWriteAction
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferencesInRange
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
class ShortenSelectionAction : AnAction() {
|
||||
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
|
||||
|
||||
override fun isDumbAware(): Boolean = false
|
||||
|
||||
@OptIn(KtAllowAnalysisFromWriteAction::class, KtAllowAnalysisOnEdt::class)
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val dataContext = e.dataContext
|
||||
val project = CommonDataKeys.PROJECT.getData(dataContext) ?: return
|
||||
val editor = CommonDataKeys.EDITOR.getData(dataContext) ?: return
|
||||
val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) as? KtFile ?: return
|
||||
val selection = TextRange(editor.selectionModel.selectionStart, editor.selectionModel.selectionEnd)
|
||||
WriteCommandAction.runWriteCommandAction(project, templateText, null, {
|
||||
allowAnalysisOnEdt {
|
||||
allowAnalysisFromWriteAction {
|
||||
analyze(file) {
|
||||
shortenReferencesInRange(file, selection)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, file)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user