Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docScope: true not selecting matching element #39

Open
digitalmaster opened this issue May 30, 2024 · 6 comments
Open

docScope: true not selecting matching element #39

digitalmaster opened this issue May 30, 2024 · 6 comments

Comments

@digitalmaster
Copy link

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 }"
    }
  ]
}
},
@digitalmaster digitalmaster changed the title docScope: true not selecting till matching element docScope: true not selecting matching element May 30, 2024
@johtela
Copy link
Owner

johtela commented May 31, 2024

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
Copy link
Author

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
Copy link
Owner

johtela commented Jun 2, 2024

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.

@johtela johtela reopened this Jun 2, 2024
@digitalmaster
Copy link
Author

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
Copy link
Owner

johtela commented Jun 4, 2024

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
Copy link
Author

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 💎 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants