ideavim icon indicating copy to clipboard operation
ideavim copied to clipboard

Fix vim-surround not working with multiple cursors

Open chylex opened this issue 3 years ago • 1 comments

Fixes multiple cursors with vim-surround commands cs, ds, S (but not ys).

https://user-images.githubusercontent.com/3685160/174427769-e523bc89-0040-46f1-98d3-ae8f628df4a5.mp4

I don't know if this is a good solution and there likely edge cases that break it, but I use multiple cursors every day and having at least some solution that makes vim-surround work in most cases is better than having it not work at all.

Unfortunately I have not figured out how to make ys work (I didn't even know that particular command existed until I looked at the source).

If you know of a better overall solution and/or a way to make ys work too, I'd be happy to improve this.

I also haven't added unit tests yet. I'm opening it as a draft for discussion, if / once you are happy with the implementation I will write some tests before it's merged in.

chylex avatar Jun 18 '22 07:06 chylex

I've rebased the commit on master to remove the changes from the second merged PR.

@lippfi could you please check if your work on making per-caret registers will fix this issue?

AlexPl292 avatar Jun 24 '22 05:06 AlexPl292

I tested multiple cursors in current master (da3d83ecc62e01b1ff14e25ad1770668a05379b4):

  • cs and ds work
  • S does not work
  • ys throws, not sure why, could be something on my end:
java.lang.NoSuchMethodError: 'boolean com.maddyhome.idea.vim.key.OperatorFunction.apply(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext, com.maddyhome.idea.vim.command.SelectionType)'
	at com.maddyhome.idea.vim.action.change.OperatorActionKt.doOperatorAction(OperatorAction.kt:53)
	at com.maddyhome.idea.vim.action.change.OperatorActionKt.access$doOperatorAction(OperatorAction.kt:1)
	at com.maddyhome.idea.vim.action.change.OperatorAction.execute(OperatorAction.kt:76)
	at com.maddyhome.idea.vim.handler.VimActionHandler.baseExecute(VimActionHandler.kt:97)
	at com.maddyhome.idea.vim.handler.EditorActionHandlerBase.doExecute(EditorActionHandlerBase.kt:96)
	at com.maddyhome.idea.vim.handler.EditorActionHandlerBase.access$doExecute(EditorActionHandlerBase.kt:53)
	at com.maddyhome.idea.vim.handler.EditorActionHandlerBase$execute$action$1.invoke(EditorActionHandlerBase.kt:78)
	at com.maddyhome.idea.vim.handler.EditorActionHandlerBase$execute$action$1.invoke(EditorActionHandlerBase.kt:78)
	at com.maddyhome.idea.vim.handler.EditorActionHandlerBase.execute(EditorActionHandlerBase.kt:82)
	at com.maddyhome.idea.vim.helper.IjActionExecutor.executeVimAction$lambda-2(IjActionExecutor.kt:176)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:210)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:174)
	at com.maddyhome.idea.vim.helper.IjActionExecutor.executeVimAction(IjActionExecutor.kt:174)
	at com.maddyhome.idea.vim.KeyHandler$ActionRunner.run(KeyHandler.kt:874)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:219)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:174)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:164)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:150)
	at com.maddyhome.idea.vim.helper.IjActionExecutor.executeCommand(IjActionExecutor.kt:160)
	at com.maddyhome.idea.vim.KeyHandler.executeCommand(KeyHandler.kt:689)
	at com.maddyhome.idea.vim.KeyHandler.finishedCommandPreparation(KeyHandler.kt:203)
	at com.maddyhome.idea.vim.KeyHandler.handleKey(KeyHandler.kt:189)
	at com.maddyhome.idea.vim.KeyHandler.handleAbandonedMappingSequence(KeyHandler.kt:481)
	at com.maddyhome.idea.vim.KeyHandler.handleKeyMapping(KeyHandler.kt:300)
	at com.maddyhome.idea.vim.KeyHandler.handleKey(KeyHandler.kt:130)
	at com.maddyhome.idea.vim.KeyHandler.handleKey(KeyHandler.kt:79)
	at com.maddyhome.idea.vim.VimTypedActionHandler.execute(VimTypedActionHandler.kt:88)

chylex avatar Oct 23 '22 23:10 chylex

Also, while cs and ds work now, they don't preserve all carets because of the final `[ command. My solution still from the PR still works, but long-term it could be solved by supporting multi-caret marks.

chylex avatar Oct 23 '22 23:10 chylex

Hi! A lot of things has changed since october (marks and registers are now supported for secondary carets) and I can't find any open issue about surround and multiple carets in YouTrack, so I guess, the issue is already fixed/ready to release I'll close this PR If the bug still persists, feel free to create an YouTrack issue Thank you for your work on this PR and sorry for such a late response

lippfi avatar Mar 31 '23 09:03 lippfi