From 62ed920363dfc69db50136a88463a3ebca2eef27 Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Mon, 3 Feb 2025 11:05:17 +0200 Subject: [PATCH] Use null instead of -1 when the version of IdeaVim is not set --- .../com/maddyhome/idea/vim/config/VimState.kt | 17 +++++++---------- .../maddyhome/idea/vim/newapi/IjVimEnabler.kt | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/maddyhome/idea/vim/config/VimState.kt b/src/main/java/com/maddyhome/idea/vim/config/VimState.kt index 5ac3f6f62d..21a3f72940 100644 --- a/src/main/java/com/maddyhome/idea/vim/config/VimState.kt +++ b/src/main/java/com/maddyhome/idea/vim/config/VimState.kt @@ -19,11 +19,7 @@ internal class VimState { var isIdeaJoinNotified by StateProperty("idea-join") var isIdeaPutNotified by StateProperty("idea-put") var wasSubscribedToEAPAutomatically by StateProperty("was-automatically-subscribed-to-eap") - - /** - * First logged version of IdeaVim, or "-1" if no version logged - */ - var firstIdeaVimVersion: String by StringProperty("first-ideavim-version", "-1") + var firstIdeaVimVersion: String? by StringProperty("first-ideavim-version", null) fun readData(element: Element) { val notifications = element.getChild("notifications") @@ -57,7 +53,7 @@ internal class VimState { } private val map by lazy { mutableMapOf() } -private val stringMap by lazy { mutableMapOf() } +private val stringMap by lazy { mutableMapOf() } private class StateProperty(val xmlName: String) : ReadWriteProperty { @@ -72,16 +68,17 @@ private class StateProperty(val xmlName: String) : ReadWriteProperty { +private class StringProperty(val propertyName: String, val defaultValue: String?) : ReadWriteProperty { init { stringMap[propertyName] = defaultValue } - override fun getValue(thisRef: VimState, property: KProperty<*>): String = - stringMap.getOrPut(propertyName) { defaultValue } + override fun getValue(thisRef: VimState, property: KProperty<*>): String? { + return stringMap.getOrPut(propertyName) { defaultValue } + } - override fun setValue(thisRef: VimState, property: KProperty<*>, value: String) { + override fun setValue(thisRef: VimState, property: KProperty<*>, value: String?) { stringMap[propertyName] = value } } diff --git a/src/main/java/com/maddyhome/idea/vim/newapi/IjVimEnabler.kt b/src/main/java/com/maddyhome/idea/vim/newapi/IjVimEnabler.kt index 659c21b7d2..d564d408fc 100644 --- a/src/main/java/com/maddyhome/idea/vim/newapi/IjVimEnabler.kt +++ b/src/main/java/com/maddyhome/idea/vim/newapi/IjVimEnabler.kt @@ -24,7 +24,7 @@ internal class IjVimEnabler : VimEnabler { fun ideOpened() { val myFirstVersion = VimPlugin.getVimState().firstIdeaVimVersion - if (myFirstVersion == "-1") { + if (myFirstVersion == null) { VimPlugin.getVimState().firstIdeaVimVersion = VimPlugin.getVersion() this.isNewUser = true }