Skip to content

Commit

Permalink
Use null instead of -1 when the version of IdeaVim is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPl292 committed Feb 3, 2025
1 parent 4fc2c1e commit 62ed920
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions src/main/java/com/maddyhome/idea/vim/config/VimState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -57,7 +53,7 @@ internal class VimState {
}

private val map by lazy { mutableMapOf<String, Boolean>() }
private val stringMap by lazy { mutableMapOf<String, String>() }
private val stringMap by lazy { mutableMapOf<String, String?>() }

private class StateProperty(val xmlName: String) : ReadWriteProperty<VimState, Boolean> {

Expand All @@ -72,16 +68,17 @@ private class StateProperty(val xmlName: String) : ReadWriteProperty<VimState, B
}
}

private class StringProperty(val propertyName: String, val defaultValue: String) : ReadWriteProperty<VimState, String> {
private class StringProperty(val propertyName: String, val defaultValue: String?) : ReadWriteProperty<VimState, String?> {

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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 62ed920

Please sign in to comment.