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

Allow user to override keybindings in comments and/or strings #1023

Closed
crispinb opened this issue Feb 9, 2021 · 4 comments
Closed

Allow user to override keybindings in comments and/or strings #1023

crispinb opened this issue Feb 9, 2021 · 4 comments

Comments

@crispinb
Copy link
Contributor

crispinb commented Feb 9, 2021

Many* users report that they prefer default text language mode keyboard shortcuts for use within comments and strings. They could configure this for themselves if calva made 'inString' and 'inComment' when-contexts available.

(* OK, one user)

@crispinb
Copy link
Contributor Author

crispinb commented Feb 9, 2021

I'm willing to have a stab at a PR for this, but don't know much about the VSCode extension API or execution model, so I'll have to read up a bit & scan the calva codebase. In the meantime I could do with some guidance for starting points.

As far as I can see from the docs and one example from Microsoft, it involves calling a vscode 'setContext' command to toggle the newly added contexts.

The initial questions that arise for me are:

  • where do the relevant events come from?
  • where will the code for these new contexts go?

@PEZ
Copy link
Collaborator

PEZ commented Feb 9, 2021

I think the relevant event is vscode.window.onDidChangeTextEditorSelection (see vscode.window)

There is probably some things to consider so that it is the current active editor that the event is about. And also what should happen when the user activates a document.

The way to examine the code structure of the editor cursor's location is to use a Calva TokenCursor. You can create a token cursor for the current selection of a document if you have a reference the document and know the location. The event has a reference to the editor where the event fired and also to the new selection. From the editor you can get the document.

We do something similar here:

https://github.com/BetterThanTomorrow/calva/blob/dev/src/results-output/results-doc.ts

A LispTokenCursor instance (which is what you'll get) has a method for checking if the cursor is within a string. You might want to add a method for checking if we're in a comment (if there isn't one already, I don't remember). The methods getToken() and getPrevToken() should take you quite far, I think...

You can start by adding the event subscription in an anonymous function right in src/extension.ts, and we can figure out later where we want to move the implementation.

I hope I am making some little sense here? 😄

@bpringe
Copy link
Member

bpringe commented Feb 9, 2021

Another thing that might help is placing a breakpoint in the code after getting/creating the token cursor, and calling methods on it in the Debug Console to get a feel for how it works.

@crispinb
Copy link
Contributor Author

crispinb commented Feb 9, 2021

Thanks guys that all makes sense & should be helpful.

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

3 participants