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

Keyboard shortcut for indenting lines of code in the code block #15791

Open
wclear opened this issue May 23, 2019 · 15 comments · May be fixed by #39509
Open

Keyboard shortcut for indenting lines of code in the code block #15791

wclear opened this issue May 23, 2019 · 15 comments · May be fixed by #39509
Assignees
Labels
[Block] Code Affects the Code Block Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Comments

@wclear
Copy link

wclear commented May 23, 2019

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
@wclear wclear changed the title Make a keyboard shortcut for indenting lines of code in the code block A keyboard shortcut for indenting lines of code in the code block May 23, 2019
@wclear wclear changed the title A keyboard shortcut for indenting lines of code in the code block Keyboard shortcut for indenting lines of code in the code block May 23, 2019
@gziolo gziolo added [Type] Enhancement A suggestion for improvement. [Block] Code Affects the Code Block labels May 23, 2019
@paaljoachim
Copy link
Contributor

Hey @wclear Will.

Is this issue still relevant? Should it be closed?

@wclear
Copy link
Author

wclear commented Jan 27, 2021

Hey @paaljoachim. I believe this issue is still relevant. I don't know if I've overlooked a development in the editor for the code block recently, but all the methods for indenting in the code block editor proposed in the issue continue to not work (and I can't find a method that does work). It seems like it is still not possible to indent and outdent lines of code with tab characters in the code block using only the keyboard.

@paaljoachim
Copy link
Contributor

Thanks @wclear Will

I will ping some developers (making my best guess) who might have some ideas about this.
@gziolo @tellthemachines @noisysocks

@wclear
Copy link
Author

wclear commented Jan 28, 2021

Wonderful, thank you @paaljoachim!

@noisysocks
Copy link
Member

Matching what we do for the List block and using Cmd + ] and Cmd + ] makes sense to me.

@noisysocks noisysocks added the Needs Dev Ready for, and needs developer efforts label Feb 4, 2021
@paaljoachim paaljoachim added the Good First Issue An issue that's suitable for someone looking to contribute for the first time label Feb 4, 2021
@amustaque97
Copy link
Member

Hi team, if this issue is still relevant I can take it up.

@paaljoachim
Copy link
Contributor

I believe it is still relevant.

Please do take it up @amustaque97
Thank you!

@amustaque97 amustaque97 self-assigned this Jan 20, 2022
@amustaque97
Copy link
Member

@paaljoachim, looks like currently there is no option for indentation and outdentation. Do we need to implement indent and outdent feature first(and part of this issue) then work on the shortcut keys?

If yes, what is the requirement for indent/outdent? Please share your ideas!

Thanks

@paaljoachim
Copy link
Contributor

Hi @amustaque97

Perhaps @getdave might have som ideas....:)

@getdave
Copy link
Contributor

getdave commented Jan 28, 2022

I suggest bringing this one up in the Core Editor chat. It seems like a good idea but I can't personally commit to it at this time.

@getdave
Copy link
Contributor

getdave commented Feb 2, 2022

This was discussed during the Core Editor chat. The consensus was that it would be great if someone could raise a PR using one of the keyboard shortcuts suggested above. We can then all test and refine the shortcuts as required.

Is anyone open to taking this one on?

@getdave
Copy link
Contributor

getdave commented Feb 3, 2022

Forwarding important feedback left in #core-editor on Slack (registration required):

@joedolson: It's totally reasonable and expected to use the tab key for indenting within a code context. It's important that users are informed how to get out of the context where tab has changed usage. E.g., text above the form like 'Use esc to leave edit mode'. (Ctrl+M is also a common key combination for toggling, used by VS Code, for example.) @alexstine and @marcoz probably have valuable opinions on this topic.

@alexstine: Me personally, I would like Escape to be used. My hope is the accessibility only Navigation Mode will be going away at some point and then Escape will be freed up.

@MarcoZehe: Yes, that sounds reasonable.

@paaljoachim
Copy link
Contributor

paaljoachim commented Feb 22, 2022

As I am currently redoing my WordPress tutorial site I am adding a lot of code into Code blocks.
I missing being able to press Tab to indent the code similar to various coding programs, or text programs. Even in Text Edit on the Mac uses Tab to indent. It seems like a standard key one uses to indent.

It would be helpful if someone is able to add Tab as a key to indent in the Code block, or in a block that uses text.
Thanks!

@mcsf Miguel is this perhaps something you might be able to pick up?

@mcsf
Copy link
Contributor

mcsf commented Feb 24, 2022

Miguel is this perhaps something you might be able to pick up?

Not anytime soon, unfortunately.

@paaljoachim
Copy link
Contributor

Alrighty. Thanks for the response Miguel. We will see when this issue moves onward.
Have a great day!

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Code Affects the Code Block Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants