johtela / vscode-modaledit

Configurable Modal Editing in VS Code
https://johtela.github.io/vscode-modaledit/docs/README.html
Other
89 stars 8 forks source link

`docScope: true` not selecting matching element #39

Open digitalmaster opened 4 months ago

digitalmaster commented 4 months ago

Hi, could use some help here. Just started setting up my key bindings so far it's been fantastic. But I think i've run into my first issue.

I'm trying to setup a basic vi [some bracket]. At first the issue was that it was only expanding to same line (which is rare for me). But then learned that we can pass the docScope: true flag to change this.

The problem now tho, is that it's now expanding to the correct matching closing element (just the first one it finds).

Am I missing something obvious here or is this just a limitation?

"a,i": {
  "help": "Select around/inside _",
  "w": [
    "modaledit.cancelSelection",
    {
      "command": "modaledit.selectBetween",
      "args": "{ from: '\\\\W', to: '\\\\W', regex: true, inclusive: __rkeys[1] == 'a' }"
    }
  ],
  " -/,:-@,[-`,{-~": [
    "modaledit.cancelSelection",
    {
      "command": "modaledit.selectBetween",
      "args": "{ from: __rkeys[0], to: __rkeys[0], inclusive: __rkeys[1] == 'a', docScope: true }"
    }
  ],
  "(,)": [
    "modaledit.cancelSelection",
    {
      "command": "modaledit.selectBetween",
      "args": "{ from: '(', to: ')', inclusive: __rkeys[1] == 'a', docScope: true }"
    }
  ],
  "{,}": [
    "modaledit.cancelSelection",
    {
      "command": "modaledit.selectBetween",
      "args": "{ from: '{', to: '}', inclusive: __rkeys[1] == 'a', docScope: true }"
    }
  ],
  "[,]": [
    "modaledit.cancelSelection",
    {
      "command": "modaledit.selectBetween",
      "args": "{ from: '[', to: ']', inclusive: __rkeys[1] == 'a', docScope: true }"
    }
  ],
  "<,>": [
    "modaledit.cancelSelection",
    {
      "command": "modaledit.selectBetween",
      "args": "{ from: '<', to: '>', inclusive: __rkeys[1] == 'a' docScope: true }"
    }
  ]
}
},
johtela commented 4 months ago

Hello!

The modaledit.selectBetween command moves to the first occurrence of the searched character(s), so it does not find the closing bracket. To implement your use case, I would use the following binding. It assumes that you have the F key bound to the modaledit.search command, and it works as in Vim. That is, jumps to the previous occurrence of a character.

            "[,]": [
                {
                    "command": "modaledit.typeNormalKeys",
                    "args": "{ keys: 'F[' }"
                },
                "editor.action.selectToBracket"
            ],
            "<,>": [
                {
                    "command": "modaledit.typeNormalKeys",
                    "args": "{ keys: 'F<' }"
                },
                "editor.action.selectToBracket"
            ],
digitalmaster commented 4 months ago

Ah that makes sense now. Doesn't look editor.action.selectToBracket can do inside the bracket variation.

Lemme know if there's an obvious way to do this. Otherwise what i'm doing now seems to be working which is using commands in this plugin.

Sidenote: Thank you so much for building this! I've been experimenting for a long time trying to find what I was looking for. Nothing felt right until now. Thank you <3

johtela commented 3 months ago

I guess selectToBracket falls short when you want to select inside arbitrary characters. Maybe selectBetween could be enhanced to count the opening brackets while it's looking for the closing bracket. I'll register this idea as a future improvement that I could implement at some point.

I was planning to do a minor update to the plugin. It has apparently been 4 years since I last touched it :-) There are few things that annoy me enough to fix them. I'm still using the plugin myself on a daily basis.

digitalmaster commented 3 months ago

Awesome! TBH that deterred me initially.. I "thought this isn't maintained so probably not in good state" but then I saw how few issues were opened and of course how thorough the documentation was and decided to give it a shot - best decision I've made in a long time. Haven't been this obsessed with an improvement to my dev workflow in years!

The plugin I'm using does the trick for now (not perfect tho).. will be on the lookout for updates.. happy to help with testing once it's ready! 🤗

johtela commented 3 months ago

The documentation is there for me to remember what I did 4 years ago 😉 There would be a lot of things to improve to get closer to the Vim functionality, but I have deliberately kept the plugin quite simple. It's just a modal editor engine, not a full-blown Vim emulation.

digitalmaster commented 3 months ago

Yup - that's the best part of the philosophy of this project. Simple because it takes the best parts of VIM and makes them available here. That's it. No bending backwards to copy VIM.

Also, the fact that we don't complete cannibalize insert mode is another great example of this philosophy - it's made it so easy to slowly adapt this into my workflow because everything I'm already used to still works.

Sure devs with Vim muscle memory already ingrained might struggle to see the point, but for everyone else this project is a hidden gem 💎 🔥