-
Notifications
You must be signed in to change notification settings - Fork 66
add toggleMultilineStringLiteral command #422
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
add toggleMultilineStringLiteral command #422
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Empty lines could be handled better so that
a
b
becomes
\\a
\\
\\b
instead of
\\a
\\
\\b
But this can also be fixed by formatting the document so it's not critical.
thanks! I can fix that. Also, I need to pick a new default keyboard shortcut. Binding this command to Ctrl-M Ctrl-S breaks the default binding of Ctrl-M to |
The VS Code API provides a DocumentPasteEditProvider that can be used to customize the behavior when a user copy pastes into a document. This could be used to detect when pasting into a multi line string literal and automatically convert the pasted content. Because users don’t need to be aware of the new command being added, this approach could be more accessible because it requires less knowledge of the extension. |
…y Moves Focus" default keybinding
I'll take a look. |
I think it would still be useful to have the command even if without a default key bind. |
I took a look at DocumentPasteEditProvider and its official sample. I don't think it's going to work for this feature. Yes, it would be possible for a DocumentPasteEditProvider to add multiline string literal tokens when pasting. But when would/should the provider do that? There's no context in the source document, the clipboard contents or the destination document that the provider could use as a definitive signal that the tokens should be added. Then you're dependent on some kind of specific user clipboard action such as the If it's ok w/ you @Techatrix, I'd rather just leave this as a simple command and skip implementing a paste provider. |
When pasting into an already existing multi line string literal.
No objections. As suggested before, there is not reason why there couldn't be both a command and a DocumentPasteEditProvider. I will look into the latter myself as a possible follow-up PR. |
This PR creates a command to toggle lines in the current selection to be part of a multiline string literal. The command adds or removes the multiline string token from each line as appropriate.
I do a lot of SQL work and tend to copy/paste multiline string literals into my zig source code from other sources. But I got tired of manually adding the multiline string token
\\
to each line.Since there aren't any other stand-alone commands in the project, I added the command function to the extension file. I'm guessing that's not the best location, but I figured better to put it there and move it to elsewhere based on feedback.
I mapped this command by default to Ctrl-M Ctrl-S (for Multiline String). I think of this command similar to the add/remove line comment commands that are mapped to Ctrl-K Ctrl-C / Ctrl-K Ctrl-U. However, I didn't think that removing multiline string literal tokens would be that common scenario, so I created a single toggle command instead of separate add/remove commands. Happy to change this to separate add/remove commands based on feedback.