geddski / macros

macros support for VS Code
MIT License
166 stars 36 forks source link

Passing a string to actions.find #39

Open amandatennent opened 6 years ago

amandatennent commented 6 years ago

I'm trying to create a macro that will find a certain string (a regex string that I use a lot), that will then replace it with another regex string. I have set it up, but instead of the find string being placed in the find box, it's being placed in the text editor. Is there another argument I should be using instead of text?

    "macros": {
        "addSpacesAfterCommas" : [
            "actions.find",
                {"command": "type", "args": {"text": "search string here"}}
        ]
    }
rsxdalv commented 5 years ago

This is caused by delay in the editor, to verify it you can add a bunch of write commands (and you'll see that they eventually write in the find window)

Solution: https://github.com/geddski/macros/pull/13

MythicLionMan commented 2 years ago

Just in case anyone else lands here, the solution I landed on was:

    "macros": {
        "upgradeFMODEvent": [
            {"command": "editor.actions.findWithArgs", "args": {"searchString": "[FMODUnity.EventRef]"} },
            "editor.action.nextMatchFindAction",
         ]
    }
linyu003 commented 1 year ago

Just in case anyone else lands here, the solution I landed on was:

    "macros": {
        "upgradeFMODEvent": [
            {"command": "editor.actions.findWithArgs", "args": {"searchString": "[FMODUnity.EventRef]"} },
            "editor.action.nextMatchFindAction",
         ]
    }

That helps a lot. Thank you. And I give another example for anyone who lands here.

        "json2-": [
            {
                "command": "editor.actions.findWithArgs",
                "args": {
                    "searchString": "^ *('|\")(.+?)('|\") *: *('|\")(.+?)('|\"),? *$",
                    "replaceString": "-$2=$5",
                    "isRegex": true
                }
            },
            "editor.action.replaceAll"
        ]

To know the full args of editor.actions.findWithArgs, refer this