Skip to content

Commit

Permalink
Merge pull request #308 from citizenmatt/VIM-2308
Browse files Browse the repository at this point in the history
Fix unnecessary caret movement when switching tabs
  • Loading branch information
AlexPl292 authored May 24, 2021
2 parents e21e1b0 + 0bde71d commit 5a85565
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 43 deletions.
6 changes: 4 additions & 2 deletions resources/META-INF/includes/VimActions.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<idea-plugin>
<extensions defaultExtensionNs="IdeaVIM">
<!-- Motions -->
<vimAction implementation="com.maddyhome.idea.vim.action.motion.tabs.MotionPreviousTabAction" mappingModes="NXO" keys="gT"/>
<vimAction implementation="com.maddyhome.idea.vim.action.motion.tabs.MotionNextTabAction" mappingModes="NXO" keys="gt"/>
<!-- Left/Right -->
<vimAction implementation="com.maddyhome.idea.vim.action.motion.leftright.MotionColumnAction" mappingModes="NXO" keys="|"/>
<vimAction implementation="com.maddyhome.idea.vim.action.motion.leftright.MotionFirstColumnAction" mappingModes="NXO" keys="0"/>
Expand Down Expand Up @@ -295,6 +293,10 @@
<vimAction implementation="com.maddyhome.idea.vim.action.window.WindowUpAction" mappingModes="N" keys="«C-W»k,«C-W»«C-K»,«C-W»«Up»"/>
<vimAction implementation="com.maddyhome.idea.vim.action.window.WindowDownAction" mappingModes="N" keys="«C-W»j,«C-W»«C-J»,«C-W»«Down»"/>

<!-- Tabs -->
<vimAction implementation="com.maddyhome.idea.vim.action.window.tabs.NextTabAction" mappingModes="NXO" keys="gt"/>
<vimAction implementation="com.maddyhome.idea.vim.action.window.tabs.PreviousTabAction" mappingModes="NXO" keys="gT"/>

<!-- Search -->
<vimAction implementation="com.maddyhome.idea.vim.action.motion.search.SearchEntryFwdAction" mappingModes="NXO" keys="/"/>
<vimAction implementation="com.maddyhome.idea.vim.action.motion.search.SearchEntryRevAction" mappingModes="NXO" keys="?"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,19 @@
* 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.action.motion.tabs
package com.maddyhome.idea.vim.action.window.tabs

import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.MotionType
import com.maddyhome.idea.vim.handler.Motion
import com.maddyhome.idea.vim.handler.MotionActionHandler
import com.maddyhome.idea.vim.handler.toMotionOrError
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.handler.VimActionHandler

/**
* @author oleg
*/
class MotionNextTabAction : MotionActionHandler.SingleExecution() {
override fun getOffset(
editor: Editor,
context: DataContext,
count: Int,
rawCount: Int,
argument: Argument?,
): Motion {
return VimPlugin.getMotion().moveCaretGotoNextTab(editor, context, rawCount).toMotionOrError()
class NextTabAction : VimActionHandler.SingleExecution() {
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
VimPlugin.getMotion().moveCaretGotoNextTab(editor, context, cmd.rawCount)
return true
}

override val motionType: MotionType = MotionType.INCLUSIVE
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,19 @@
* 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.action.motion.tabs
package com.maddyhome.idea.vim.action.window.tabs

import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.Argument
import com.maddyhome.idea.vim.command.MotionType
import com.maddyhome.idea.vim.handler.Motion
import com.maddyhome.idea.vim.handler.MotionActionHandler
import com.maddyhome.idea.vim.handler.toMotionOrError
import com.maddyhome.idea.vim.command.Command
import com.maddyhome.idea.vim.handler.VimActionHandler

/**
* @author oleg
*/
class MotionPreviousTabAction : MotionActionHandler.SingleExecution() {
override fun getOffset(
editor: Editor,
context: DataContext,
count: Int,
rawCount: Int,
argument: Argument?,
): Motion {
return VimPlugin.getMotion().moveCaretGotoPreviousTab(editor, context, rawCount).toMotionOrError()
class PreviousTabAction : VimActionHandler.SingleExecution() {
override fun execute(editor: Editor, context: DataContext, cmd: Command): Boolean {
VimPlugin.getMotion().moveCaretGotoPreviousTab(editor, context, cmd.rawCount)
return true
}

override val motionType: MotionType = MotionType.INCLUSIVE
override val type: Command.Type = Command.Type.OTHER_SELF_SYNCHRONIZED
}
4 changes: 2 additions & 2 deletions src/com/maddyhome/idea/vim/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
* |gP| {@link com.maddyhome.idea.vim.action.copy.PutTextBeforeCursorActionMoveCursor}
* |gQ| TO BE IMPLEMENTED
* |gR| TO BE IMPLEMENTED
* |gT| {@link com.maddyhome.idea.vim.action.motion.tabs.MotionPreviousTabAction}
* |gT| {@link com.maddyhome.idea.vim.action.window.tabs.PreviousTabAction}
* |gU| {@link com.maddyhome.idea.vim.action.change.change.ChangeCaseUpperMotionAction}
* |gV| TO BE IMPLEMENTED
* |g]| TO BE IMPLEMENTED
Expand All @@ -434,7 +434,7 @@
* |gq| {@link com.maddyhome.idea.vim.action.change.change.ReformatCodeMotionAction}
* |gr| TO BE IMPLEMENTED
* |gs| TO BE IMPLEMENTED
* |gt| {@link com.maddyhome.idea.vim.action.motion.tabs.MotionNextTabAction}
* |gt| {@link com.maddyhome.idea.vim.action.window.tabs.NextTabAction}
* |gu| {@link com.maddyhome.idea.vim.action.change.change.ChangeCaseLowerMotionAction}
* |gv| {@link com.maddyhome.idea.vim.action.motion.visual.VisualSelectPreviousAction}
* |gw| TO BE IMPLEMENTED
Expand Down
2 changes: 1 addition & 1 deletion test/org/jetbrains/plugins/ideavim/RegisterActionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class RegisterActionsTest : VimTestCase() {
val after = "I f${c}ound it in a legendary land"
var motionRightAction: ActionBeanClass? = null
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE) {
motionRightAction = VIM_ACTIONS_EP.extensions().findAny().get()
motionRightAction = VIM_ACTIONS_EP.extensions().filter { it.actionId == "VimPreviousTabAction" }.findFirst().get()

assertNotNull(getCommandNode())

Expand Down

0 comments on commit 5a85565

Please sign in to comment.