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

Select text and tag via shortcut #145

Open
5 of 6 tasks
lindhor opened this issue Feb 9, 2019 · 2 comments
Open
5 of 6 tasks

Select text and tag via shortcut #145

lindhor opened this issue Feb 9, 2019 · 2 comments

Comments

@lindhor
Copy link

lindhor commented Feb 9, 2019

Thanks for the additional snippets in #143 they work fine!

When playing with them I found that it is not possible to select some text and run the snippet "on" the selected text to tag it with the role/directive.

I suggest that we define each snippets for all roles using $TM_SELECTED_TEXT${1:} as shown below in order to allow tagging selected text. Note the removed blank space before $0 to avoid extra space to be inserted.

	"key": {
		"prefix": "key",
		"body": ":kbd:`$TM_SELECTED_TEXT${1:}`$0",
		"description": "Keyboard Shortcut",
		"scope": "text.restructuredtext"		
	},

Also, for directives that are used to tag text (i.e. stuff like .. tip:: but not .. image:: (i.e. all currently implemented directives apart from image, figure and label) I woiuld suggest to use a similar approach with a few additional new lines as shown below in order to be able to tag selected text no matter if on a single or multiple lines.

	"tip": {
		"prefix": "tip",
		"body": "\n.. tip::\n\n   $TM_SELECTED_TEXT${1:}\n$0\n",
		"description": "Tip",
		"scope": "text.restructuredtext"
	},

I.e. with the selected text starting one line below the directive and indented with three blanks to start at the same column as the directive name. For example resulting in this structure if selecting the lines bbb and ccc Before running the snippet (with the cursor on indented on the line after ccc).

aaa

.. tip::

   bbb
   ccc
   

ddd

The only downside I can see with using $TM_SELECTED_TEXT${1:} is that you will not get any helping default text, but I Think the possibility to tag selected text benefits a lot more.

Finally you might want to consider adding the snippets as keyboard shortcuts for rst-documents like below.

    {
        "key": "ctrl+k t",
        "command": "editor.action.insertSnippet",
        "args": { "name": "tip" }
    }

Environment

  • Extension version: 102
  • Visual Studio Code version: 1.31.0
  • Operating System version: Win/OSX/Linux
  • Python version: 3.7
  • sphinx version: 1.7.9
  • A sample of conf.py or its important fragments:
@lextm
Copy link
Member

lextm commented Feb 10, 2019

Nice idea but might take a few days to plan out. Will provide an update once ready.

@lindhor
Copy link
Author

lindhor commented Feb 10, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants