1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-06-05 22:34:03 +02:00

Revert "Support new marks"

This reverts commit 134c68c705.
This commit is contained in:
Alex Plate 2021-12-16 11:56:58 +03:00
parent 27fb36a6c5
commit 932296afb6
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
11 changed files with 145 additions and 200 deletions
.teamcity/_Self
build.gradle.ktsgradle.properties
src
main
java/com/maddyhome/idea/vim
resources/META-INF
test/java/org/jetbrains/plugins/ideavim
VimTestCase.kt
action/motion/mark
ex/implementation/commands

View File

@ -5,7 +5,7 @@ object Constants {
const val EAP_CHANNEL = "eap" const val EAP_CHANNEL = "eap"
const val DEV_CHANNEL = "Dev" const val DEV_CHANNEL = "Dev"
const val VERSION = "1.9.1" const val VERSION = "1.9.0"
const val DEV_VERSION = "1.10.0" const val DEV_VERSION = "1.10.0"
const val GITHUB_TESTS = "LATEST-EAP-SNAPSHOT" const val GITHUB_TESTS = "LATEST-EAP-SNAPSHOT"
@ -14,7 +14,7 @@ object Constants {
const val PROPERTY_TESTS = "LATEST-EAP-SNAPSHOT" const val PROPERTY_TESTS = "LATEST-EAP-SNAPSHOT"
const val LONG_RUNNING_TESTS = "LATEST-EAP-SNAPSHOT" const val LONG_RUNNING_TESTS = "LATEST-EAP-SNAPSHOT"
const val QODANA_TESTS = "LATEST-EAP-SNAPSHOT" const val QODANA_TESTS = "LATEST-EAP-SNAPSHOT"
const val RELEASE = "2021.3" const val RELEASE = "2021.2.2"
const val RELEASE_DEV = "LATEST-EAP-SNAPSHOT" const val RELEASE_DEV = "LATEST-EAP-SNAPSHOT"
const val RELEASE_EAP = "LATEST-EAP-SNAPSHOT" const val RELEASE_EAP = "LATEST-EAP-SNAPSHOT"
} }

View File

