{"action":"closed","issue":{"url":"https://api.github.com/repos/kangax/fabric.js/issues/3256","repository_url":"https://api.github.com/repos/kangax/fabric.js","labels_url":"https://api.github.com/repos/kangax/fabric.js/issues/3256/labels{/name}","comments_url":"https://api.github.com/repos/kangax/fabric.js/issues/3256/comments","events_url":"https://api.github.com/repos/kangax/fabric.js/issues/3256/events","html_url":"https://github.com/kangax/fabric.js/issues/3256","id":176596161,"number":3256,"title":"Textbox - line's style is gone when pushing line down","user":{"login":"belfz","id":5827079,"avatar_url":"https://avatars.githubusercontent.com/u/5827079?v=3","gravatar_id":"","url":"https://api.github.com/users/belfz","html_url":"https://github.com/belfz","followers_url":"https://api.github.com/users/belfz/followers","following_url":"https://api.github.com/users/belfz/following{/other_user}","gists_url":"https://api.github.com/users/belfz/gists{/gist_id}","starred_url":"https://api.github.com/users/belfz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/belfz/subscriptions","organizations_url":"https://api.github.com/users/belfz/orgs","repos_url":"https://api.github.com/users/belfz/repos","events_url":"https://api.github.com/users/belfz/events{/privacy}","received_events_url":"https://api.github.com/users/belfz/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-13T09:46:02Z","updated_at":"2016-09-25T20:13:35Z","closed_at":"2016-09-25T20:13:35Z","body":"## Version\r\n1.6.4\r\n\r\n## Test Case\r\nhttp://jsfiddle.net/cf513q09/2/\r\n\r\n## Steps to reproduce\r\n1. Open the fiddle. The first line of text is already bolded.\r\n2. Position a cursor before first letter\r\n3. Hit enter\r\n\r\n## Expected Behavior\r\nThe text should be pushed to the second line and it should preserve the styling.\r\n\r\n## Actual Behavior\r\nThe text was pushed to the second line, but the styles are lost.\r\n\r\n\r\n## Additional informations\r\nI have noticed, that adding one simple condition to the `if` statement of `fabric.Textbox.prototype._generateStyleMap` seems to fix the issue. Take a look at my solution below (marked with a comment `// belfz's fix: added '&& i > 0' here`):\r\n```\r\nfabric.Textbox.prototype._generateStyleMap = function() {\r\n          var realLineCount     = 0,\r\n              realLineCharCount = 0,\r\n              charCount         = 0,\r\n              map               = {};\r\n\r\n          for (var i = 0; i < this._textLines.length; i++) {\r\n            // belfz's fix: added '&& i > 0' here\r\n            if (this.text[charCount] === '\\n' && i > 0) {\r\n              realLineCharCount = 0;\r\n              charCount++;\r\n              realLineCount++;\r\n            }\r\n            else if (this.text[charCount] === ' ') {\r\n              // this case deals with space's that are removed from end of lines when wrapping\r\n              realLineCharCount++;\r\n              charCount++;\r\n            }\r\n\r\n            map[i] = { line: realLineCount, offset: realLineCharCount };\r\n\r\n            charCount += this._textLines[i].length;\r\n            realLineCharCount += this._textLines[i].length;\r\n          }\r\n\r\n          return map;\r\n        };\r\n```"}}
{"actor":{"display_login":"asturur"}}