meganrogge / template-string-converter

Autocorrect from quotes to backticks
MIT License
190 stars 24 forks source link

[enhancement] add key bindings for insert interpolation symbol #62

Open maksimaliabyshev opened 2 years ago

maksimaliabyshev commented 2 years ago

I could not find an adequate extension to implement this improvement. It would be great if the interpolation of the selected text worked, and a second click inside the interpolated text removed the characters.

command for keybindings: ctrl/cmd+shift+4 image

selected_text_or_word --> keypress --> ${cursor_in_text} --> keypress --> text

As an implementation example (inconvenient extension): https://marketplace.visualstudio.com/items?itemName=adiessl.vscode-backtix

zardoy commented 1 year ago

I could not find an adequate extension to implement this improvement.

  1. Install Commands extension

  2. Add this to your keybindings.json:

{
    "key": "alt+c",
    "command": "commands.run",
    "args": [
        {
            "command": "type",
            "args": {
                "text": "{"
            }
        },
        "cursorLeft",
        "cursorLeft",
        {
            "command": "type",
            "args": {
                "text": "$"
            }
        },
        {
            "command": "deleteRight",
            "delay": 50
        }
    ]
}

Note that last deleteRight is required with delay to workaround https://github.com/meganrogge/template-string-converter/issues/70 it should be removed when that issue is resolved

@truepatch is that what you wanted? The only downside of this solution is that undo stack is not clean (need to press ctrl+z several times instead of one), but this command is easy to impl here i think

maksimaliabyshev commented 1 year ago

@truepatch is that what you wanted? The only downside of this solution is that undo stack is not clean (need to press ctrl+z several times instead of one), but this command is easy to impl here i think

Almost, I wanted the author of the extension to improve this function, via ctrl/cmd+shift+4

// ▯ - cursor
let string = 'not select▯ed word' //press ctrl/cmd+shift+4
                   ▼
let string = `not ${select▯ed} word` //press ctrl/cmd+shift+4
                   ▼
let string = 'not select▯ed word'

OR

let string = '[selected words]' //press ctrl/cmd+shift+4
                   ▼
let string = `${selected words}` //press ctrl/cmd+shift+4
                   ▼
let string = 'selected words'