draft-js-code icon indicating copy to clipboard operation
draft-js-code copied to clipboard

Added support for shift+tab to decrease indents.

Open cbeninati opened this issue 7 years ago • 15 comments

cbeninati avatar Jan 28 '18 05:01 cbeninati

Coverage Status

Coverage decreased (-3.6%) to 95.714% when pulling b21e242c11b1b95c2c3d1dc4477c57b02a4c89a8 on cbeninati:Support-Shift+Tab-to-remove-tabs-#6 into c219dc50d42f7db9c69b4b8c9be4b437116e8e6a on SamyPesse:master.

coveralls avatar Jan 28 '18 05:01 coveralls

How does this compare to #30?

mxstbr avatar Jan 28 '18 13:01 mxstbr

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.

cbeninati avatar Jan 28 '18 15:01 cbeninati

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!

mxstbr avatar Jan 28 '18 16:01 mxstbr

Yeah, no problem, thanks for catching that! I'll look into it either later tonight or tomorrow.

cbeninati avatar Jan 28 '18 16:01 cbeninati

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.

cbeninati avatar Jan 30 '18 04:01 cbeninati

@mxstbr Is there anything I can update or issues I can fix or would you like to discuss alternative approaches to help resolve this?

cbeninati avatar Feb 13 '18 03:02 cbeninati

Ok, sounds good. I'll update the docs and let you know when it's ready.

cbeninati avatar Feb 13 '18 22:02 cbeninati

ETA when this will merge?

wrahman0 avatar Mar 20 '18 20:03 wrahman0

Whenever @cbeninati adds stuff to the docs!

mxstbr avatar Mar 21 '18 08:03 mxstbr

@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. :)

cbeninati avatar Mar 22 '18 02:03 cbeninati

@mxstbr Let me know if anything's missing from the documentation. There wasn't much to do.

cbeninati avatar Mar 29 '18 01:03 cbeninati

It doesn't seem to detect tab size based on the rest of the code?

Recording of broken shift+tab behavior

Note how pressing "Backspace" does the right thing (removes the indentation) but pressing shift+tab doesn't do anything.

mxstbr avatar Mar 30 '18 13:03 mxstbr

@cbeninati Any chance you can fix the problem described by @mxstbr ? I'd really appreciate this getting merged. Thanks for all your work.

pReya avatar Mar 01 '19 07:03 pReya

Will this be merged soon? Would love to have Shift Tab functionality

RafaelZasas avatar Mar 07 '22 06:03 RafaelZasas