chrisgrieser / nvim-scissors

Automagical editing and creation of snippets.
MIT License
377 stars 4 forks source link

Feature Request: Allows defining a title different from the prefix #21

Closed MasouShizuka closed 2 months ago

MasouShizuka commented 2 months ago

Checklist

Feature Requested

Currently defined snippets have the same title and prefix, but they can contain more information, for example:

    "Module template": {
        "body": [
            "local M = {}",
            "${TM_SELECTED_TEXT}$0",
            "return M"
        ],
        "description": "This is a module template",
        "prefix": "M"
    },

This will look like: image

So it would be great if could allow custom title and description.

Relevant Screenshot

No response

chrisgrieser commented 2 months ago

That would require rewriting the plugin's UI to support somehow writing more than the snippet body and snippet prefix. Not impossible, but would take a certain amount of work, and make the plugin more complicated to use, while ease-of-use is one of its goals.

In my view, the benefit of being able to define a title different from the prefix is not big enough to warrant implementing this. For the very few cases where this might be useful, you can use the openInFile keymap to edit the title directly.

MasouShizuka commented 2 months ago

After editing and saving an existing snippet, the title will be overwritten with the prefix.

For example, after saving the above snippet, it will become:

    "M": {
        "body": [
            "local M = {}",
            "${TM_SELECTED_TEXT}$0",
            "return M"
        ],
        "description": "This is a module template",
        "prefix": "M"
    },

In addition, it is also found that the part of luasnip will disappear:

    "Insert heading level 1": {
        "prefix": [
            ".1",
            "。1"
        ],
        "body": "# ${TM_SELECTED_TEXT}",
        "luasnip": {
            "autotrigger": true
        },
        "description": "Insert heading level 1"
    },

become:

    ".1 + 。1": {
        "body": "# ${TM_SELECTED_TEXT}",
        "description": "Insert heading level 1",
        "prefix": [
            ".1",
            "。1"
        ]
    },

Is it possible to prevent other parts from being overwritten?

chrisgrieser commented 2 months ago

good point. Should be fixed.

MasouShizuka commented 2 months ago

After this fix, some keys that were not originally there appear after the snippet is saved, such as the above snippet:

    "Module template": {
        "body": [
            "local M = {}",
            "${TM_SELECTED_TEXT}$0",
            "return M"
        ],
        "description": "This is a module template",
        "filetype": "lua",
        "fullPath": "C:/Users/MasouShizuka/scoop/persist/vscode/data/user-data/User/snippets/lua.json",
        "originalKey": "Module template",
        "prefix": "M"
    },
chrisgrieser commented 2 months ago

fixed