@ -74,14 +74,14 @@ configurations {
tasks { tasks {
// Include tests for testing on LATEST-EAP-SNAPSHOT // Include tests for testing on LATEST-EAP-SNAPSHOT
val test by getting(Test::class) { // val test by getting(Test::class) {
isScanForTestClasses = false // isScanForTestClasses = false
// Only run tests from classes that end with "Test" // // Only run tests from classes that end with "Test"
include("**/*Test.class") // include("**/*Test.class")
include("**/*Tests.class") // include("**/*Tests.class")
exclude("**/ParserTest.class") // exclude("**/ParserTest.class")
} // }
//
compileJava { compileJava {
sourceCompatibility = javaVersion sourceCompatibility = javaVersion
targetCompatibility = javaVersion targetCompatibility = javaVersion

View File

@ -1,6 +1,6 @@
# suppress inspection "UnusedProperty" for whole file # suppress inspection "UnusedProperty" for whole file
ideaVersion=LATEST-EAP-SNAPSHOT ideaVersion=2021.2.2
downloadIdeaSources=true downloadIdeaSources=true
instrumentPluginCode=true instrumentPluginCode=true
version=SNAPSHOT version=SNAPSHOT

View File

@ -18,9 +18,8 @@
package com.maddyhome.idea.vim.common package com.maddyhome.idea.vim.common
import com.intellij.ide.bookmark.BookmarkType import com.intellij.ide.bookmarks.Bookmark
import com.intellij.ide.bookmark.BookmarksManager import com.intellij.ide.bookmarks.BookmarkManager
import com.intellij.ide.bookmark.LineBookmark
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
@ -80,11 +79,11 @@ data class VimMark(
} }
} }
class IntellijMark(bookmark: LineBookmark, override val col: Int, project: Project?) : Mark { class IntellijMark(bookmark: Bookmark, override val col: Int, project: Project?) : Mark {
private val project: WeakReference<Project?> = WeakReference(project) private val project: WeakReference<Project?> = WeakReference(project)
override val key = BookmarksManager.getInstance(project)?.getType(bookmark)?.mnemonic!! override val key = bookmark.mnemonic
override val logicalLine: Int override val logicalLine: Int
get() = getMark()?.line ?: 0 get() = getMark()?.line ?: 0
override val filename: String override val filename: String
@ -92,16 +91,14 @@ class IntellijMark(bookmark: LineBookmark, override val col: Int, project: Proje
override val protocol: String override val protocol: String
get() = getMark()?.file?.let { MarkGroup.extractProtocol(it) } ?: "" get() = getMark()?.file?.let { MarkGroup.extractProtocol(it) } ?: ""
override fun isClear(): Boolean = getMark() == null override fun isClear(): Boolean = getMark()?.isValid?.not() ?: false
override fun clear() { override fun clear() {
val mark = getMark() ?: return val mark = getMark() ?: return
getProject()?.let { project -> BookmarksManager.getInstance(project)?.remove(mark) } getProject()?.let { project -> BookmarkManager.getInstance(project).removeBookmark(mark) }
} }
private fun getMark(): LineBookmark? = private fun getMark(): Bookmark? =
getProject()?.let { getProject()?.let { project -> BookmarkManager.getInstance(project).findBookmarkForMnemonic(key) }
project -> BookmarksManager.getInstance(project)?.getBookmark(BookmarkType.get(key)) as? LineBookmark
}
private fun getProject(): Project? { private fun getProject(): Project? {
val proj = project.get() ?: return null val proj = project.get() ?: return null

View File

@ -18,10 +18,9 @@
package com.maddyhome.idea.vim.group; package com.maddyhome.idea.vim.group;
import com.intellij.ide.bookmark.BookmarkGroup; import com.intellij.ide.bookmarks.Bookmark;
import com.intellij.ide.bookmark.BookmarkType; import com.intellij.ide.bookmarks.BookmarkManager;
import com.intellij.ide.bookmark.BookmarksManager; import com.intellij.ide.bookmarks.BookmarksListener;
import com.intellij.ide.bookmark.LineBookmark;
import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.RoamingType; import com.intellij.openapi.components.RoamingType;
import com.intellij.openapi.components.State; import com.intellij.openapi.components.State;
@ -48,6 +47,7 @@ import com.maddyhome.idea.vim.helper.HelperKt;
import com.maddyhome.idea.vim.helper.SearchHelper; import com.maddyhome.idea.vim.helper.SearchHelper;
import com.maddyhome.idea.vim.vimscript.services.OptionService; import com.maddyhome.idea.vim.vimscript.services.OptionService;
import org.jdom.Element; import org.jdom.Element;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -221,7 +221,7 @@ public class MarkGroup implements PersistentStateComponent<Element> {
HashMap<Character, Mark> fmarks = getFileMarks(editor.getDocument()); HashMap<Character, Mark> fmarks = getFileMarks(editor.getDocument());
if (fmarks == null) return false; if (fmarks == null) return false;
@Nullable LineBookmark systemMark = SystemMarks.createOrGetSystemMark(ch, lp.line, editor); Bookmark systemMark = createOrGetSystemMark(ch, lp.line, editor);
Mark mark; Mark mark;
if (systemMark != null) { if (systemMark != null) {
mark = new IntellijMark(systemMark, lp.column, editor.getProject()); mark = new IntellijMark(systemMark, lp.column, editor.getProject());
@ -238,6 +238,22 @@ public class MarkGroup implements PersistentStateComponent<Element> {
return true; return true;
} }
private @Nullable Bookmark createOrGetSystemMark(char ch, int line, @NotNull Editor editor) {
if (!VimPlugin.getOptionService().isSet(new OptionService.Scope.LOCAL(editor), "ideamarks", "ideamarks")) return null;
final Project project = editor.getProject();
if (project == null) return null;
final BookmarkManager bookmarkManager = BookmarkManager.getInstance(project);
Bookmark bookmark = bookmarkManager.findBookmarkForMnemonic(ch);
if (bookmark != null && bookmark.getLine() == line) return bookmark;
final VirtualFile virtualFile = EditorHelper.getVirtualFile(editor);
if (virtualFile == null) return null;
bookmark = bookmarkManager.addTextBookmark(virtualFile, line, "");
bookmarkManager.setMnemonic(bookmark, ch);
return bookmark;
}
public static String extractProtocol(@NotNull VirtualFile vf) { public static String extractProtocol(@NotNull VirtualFile vf) {
return VirtualFileManager.extractProtocol(vf.getUrl()); return VirtualFileManager.extractProtocol(vf.getUrl());
} }
@ -730,56 +746,68 @@ public class MarkGroup implements PersistentStateComponent<Element> {
} }
} }
public static class VimBookmarksListener implements com.intellij.ide.bookmark.BookmarksListener { public static class MarkListener implements BookmarksListener {
private final Project myProject;
public VimBookmarksListener(Project project) { private final Project project;
myProject = project; private Bookmark bookmarkTemplate = null;
@Contract(pure = true)
public MarkListener(Project project) {
this.project = project;
} }
/**
* IJ has an interesting approach in mnemonic marks initialization. Firstly it creates an unnamed mark,
* then updates it. In general, it creates two events: one for creation and one for mnemonic set.
* However, when IJ starts and reads existing marks from caches, it creates marks with mnemonics already.
*/
@Override @Override
public void bookmarkAdded(@NotNull BookmarkGroup group, com.intellij.ide.bookmark.@NotNull Bookmark bookmark) { public void bookmarkAdded(@NotNull Bookmark b) {
if (!VimPlugin.isEnabled()) return; if (!VimPlugin.isEnabled()) return;
if (!VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL.INSTANCE, "ideamarks", "ideamarks")) return; if (!VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL.INSTANCE, "ideamarks", "ideamarks")) return;
if (b.getMnemonic() == '\u0000') {
if (!(bookmark instanceof LineBookmark)) return; bookmarkTemplate = b;
BookmarksManager bookmarksManager = BookmarksManager.getInstance(myProject); } else {
if (bookmarksManager == null) return; createVimMark(b);
BookmarkType type = bookmarksManager.getType(bookmark);
if (type == null) return;
char mnemonic = type.getMnemonic();
if (GLOBAL_MARKS.indexOf(mnemonic) == -1) return;
createVimMark((LineBookmark)bookmark, mnemonic);
}
@Override
public void bookmarkRemoved(@NotNull BookmarkGroup group, com.intellij.ide.bookmark.@NotNull Bookmark bookmark) {
if (!VimPlugin.isEnabled()) return;
if (!VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL.INSTANCE, "ideamarks", "ideamarks")) return;
if (!(bookmark instanceof LineBookmark)) return;
BookmarksManager bookmarksManager = BookmarksManager.getInstance(myProject);
if (bookmarksManager == null) return;
BookmarkType type = bookmarksManager.getType(bookmark);
if (type == null) return;
char ch = type.getMnemonic();
if (GLOBAL_MARKS.indexOf(ch) != -1) {
FileMarks<Character, Mark> fmarks = VimPlugin.getMark().getFileMarks(((LineBookmark)bookmark).getFile().getPath());
fmarks.remove(ch);
VimPlugin.getMark().globalMarks.remove(ch);
} }
} }
private void createVimMark(@NotNull LineBookmark b, char mnemonic) { @Override
int col = 0; public void bookmarkRemoved(@NotNull Bookmark b) {
Editor editor = EditorHelper.getEditor(b.getFile()); if (!VimPlugin.isEnabled()) return;
if (editor != null) col = editor.getCaretModel().getCurrentCaret().getLogicalPosition().column; if (!VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL.INSTANCE, "ideamarks", "ideamarks")) return;
IntellijMark mark = new IntellijMark(b, col, myProject);
FileMarks<Character, Mark> fmarks = VimPlugin.getMark().getFileMarks(b.getFile().getPath()); char ch = b.getMnemonic();
fmarks.put(mnemonic, mark); if (GLOBAL_MARKS.indexOf(ch) != -1) {
VimPlugin.getMark().globalMarks.put(mnemonic, mark); FileMarks<Character, Mark> fmarks = VimPlugin.getMark().getFileMarks(b.getFile().getPath());
fmarks.remove(ch);
VimPlugin.getMark().globalMarks.remove(ch);
// No need to call mark.clear()
}
}
@Override
public void bookmarkChanged(@NotNull Bookmark b) {
if (!VimPlugin.isEnabled()) return;
/* IJ sets named marks in two steps. Firstly it creates an unnamed mark, then adds a mnemonic */
if (!VimPlugin.getOptionService().isSet(OptionService.Scope.GLOBAL.INSTANCE, "ideamarks", "ideamarks")) return;
if (b != bookmarkTemplate) return;
bookmarkTemplate = null;
createVimMark(b);
}
private void createVimMark(@NotNull Bookmark b) {
char ch = b.getMnemonic();
if (GLOBAL_MARKS.indexOf(ch) != -1) {
int col = 0;
Editor editor = EditorHelper.getEditor(b.getFile());
if (editor != null) col = editor.getCaretModel().getCurrentCaret().getLogicalPosition().column;
IntellijMark mark = new IntellijMark(b, col, project);
FileMarks<Character, Mark> fmarks = VimPlugin.getMark().getFileMarks(b.getFile().getPath());
fmarks.put(ch, mark);
VimPlugin.getMark().globalMarks.put(ch, mark);
}
} }
} }

View File

@ -1,90 +0,0 @@
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*
* IdeaVim - Vim emulator for IDEs based on the IntelliJ platform
* Copyright (C) 2003-2021 The IdeaVim authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.maddyhome.idea.vim.group
import com.intellij.ide.bookmark.Bookmark
import com.intellij.ide.bookmark.BookmarkType
import com.intellij.ide.bookmark.BookmarksManager
import com.intellij.ide.bookmark.LineBookmark
import com.intellij.ide.bookmark.providers.LineBookmarkProvider
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.vimscript.services.OptionService.Scope.LOCAL
class SystemMarks {
companion object {
@JvmStatic
fun createOrGetSystemMark(ch: Char, line: Int, editor: Editor): LineBookmark? {
if (!VimPlugin.getOptionService().isSet(LOCAL(editor), "ideamarks", "ideamarks")) return null
val project = editor.project ?: return null
val type = BookmarkType.get(ch)
if (type == BookmarkType.DEFAULT) return null
val bookmarksManager = BookmarksManager.getInstance(project) ?: return null
val foundBookmark = bookmarksManager.getBookmark(type)
if (foundBookmark != null) {
if (foundBookmark is LineBookmark && foundBookmark.line == line) {
return foundBookmark
}
bookmarksManager.remove(foundBookmark)
}
return project.createLineBookmark(editor, line, ch)
}
}
}
internal fun Project.createLineBookmark(editor: Editor, line: Int, mnemonic: Char): LineBookmark? {
val bookmarksManager = BookmarksManager.getInstance(this) ?: return null
val lineBookmarkProvider = LineBookmarkProvider.find(this) ?: return null
val bookmark = lineBookmarkProvider.createBookmark(editor, line) as LineBookmark? ?: return null
val type = BookmarkType.get(mnemonic)
if (type == BookmarkType.DEFAULT) return null
val group = bookmarksManager.defaultGroup ?: bookmarksManager.addGroup("IdeaVim", true) ?: return null
if (group.canAdd(bookmark)) {
group.add(bookmark, type)
return bookmark
}
return null
}
internal fun Bookmark.mnemonic(project: Project?): Char {
return BookmarksManager.getInstance(project)?.getType(this)!!.mnemonic
}

View File

@ -18,8 +18,8 @@
<listener class="com.maddyhome.idea.vim.listener.IdeaSpecifics$VimTemplateManagerListener" <listener class="com.maddyhome.idea.vim.listener.IdeaSpecifics$VimTemplateManagerListener"
topic="com.intellij.codeInsight.template.TemplateManagerListener"/> topic="com.intellij.codeInsight.template.TemplateManagerListener"/>
<listener class="com.maddyhome.idea.vim.group.MarkGroup$VimBookmarksListener" <listener class="com.maddyhome.idea.vim.group.MarkGroup$MarkListener"
topic="com.intellij.ide.bookmark.BookmarksListener"/> topic="com.intellij.ide.bookmarks.BookmarksListener"/>
<listener class="com.maddyhome.idea.vim.listener.IdeaSpecifics$VimFindModelListener" <listener class="com.maddyhome.idea.vim.listener.IdeaSpecifics$VimFindModelListener"
topic="com.intellij.find.FindModelListener"/> topic="com.intellij.find.FindModelListener"/>

View File

@ -76,7 +76,7 @@
<!-- Please search for "[VERSION UPDATE]" in project in case you update the since-build version --> <!-- Please search for "[VERSION UPDATE]" in project in case you update the since-build version -->
<!-- Check for [Version Update] tag in YouTrack as well --> <!-- Check for [Version Update] tag in YouTrack as well -->
<idea-version since-build="213"/> <idea-version since-build="203"/>
<!-- Mark the plugin as compatible with RubyMine and other products based on the IntelliJ platform (including CWM) --> <!-- Mark the plugin as compatible with RubyMine and other products based on the IntelliJ platform (including CWM) -->
<depends>com.intellij.modules.platform</depends> <depends>com.intellij.modules.platform</depends>

View File

@ -17,7 +17,8 @@
*/ */
package org.jetbrains.plugins.ideavim package org.jetbrains.plugins.ideavim
import com.intellij.ide.bookmark.BookmarksManager import com.intellij.ide.bookmarks.Bookmark
import com.intellij.ide.bookmarks.BookmarkManager
import com.intellij.ide.highlighter.JavaFileType import com.intellij.ide.highlighter.JavaFileType
import com.intellij.ide.highlighter.XmlFileType import com.intellij.ide.highlighter.XmlFileType
import com.intellij.json.JsonFileType import com.intellij.json.JsonFileType
@ -77,6 +78,7 @@ import com.maddyhome.idea.vim.vimscript.services.OptionService
import com.maddyhome.idea.vim.vimscript.services.VariableServiceImpl import com.maddyhome.idea.vim.vimscript.services.VariableServiceImpl
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions
import org.junit.Assert import org.junit.Assert
import java.util.function.Consumer
import javax.swing.KeyStroke import javax.swing.KeyStroke
/** /**
@ -127,10 +129,8 @@ abstract class VimTestCase : UsefulTestCase() {
override fun tearDown() { override fun tearDown() {
val swingTimer = swingTimer val swingTimer = swingTimer
swingTimer?.stop() swingTimer?.stop()
val bookmarksManager = BookmarksManager.getInstance(myFixture.project) val bookmarkManager = BookmarkManager.getInstance(myFixture.project)
bookmarksManager?.bookmarks?.forEach { bookmark -> bookmarkManager.validBookmarks.forEach(Consumer { bookmark: Bookmark? -> bookmarkManager.removeBookmark(bookmark!!) })
bookmarksManager.remove(bookmark)
}
SelectionVimListenerSuppressor.lock().use { myFixture.tearDown() } SelectionVimListenerSuppressor.lock().use { myFixture.tearDown() }
ExEntryPanel.getInstance().deactivate(false) ExEntryPanel.getInstance().deactivate(false)
(VimPlugin.getVariableService() as VariableServiceImpl).clear() (VimPlugin.getVariableService() as VariableServiceImpl).clear()

View File

@ -18,12 +18,8 @@
package org.jetbrains.plugins.ideavim.action.motion.mark package org.jetbrains.plugins.ideavim.action.motion.mark
import com.intellij.ide.bookmark.BookmarksManager import com.intellij.ide.bookmarks.BookmarkManager
import com.intellij.ide.bookmark.LineBookmark
import com.intellij.testFramework.PlatformTestUtil
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.group.createLineBookmark
import com.maddyhome.idea.vim.group.mnemonic
import com.maddyhome.idea.vim.helper.StringHelper import com.maddyhome.idea.vim.helper.StringHelper
import com.maddyhome.idea.vim.option.IdeaMarksOptionsData import com.maddyhome.idea.vim.option.IdeaMarksOptionsData
import junit.framework.TestCase import junit.framework.TestCase
@ -31,6 +27,7 @@ import org.jetbrains.plugins.ideavim.OptionValueType
import org.jetbrains.plugins.ideavim.VimOptionTestCase import org.jetbrains.plugins.ideavim.VimOptionTestCase
import org.jetbrains.plugins.ideavim.VimOptionTestConfiguration import org.jetbrains.plugins.ideavim.VimOptionTestConfiguration
import org.jetbrains.plugins.ideavim.VimTestOption import org.jetbrains.plugins.ideavim.VimTestOption
import org.junit.Ignore
class MotionMarkActionTest : VimOptionTestCase(IdeaMarksOptionsData.name) { class MotionMarkActionTest : VimOptionTestCase(IdeaMarksOptionsData.name) {
@VimOptionTestConfiguration(VimTestOption(IdeaMarksOptionsData.name, OptionValueType.NUMBER, "1")) @VimOptionTestConfiguration(VimTestOption(IdeaMarksOptionsData.name, OptionValueType.NUMBER, "1"))
@ -78,10 +75,7 @@ class MotionMarkActionTest : VimOptionTestCase(IdeaMarksOptionsData.name) {
""".trimIndent() """.trimIndent()
configureByText(text) configureByText(text)
typeText(keys) typeText(keys)
checkMarks('A' to 2) checkMarks('A' to 2, 'B' to 2, 'C' to 2)
// Previously it was like this, but now it's impossible to set multiple bookmarks on the same line.
// checkMarks('A' to 2, 'B' to 2, 'C' to 2)
} }
@VimOptionTestConfiguration(VimTestOption(IdeaMarksOptionsData.name, OptionValueType.NUMBER, "1")) @VimOptionTestConfiguration(VimTestOption(IdeaMarksOptionsData.name, OptionValueType.NUMBER, "1"))
@ -111,8 +105,34 @@ class MotionMarkActionTest : VimOptionTestCase(IdeaMarksOptionsData.name) {
hard by the torrent of a mountain pass. hard by the torrent of a mountain pass.
""".trimIndent() """.trimIndent()
configureByText(text) configureByText(text)
myFixture.project.createLineBookmark(myFixture.editor, 2, 'A') val bookmarkManager = BookmarkManager.getInstance(myFixture.project)
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue() bookmarkManager.addEditorBookmark(myFixture.editor, 2)
val bookmark = bookmarkManager.findEditorBookmark(myFixture.editor.document, 2) ?: kotlin.test.fail()
bookmarkManager.setMnemonic(bookmark, 'A')
val vimMarks = VimPlugin.getMark().getMarks(myFixture.editor)
TestCase.assertEquals(1, vimMarks.size)
TestCase.assertEquals('A', vimMarks[0].key)
}
@VimOptionTestConfiguration(VimTestOption(IdeaMarksOptionsData.name, OptionValueType.NUMBER, "1"))
@Ignore("Probably one day it would be possible to test it")
fun `ignoretest apply new state`() {
val text = """
A Discovery
I ${c}found it in a legendary land
all rocks and lavender and tufted grass,
where it was settled on some sodden sand
hard by the torrent of a mountain pass.
""".trimIndent()
configureByText(text)
val bookmarkManager = BookmarkManager.getInstance(myFixture.project)
bookmarkManager.addEditorBookmark(myFixture.editor, 2)
val bookmark = bookmarkManager.findEditorBookmark(myFixture.editor.document, 2) ?: kotlin.test.fail()
bookmark.mnemonic = 'A'
bookmarkManager.applyNewStateInTestMode(listOf(bookmark))
val vimMarks = VimPlugin.getMark().getMarks(myFixture.editor) val vimMarks = VimPlugin.getMark().getMarks(myFixture.editor)
TestCase.assertEquals(1, vimMarks.size) TestCase.assertEquals(1, vimMarks.size)
TestCase.assertEquals('A', vimMarks[0].key) TestCase.assertEquals('A', vimMarks[0].key)
@ -129,12 +149,15 @@ class MotionMarkActionTest : VimOptionTestCase(IdeaMarksOptionsData.name) {
hard by the torrent of a mountain pass. hard by the torrent of a mountain pass.
""".trimIndent() """.trimIndent()
configureByText(text) configureByText(text)
var bookmarkManager = BookmarkManager.getInstance(myFixture.project)
bookmarkManager.addEditorBookmark(myFixture.editor, 2)
var bookmark = bookmarkManager.findEditorBookmark(myFixture.editor.document, 2) ?: kotlin.test.fail()
bookmarkManager.setMnemonic(bookmark, 'A')
val bookmark = myFixture.project.createLineBookmark(myFixture.editor, 2, 'A') bookmarkManager = BookmarkManager.getInstance(myFixture.project)
bookmarkManager.addEditorBookmark(myFixture.editor, 4)
BookmarksManager.getInstance(myFixture.project)?.remove(bookmark!!) bookmark = bookmarkManager.findEditorBookmark(myFixture.editor.document, 4) ?: kotlin.test.fail()
myFixture.project.createLineBookmark(myFixture.editor, 4, 'A') bookmarkManager.setMnemonic(bookmark, 'A')
PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
val vimMarks = VimPlugin.getMark().getMarks(myFixture.editor) val vimMarks = VimPlugin.getMark().getMarks(myFixture.editor)
TestCase.assertEquals(1, vimMarks.size) TestCase.assertEquals(1, vimMarks.size)
TestCase.assertEquals('A', vimMarks[0].key) TestCase.assertEquals('A', vimMarks[0].key)
@ -142,12 +165,11 @@ class MotionMarkActionTest : VimOptionTestCase(IdeaMarksOptionsData.name) {
} }
private fun checkMarks(vararg marks: Pair<Char, Int>) { private fun checkMarks(vararg marks: Pair<Char, Int>) {
val project = myFixture.project val validBookmarks = BookmarkManager.getInstance(myFixture.project).validBookmarks
val validBookmarks = BookmarksManager.getInstance(project)!!.bookmarks.sortedBy { it.mnemonic(project) }
assertEquals(marks.size, validBookmarks.size) assertEquals(marks.size, validBookmarks.size)
marks.sortedBy { it.first }.forEachIndexed { index, (mn, line) -> marks.forEachIndexed { index, (mn, line) ->
assertEquals(mn, validBookmarks[index].mnemonic(project)) assertEquals(mn, validBookmarks[marks.size - index - 1].mnemonic)
assertEquals(line, (validBookmarks[index] as LineBookmark).line) assertEquals(line, validBookmarks[marks.size - index - 1].line)
} }
} }
} }

View File

@ -18,7 +18,6 @@
package org.jetbrains.plugins.ideavim.ex.implementation.commands package org.jetbrains.plugins.ideavim.ex.implementation.commands
import com.intellij.openapi.editor.LogicalPosition
import com.maddyhome.idea.vim.VimPlugin import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.common.Mark import com.maddyhome.idea.vim.common.Mark
import org.jetbrains.plugins.ideavim.VimTestCase import org.jetbrains.plugins.ideavim.VimTestCase
@ -35,22 +34,11 @@ class DeleteMarksCommandTest : VimTestCase() {
all rocks and lavender and tufted grass, all rocks and lavender and tufted grass,
where it was settled on some sodden sand where it was settled on some sodden sand
hard by the torrent of a mountain pass. hard by the torrent of a mountain pass.
The features it combines mark it as new
to science: shape and shade -- the special tinge,
akin to moonlight, tempering its blue,
the dingy underside, the checquered fringe.
My needles have teased out its sculpted sex;
corroded tissues could no longer hide
that priceless mote now dimpling the convex
and limpid teardrop on a lighted slide.
""".trimMargin() """.trimMargin()
) )
marks.forEachIndexed { index, c -> marks.forEachIndexed { index, c ->
VimPlugin.getMark() VimPlugin.getMark().setMark(myFixture.editor, c, index * 10)
.setMark(myFixture.editor, c, myFixture.editor.logicalPositionToOffset(LogicalPosition(index, 0)))
} }
} }