Skip to content

Commit

Permalink
Prepare to changing the default value of the undo
Browse files Browse the repository at this point in the history
A notification added to give the information about what happened

Related: VIM-547
  • Loading branch information
AlexPl292 committed Jul 15, 2024
1 parent 3465e11 commit fb08b5f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
9 changes: 8 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ intellijPlatform {
pluginConfiguration {
name = "IdeaVim"
changeNotes.set(
"""<a href="https://youtrack.jetbrains.com/issues/VIM?q=State:%20Fixed%20Fix%20versions:%20${version.get()}">Changelog</a>"""
"""
Undo in IdeaVim now works like in Vim<br/>
Caret movement is no longer a separate undo step, and full insert is undoable in one step.<br/>
<a href="https://youtrack.jetbrains.com/issue/VIM-547/Undo-splits-Insert-mode-edits-into-separate-undo-chunks">Share Feedback</a>
<br/>
<br/>
<a href="https://youtrack.jetbrains.com/issues/VIM?q=State:%20Fixed%20Fix%20versions:%20${version.get()}">Changelog</a>
""".trimIndent()
)

ideaVersion {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/maddyhome/idea/vim/config/VimState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlin.reflect.KProperty
internal class VimState {
var isIdeaJoinNotified by StateProperty("idea-join")
var isIdeaPutNotified by StateProperty("idea-put")
var isNewUndoNotified by StateProperty("idea-undo")

fun readData(element: Element) {
val notifications = element.getChild("notifications")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/maddyhome/idea/vim/group/IjOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ object IjOptions {
// Temporary feature flags during development, not really intended for external use
val closenotebooks: ToggleOption = addOption(ToggleOption("closenotebooks", GLOBAL, "closenotebooks", true, isHidden = true))
val commandOrMotionAnnotation: ToggleOption = addOption(ToggleOption("commandormotionannotation", GLOBAL, "commandormotionannotation", true, isHidden = true))
val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", true, isHidden = true))
val oldundo: ToggleOption = addOption(ToggleOption("oldundo", GLOBAL, "oldundo", false, isHidden = true))
val unifyjumps: ToggleOption = addOption(ToggleOption("unifyjumps", GLOBAL, "unifyjumps", true, isHidden = true))
val vimscriptFunctionAnnotation: ToggleOption = addOption(ToggleOption("vimscriptfunctionannotation", GLOBAL, "vimscriptfunctionannotation", true, isHidden = true))

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/maddyhome/idea/vim/group/NotificationService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ internal class NotificationService(private val project: Project?) {
@Suppress("unused")
constructor() : this(null)

fun notifyAboutNewUndo() {
val notification = Notification(
IDEAVIM_NOTIFICATION_ID,
"IdeaVim undo now works like Vim undo",
"""
Caret movement is no more a separate undo step and full insert is undoable in one step
""".trimIndent(),
NotificationType.INFORMATION,
)

notification.addAction(object : DumbAwareAction("Share Feedback") {
override fun actionPerformed(p0: AnActionEvent) {
BrowserUtil.browse("https://youtrack.jetbrains.com/issue/VIM-547/Undo-splits-Insert-mode-edits-into-separate-undo-chunks")
}
})

notification.notify(project)
}

fun notifyAboutIdeaPut() {
val notification = Notification(
IDEAVIM_NOTIFICATION_ID,
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/maddyhome/idea/vim/helper/UndoRedoHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.registry.Registry
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.ChangesListener
import com.maddyhome.idea.vim.newapi.IjVimCaret
import com.maddyhome.idea.vim.common.InsertSequence
import com.maddyhome.idea.vim.newapi.IjVimCaret
import com.maddyhome.idea.vim.newapi.globalIjOptions
import com.maddyhome.idea.vim.newapi.ij
import com.maddyhome.idea.vim.undo.UndoRedoBase
Expand Down Expand Up @@ -75,6 +77,7 @@ internal class UndoRedoHelper : UndoRedoBase() {
removeSelections(editor)
}
} else {
notifyAboutNewUndo(editor.ij.project)
runWithBooleanRegistryOption("ide.undo.transparent.caret.movement", true) {
var nextUndoNanoTime = undoManager.getNextUndoNanoTime(fileEditor)
val insertInfo = (editor.primaryCaret() as IjVimCaret).getInsertSequenceForTime(nextUndoNanoTime)
Expand All @@ -95,6 +98,13 @@ internal class UndoRedoHelper : UndoRedoBase() {
}
}

private fun notifyAboutNewUndo(project: Project?) {
if (VimPlugin.getVimState().isNewUndoNotified) return
VimPlugin.getVimState().isNewUndoNotified = true

VimPlugin.getNotifications(project).notifyAboutNewUndo()
}

private fun hasSelection(editor: VimEditor): Boolean {
return editor.primaryCaret().ij.hasSelection()
}
Expand Down

0 comments on commit fb08b5f

Please sign in to comment.