t9md / atom-vim-mode-plus

vim-mode improved
https://atom.io/packages/vim-mode-plus
MIT License
1.4k stars 112 forks source link

jump to matching character not always working `%` percent key #700

Open morenoh149 opened 7 years ago

morenoh149 commented 7 years ago

for some jsx like

      <Box pad={{horizontal: "medium", vertical: "small"}}>
      </Box>

if the cursor is on the first { character I would expect the cursor to jump near the end of the same line. Instead it jumps to the matching jsx tag </Box>. Perhaps this is a precedence issue?

Check list

gittyupagain commented 7 years ago

It is also a problem with this code snippet:

if (a < b) {
  a->foo(b);
}

It can match from the parentheses on the left of (a < b), but it then fails to jump back. Similarly, the last } brace can match back to the opening brace, but not the other way around. The problem seems to be with the < and > characters interfering with the matching.

In the snippet from @morenoh149, the matching between <Box ...> and </Box> appears to be interfering with the inner {} matchings. That is, if you rename Box or /Box so that they should no longer match, the {} matchings work fine.

t9md commented 7 years ago

Sorry for late response.

Instead it jumps to the matching jsx tag . Perhaps this is a precedence issue? Yes, I'll check to tune this.

@gittyupagain For the <, > matching issue. I want to just remove <, > matching from % motion. This is problematic, frequently unwanted matching, even pure Vim don't include <> matching, I noticed.. Why I included this in the first place???

class MoveToPair extends Motion
  @extend()
  inclusive: true
  jump: true
  # new
  member: ['Parenthesis', 'CurlyBracket', 'SquareBracket']

  # old
  # member: ['Parenthesis', 'CurlyBracket', 'SquareBracket', 'AngleBracket']
gittyupagain commented 7 years ago

@t9md In Vim you may enable angle bracket matching (:set matchpairs+=<:>). It should be allowed here too (even if it isn't the default). I use it for matching < and > when using templates in C++. I added some tests to verify the behavior matches Vim. I've been using this fix for a couple of months now, and finally got around to making a PR, allowing others to use it too.

morenoh149 commented 7 years ago

ref https://github.com/t9md/atom-vim-mode-plus/pull/798