{"action":"created","issue":{"url":"https://api.github.com/repos/draft-js-plugins/draft-js-plugins/issues/580","repository_url":"https://api.github.com/repos/draft-js-plugins/draft-js-plugins","labels_url":"https://api.github.com/repos/draft-js-plugins/draft-js-plugins/issues/580/labels{/name}","comments_url":"https://api.github.com/repos/draft-js-plugins/draft-js-plugins/issues/580/comments","events_url":"https://api.github.com/repos/draft-js-plugins/draft-js-plugins/issues/580/events","html_url":"https://github.com/draft-js-plugins/draft-js-plugins/issues/580","id":193106678,"number":580,"title":"Hitting backspace on an empty, styled Block doesn't reset it to unstyled.","user":{"login":"mkampik","id":6001744,"avatar_url":"https://avatars.githubusercontent.com/u/6001744?v=3","gravatar_id":"","url":"https://api.github.com/users/mkampik","html_url":"https://github.com/mkampik","followers_url":"https://api.github.com/users/mkampik/followers","following_url":"https://api.github.com/users/mkampik/following{/other_user}","gists_url":"https://api.github.com/users/mkampik/gists{/gist_id}","starred_url":"https://api.github.com/users/mkampik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkampik/subscriptions","organizations_url":"https://api.github.com/users/mkampik/orgs","repos_url":"https://api.github.com/users/mkampik/repos","events_url":"https://api.github.com/users/mkampik/events{/privacy}","received_events_url":"https://api.github.com/users/mkampik/received_events","type":"User","site_admin":false},"labels":[{"id":332340771,"url":"https://api.github.com/repos/draft-js-plugins/draft-js-plugins/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-02T12:37:07Z","updated_at":"2016-12-04T12:44:49Z","closed_at":null,"body":"As it stands, hitting the backspace key on an empty, styled Block (e.g. `unordered-list-item`) removes the Block entirely, and puts the cursor to the previous line. If this is intentional, shouldn't the desired behaviour be that it resets the Block to `unstyled` instead?\r\n\r\nE.g. if you've written 3 bullet points, hit enter and a fourth appears, then hitting the backspace key should remove the fourth bullet point so that you can continue writing on the same line if you wish.\r\n\r\nThis is what happens on the[ Draft.js](https://facebook.github.io/draft-js/) example editor (if you'd like to give it a go), as well as in Word, Google docs etc...\r\n\r\nIn an attempt to solve the issue, I've started to implement a Key Binding function which is supposed to reset the Block if its styled and empty. Like so:\r\n\r\n```javascript\r\nimport Editor from 'draft-js-plugins-editor'\r\nimport {Modifier, getDefaultKeyBinding} from 'draft-js'\r\n\r\nconst BindKeys = (e, editorState) => {\r\n  var lastBlock = editorState.getCurrentContent().getLastBlock();\r\n  if (e.keyCode === 8) {\r\n    if (lastBlock.getType() !== 'unstyled' && lastBlock.getText().length === 0) {\r\n      return {\r\n        cmd: 'reset-style',\r\n        editorState: editorState,\r\n      }\r\n    }\r\n    return getDefaultKeyBinding(e);\r\n  }\r\n}\r\n\r\nexport class MyEditor extends React.Component {\r\n  handleKeyCommand = (e) => {\r\n    if (e.cmd === 'reset-style') {\r\n      // Modifier.replaceText()?\r\n      return 'handled';\r\n    }\r\n    return 'not-handled';\r\n  }\r\n  //...\r\n    return (\r\n      <Editor\r\n        editorState={editorState}\r\n        onChange={this.updateEditorState}\r\n        handleKeyCommand={this.handleKeyCommand}\r\n        keyBindingFn={ (e) => BindKeys(e, editorState) } />\r\n    )\r\n}\r\n```\r\n\r\nThe function fires on the desired event, but I'm not managing to get `Modifier.replaceText` to work. Is this the correct method to use at this point?\r\n\r\nMore importantly tho, is this a good approach to resolving the issue within `draft-js-plugins-editor`'s architecture? It somehow feels overkill...\r\n\r\nAny suggestions and pointers on both resolving the issue and how to make this a useful contribution are much appreciated. Thanks!"},"comment":{"url":"https://api.github.com/repos/draft-js-plugins/draft-js-plugins/issues/comments/264701856","html_url":"https://github.com/draft-js-plugins/draft-js-plugins/issues/580#issuecomment-264701856","issue_url":"https://api.github.com/repos/draft-js-plugins/draft-js-plugins/issues/580","id":264701856,"user":{"login":"mkampik","id":6001744,"avatar_url":"https://avatars.githubusercontent.com/u/6001744?v=3","gravatar_id":"","url":"https://api.github.com/users/mkampik","html_url":"https://github.com/mkampik","followers_url":"https://api.github.com/users/mkampik/followers","following_url":"https://api.github.com/users/mkampik/following{/other_user}","gists_url":"https://api.github.com/users/mkampik/gists{/gist_id}","starred_url":"https://api.github.com/users/mkampik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkampik/subscriptions","organizations_url":"https://api.github.com/users/mkampik/orgs","repos_url":"https://api.github.com/users/mkampik/repos","events_url":"https://api.github.com/users/mkampik/events{/privacy}","received_events_url":"https://api.github.com/users/mkampik/received_events","type":"User","site_admin":false},"created_at":"2016-12-04T12:44:49Z","updated_at":"2016-12-04T12:44:49Z","body":"No problem, totally understand. I'm gonna have to move on to something else for a bit, but will let you know if and how I've resolved it. "}}
{"actor":{"display_login":"mkampik"}}