mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-11 09:40:37 +02:00
Fix problem with lookup selection
This commit is contained in:
parent
cdcb31cf2f
commit
9d6f43cfeb
src/com/maddyhome/idea/vim/option
test/org/jetbrains/plugins/ideavim/group/visual
@ -18,6 +18,8 @@
|
||||
|
||||
package com.maddyhome.idea.vim.option
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupEvent
|
||||
import com.intellij.codeInsight.lookup.LookupListener
|
||||
import com.intellij.codeInsight.lookup.LookupManager
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
|
||||
@ -477,7 +479,19 @@ object IdeaRefactorMode {
|
||||
|
||||
val lookup = LookupManager.getActiveLookup(editor) as? LookupImpl
|
||||
if (lookup != null) {
|
||||
val selStart = editor.selectionModel.selectionStart
|
||||
val selEnd = editor.selectionModel.selectionEnd
|
||||
lookup.performGuardedChange(action)
|
||||
lookup.addLookupListener(object : LookupListener {
|
||||
override fun beforeItemSelected(event: LookupEvent): Boolean {
|
||||
// FIXME: 01.11.2019 Nasty workaround because of problems in IJ platform
|
||||
// Lookup replaces selected text and not the template itself. So, if there is no selection
|
||||
// in the template, lookup value will not replace the template, but just insert value on the caret position
|
||||
lookup.performGuardedChange { editor.selectionModel.setSelection(selStart, selEnd) }
|
||||
lookup.removeLookupListener(this)
|
||||
return true
|
||||
}
|
||||
})
|
||||
} else {
|
||||
action()
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
package org.jetbrains.plugins.ideavim.group.visual
|
||||
|
||||
import com.intellij.codeInsight.lookup.Lookup
|
||||
import com.intellij.codeInsight.template.TemplateManager
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
|
||||
import com.intellij.ide.DataManager
|
||||
@ -438,6 +439,27 @@ class TemplateTest : VimOptionTestCase(IdeaRefactorMode.name) {
|
||||
assertNull(TemplateManagerImpl.getTemplateState(myFixture.editor))
|
||||
}
|
||||
|
||||
@VimOptionTestConfiguration(VimTestOption(IdeaRefactorMode.name, VimTestOptionType.VALUE, [IdeaRefactorMode.keep]))
|
||||
fun `test template with lookup`() {
|
||||
configureByJavaText("""
|
||||
class Hello {
|
||||
public static void main() {
|
||||
int my${c}Var = 5;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
startRenaming(VariableInplaceRenameHandler())
|
||||
val lookupValue = myFixture.lookupElementStrings?.get(0) ?: kotlin.test.fail()
|
||||
myFixture.finishLookup(Lookup.NORMAL_SELECT_CHAR)
|
||||
myFixture.checkResult("""
|
||||
class Hello {
|
||||
public static void main() {
|
||||
int $lookupValue = 5;
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
private fun startRenaming(handler: VariableInplaceRenameHandler): Editor {
|
||||
val editor = if (myFixture.editor is EditorWindow) (myFixture.editor as EditorWindow).delegate else myFixture.editor
|
||||
VimListenerManager.EditorListeners.add(editor)
|
||||
|
Loading…
Reference in New Issue
Block a user