1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-04-13 11:15:43 +02:00

Fix IdeaVim state after starting the template in remdev scenario

Now the template is properly detected on client as well.

Related: RIDER-118965
This commit is contained in:
Ilya Usov 2025-03-13 11:49:49 +02:00 committed by Alex Plate
parent 79b9dbd656
commit f40540d114
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
2 changed files with 48 additions and 1 deletions
AUTHORS.md
src/main/java/com/maddyhome/idea/vim/helper

View File

@ -583,6 +583,10 @@ Contributors:
[![icon][github]](https://github.com/nath)
 
Nath Tumlin
* [![icon][mail]](mailto:ilya.usov@jetbrains.com)
[![icon][github]](https://github.com/Iliya-usov)
 
Ilya Usov
Previous contributors:

View File

@ -12,6 +12,13 @@ import com.intellij.codeInsight.template.TemplateManager
import com.intellij.injected.editor.EditorWindow
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.colors.EditorColors
import com.intellij.openapi.editor.ex.MarkupModelEx
import com.intellij.openapi.editor.impl.DocumentMarkupModel
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Computable
import com.intellij.util.Processor
import com.intellij.util.application
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.inBlockSelection
@ -34,7 +41,43 @@ internal fun Editor.isTemplateActive(): Boolean {
val project = this.project ?: return false
// XXX: I've disabled this check to find the stack trace where the project is disposed
// if (project.isDisposed) return false
return TemplateManager.getInstance(project).getActiveTemplate(this) != null
if (TemplateManager.getInstance(project).getActiveTemplate(this) != null) {
return true
}
return checkTemplateByHighlighter(project)
}
// Note: This approach is important for IDEs which use remote connection (Rider, CLion, RemDev, etc)
// The highlighting happens on the backend, and IdeaVim works on the frontend. Thus, TemplateManager
// is always empty. However, the highlighting itself also contains information about the LIVE TEMPLATE,
// which we verify here.
private fun Editor.checkTemplateByHighlighter(project: Project): Boolean {
return application.runReadAction(Computable {
val offset = caretModel.primaryCaret.offset
val editorMarkup = markupModel
if (editorMarkup is MarkupModelEx && hasLiveTemplateHighlighter(editorMarkup, offset)) {
return@Computable true
}
val documentMarkup = DocumentMarkupModel.forDocument(document, project, true)
documentMarkup is MarkupModelEx && hasLiveTemplateHighlighter(documentMarkup, offset)
})
}
private fun hasLiveTemplateHighlighter(
markup: MarkupModelEx,
offset: Int,
): Boolean {
var found = false;
markup.processRangeHighlightersOverlappingWith(
offset, offset,
Processor {
found = it.textAttributesKey == EditorColors.LIVE_TEMPLATE_ATTRIBUTES
!found
})
return found
}
private fun vimEnabled(editor: Editor?): Boolean {