WordPress/gutenberg

Keyboard shortcut for indenting lines of code in the code block

Open

#15791 opened on May 23, 2019

View on GitHub
 (15 comments) (7 reactions) (1 assignee)JavaScript (9,607 stars) (3,893 forks)batch import
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) and Ctrl + [ (outdent)
  • For single tab inserts on Windows, ensuring that Alt + 0 + 0 + 9 inserts 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 + Tab inserts 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

Contributor guide