WordPress/gutenberg
View on GitHubKeyboard shortcut for indenting lines of code in the code block
Open
#15791 opened on May 23, 2019
Good First IssueNeeds Dev[Block] Code[Status] In Progress[Type] Enhancement
Description
Is your feature request related to a problem? Please describe. In the code block editor I would like to be able to indent and outdent lines of code with a minimal number of keystrokes.
Describe the solution you'd like Ideally:
- pressing a key combination of 3 or less keys would insert a tab character at the start of the line (or lines, if multiple lines are selected)
- pressing a key combination of 3 or less keys would remove tab characters at the start of the line (or lines, if multiple lines are selected)
The key combination could be:
- Using the same indent and outdent keys used for lists:
Ctrl+](indent) andCtrl+[(outdent) - For single tab inserts on Windows, ensuring that
Alt+0+0+9inserts a tab in the code block editor on all major browsers could make up part of the solution as this already inserts a tab character in Chrome and Edge but not in Firefox. This does not allow indenting and outdenting multiple lines of selected code at once however. - For single tab inserts on MacOS, ensuring that
Ctrl+Option+Tabinserts a tab character in the code block editor on all major browsers could make up part of the solution as this already inserts a tab character in Safari but not Chrome or Firefox.
Describe alternatives you've considered
- Copying and pasting tabs from another program (tedious when freestyle writing lots of code in a code block)
- Using multiple spaces to emulate the tab character (this breaks convention when writing for code which uses tabs instead of spaces so it's not copy-pastable)
- https://github.com/bfred-it/indent-textarea (allows selecting lines and indenting them but changes tab key behaviour so it breaks the accessibility model)
- Looked at related issues and pull requests: #1640 #1826 #9611 #7051