Draft-js: Ctrl-K (Mac) should delete to newline, not block end

Created on 25 Jun 2016  路  5Comments  路  Source: facebook/draft-js

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.

help wanted

All 5 comments

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

  • ctrl-k deletes til (but not including) next newline or it deletes til end of block
  • if next char is newline, then delete it and stop

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.

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

@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

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.

Thanks for pointing that out, I'll look into that 馃憤

Was this page helpful?
0 / 5 - 0 ratings