draft-js-code
draft-js-code copied to clipboard
Added support for shift+tab to decrease indents.
Coverage decreased (-3.6%) to 95.714% when pulling b21e242c11b1b95c2c3d1dc4477c57b02a4c89a8 on cbeninati:Support-Shift+Tab-to-remove-tabs-#6 into c219dc50d42f7db9c69b4b8c9be4b437116e8e6a on SamyPesse:master.
How does this compare to #30?
It works more like @newsiberian mentioned regarding WebStorm's functionality.
Hi, here we should some extra work. I've checked again WebStorm behaviour on shift+Tab and backspace and their are differ.
This adds indentation decrease, which is a line-based action. That meansit will remove indentation from the start of the line regardless of the cursor's position.
If there is no indentation at the start of the line, it will ignore the request to decrease indentation.
For my needs, and this seems to be reflected in @newsiberian's comment above, there should separate functionality for 'backspace' (remove from the cursor's position) and 'shift+tab' (remove the line's indentation).
If we wanted, to add more flexibility, we could add an optional parameter in onTab()
to specify the intent. Something like:
onTab(event, editorState, action)
In which action
could be 'backspace' or 'decrease indent' or something like that.
I see, that makes sense!
This breaks for me on any code block that has > 1 line of code, see this recording: https://www.dropbox.com/s/qspu16vnb2zrrjr/remove-tab-bug.mov?dl=0
Mind fixing that and adding some tests verifying both that case and the "no indentation at start" case work as expected? Thanks!
Yeah, no problem, thanks for catching that! I'll look into it either later tonight or tomorrow.
Ok @mxstbr, I fixed the multiline issue. In doing so, I also added support for 'default tab size' to be optionally passed through to the onTab() method as a third parameter.
This allows for an editor to have it's own declared tab spacing setting instead of just reading the indentation spacing (although that is a fallback if the tabSize is set to null).
This is important because, with knowledge of an individual tab size, we can decrease indentation one tab at a time instead of just removing all spaces at the beginning of the line.
I'm glad to discuss alternative implementations also, but I needed something in place in order to handle true tab-by-tab decreasing.
If you agree with my implementation, then I'd be happy to update the documentation also, but I wanted to give you a chance to review it first.
@mxstbr Is there anything I can update or issues I can fix or would you like to discuss alternative approaches to help resolve this?
Ok, sounds good. I'll update the docs and let you know when it's ready.
ETA when this will merge?
Whenever @cbeninati adds stuff to the docs!
@mxstbr Apologies for the delay. I diverted from the DraftJS project I was using this for.
The README has been updated to reflect the new onTab
functionality. Not much to it. :)
@mxstbr Let me know if anything's missing from the documentation. There wasn't much to do.
It doesn't seem to detect tab size based on the rest of the code?
Note how pressing "Backspace" does the right thing (removes the indentation) but pressing shift+tab doesn't do anything.
@cbeninati Any chance you can fix the problem described by @mxstbr ? I'd really appreciate this getting merged. Thanks for all your work.
Will this be merged soon? Would love to have Shift Tab functionality