facebookarchive / draft-js

A React framework for building text editors.
https://draftjs.org/
MIT License
22.58k stars 2.64k forks source link

Ctrl-K (Mac) should delete to newline, not block end #487

Open sophiebits opened 8 years ago

sophiebits commented 8 years ago

Usually blocks don't have newlines in them, but when they do (shift-enter in a list item, for example), Ctrl-K should delete to the newline, not the end of the block.

Also, Ctrl-K should delete an empty block.

danneu commented 7 years ago

Unfortunately I don't have the energy right now to figure out the draft-js build + test system, but here's what I got working by editing SecondaryClipboard.js directly in my node_modules folder so that I could test it in my toy editor:

https://gist.github.com/danneu/89cbcf64bcb62995b91cb80acf8bf79b#file-secondaryclipboard-js-L12-L32

Not sure the ideal way to delete the current block, either. Thought I'd be able to leverage the backspace behavior:

if (block.getText().length === 0) {
  return RichUtils.onBackspace(editorState) || editorState
}

but got some runtime error after the block was deleted.

Could have updated the blockMap myself, but seemed like surely there was a helper I could use.

claudiopro commented 5 years ago

I recall @sophiebits addressed this issue with 645549343e7248ae07bf8e274de971acfe1c53c0, so it can be closed

sophiebits commented 5 years ago

@claudiopro That's a different issue; can you reopen?

Repro for this one:

  1. Open Workplace composer
  2. Type * a opt-enter b then go to before the a
  3. Ctrl-K

Expected: Only the "a" is deleted. Actual: "a", the newline, and "b" is deleted

screenshot

sophiebits commented 5 years ago

In the line selection.set('focusOffset', blockEnd);, instead of using blockEnd it should find the first newline whose position is greater than the current focusOffset and then cut up to (but not including) that char.

claudiopro commented 5 years ago

Thanks for pointing that out, I'll look into that 👍