From b0261442543a263eb527e27bcc0310d540c1ae56 Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Fri, 15 Nov 2024 20:53:54 +0200 Subject: [PATCH] Add RWLock label to `selectionStart` & `selectionEnd` --- .../kotlin/com/maddyhome/idea/vim/api/VimCaret.kt | 3 +++ .../idea/vim/group/visual/EngineVisualGroup.kt | 12 ++++++++++-- .../com/maddyhome/idea/vim/helper/RWLockLabel.kt | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCaret.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCaret.kt index 2e477ccc00..de189851c1 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCaret.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimCaret.kt @@ -14,6 +14,7 @@ import com.maddyhome.idea.vim.group.visual.VisualChange import com.maddyhome.idea.vim.group.visual.vimMoveBlockSelectionToOffset import com.maddyhome.idea.vim.group.visual.vimMoveSelectionToCaret import com.maddyhome.idea.vim.handler.Motion +import com.maddyhome.idea.vim.helper.RWLockLabel import com.maddyhome.idea.vim.helper.StrictMode import com.maddyhome.idea.vim.helper.exitVisualMode import com.maddyhome.idea.vim.register.Register @@ -40,7 +41,9 @@ interface ImmutableVimCaret { val isValid: Boolean val isPrimary: Boolean + @RWLockLabel.Readonly val selectionStart: Int + @RWLockLabel.Readonly val selectionEnd: Int val vimSelectionStart: Int diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/group/visual/EngineVisualGroup.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/group/visual/EngineVisualGroup.kt index 04c32a331c..d69b7b6b5d 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/group/visual/EngineVisualGroup.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/group/visual/EngineVisualGroup.kt @@ -8,8 +8,15 @@ package com.maddyhome.idea.vim.group.visual -import com.maddyhome.idea.vim.api.* -import com.maddyhome.idea.vim.helper.* +import com.maddyhome.idea.vim.api.ImmutableVimCaret +import com.maddyhome.idea.vim.api.VimCaret +import com.maddyhome.idea.vim.api.VimEditor +import com.maddyhome.idea.vim.api.VimMotionGroupBase +import com.maddyhome.idea.vim.api.VimVisualPosition +import com.maddyhome.idea.vim.api.getLineEndOffset +import com.maddyhome.idea.vim.api.injector +import com.maddyhome.idea.vim.api.isLineEmpty +import com.maddyhome.idea.vim.helper.RWLockLabel import com.maddyhome.idea.vim.state.mode.Mode import com.maddyhome.idea.vim.state.mode.SelectionType import com.maddyhome.idea.vim.state.mode.inBlockSelection @@ -135,6 +142,7 @@ fun VimCaret.vimUpdateEditorSelection() { /** * This works almost like [Caret.getLeadSelectionOffset] in IJ, but vim-specific */ +@RWLockLabel.Readonly val ImmutableVimCaret.vimLeadSelectionOffset: Int get() { val caretOffset = offset diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/helper/RWLockLabel.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/helper/RWLockLabel.kt index e8b172eb5e..5d21a7d029 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/helper/RWLockLabel.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/helper/RWLockLabel.kt @@ -17,7 +17,7 @@ annotation class RWLockLabel { * [Readonly] annotation means that annotated function should be called from read action * This annotation is only a marker and doesn't enable r/w lock automatically */ - @Target(AnnotationTarget.FUNCTION) + @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) annotation class Readonly /**