{"action":"created","comment":{"url":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/comments/36903458","id":36903458,"diff_hunk":"@@ -53,16 +58,57 @@ export default class Section extends LinkedItem {\n   }\n \n   /**\n-   * Splits the marker at the offset (until the endOffset, if given)\n-   * into 1, 2, or 3 markers and replaces the existing marker\n-   * with the new ones\n+   * Splits the marker at the offset, filters empty markers from the result,\n+   * and replaces this marker with the new non-empty ones\n+   * @param {Marker} marker the marker to split\n+   * @return {Array} the new markers that replaced `marker`\n    */\n   splitMarker(marker, offset, endOffset=marker.length) {\n-    const newMarkers = marker.split(offset, endOffset);\n+    const newMarkers = filter(marker.split(offset, endOffset), m => !m.empty());\n     this.markers.splice(marker, 1, newMarkers);\n     return newMarkers;\n   }\n \n+  splitAtMarker(marker, offset=0) {\n+    let [beforeSection, afterSection] = [\n+      this.builder.createMarkupSection(this.tagName, []),\n+      this.builder.createMarkupSection(this.tagName, [])\n+    ];\n+\n+    let currentSection = beforeSection;\n+    forEach(this.markers, m => {\n+      if (m === marker) {\n+        const [beforeMarker, ...afterMarkers] = marker.split(offset);\n+        beforeSection.markers.append(beforeMarker);\n+        forEach(afterMarkers, _m => afterSection.markers.append(_m));\n+        currentSection = afterSection;\n+      } else {\n+        currentSection.markers.append(m.clone());\n+      }\n+    });\n+\n+    beforeSection.coalesceMarkers();\n+    afterSection.coalesceMarkers();\n+\n+    return [beforeSection, afterSection];\n+  }\n+\n+  /**\n+   * Remove extranous empty markers, adding one at the end if there\n+   * are no longer any markers\n+   *\n+   * Mutates this section's markers\n+   */\n+  coalesceMarkers() {\n+    forEach(\n+      filter(this.markers, m => m.empty()),","path":"src/js/models/markup-section.js","position":63,"original_position":63,"commit_id":"3f113b303fd1addf79a05a87e0c3d58eb4b7ade8","original_commit_id":"3f113b303fd1addf79a05a87e0c3d58eb4b7ade8","user":{"login":"bantic","id":2023,"avatar_url":"https://avatars.githubusercontent.com/u/2023?v=3","gravatar_id":"","url":"https://api.github.com/users/bantic","html_url":"https://github.com/bantic","followers_url":"https://api.github.com/users/bantic/followers","following_url":"https://api.github.com/users/bantic/following{/other_user}","gists_url":"https://api.github.com/users/bantic/gists{/gist_id}","starred_url":"https://api.github.com/users/bantic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bantic/subscriptions","organizations_url":"https://api.github.com/users/bantic/orgs","repos_url":"https://api.github.com/users/bantic/repos","events_url":"https://api.github.com/users/bantic/events{/privacy}","received_events_url":"https://api.github.com/users/bantic/received_events","type":"User","site_admin":false},"body":"@mixonic removing markers while iterating them causes the iteration to skip (`item.next` is something different before/after the callback). I have a PR coming to fix iteration of the linkedlist","created_at":"2015-08-12T19:34:41Z","updated_at":"2015-08-12T19:34:41Z","html_url":"https://github.com/bustlelabs/content-kit-editor/pull/53#discussion_r36903458","pull_request_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/53","_links":{"self":{"href":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/comments/36903458"},"html":{"href":"https://github.com/bustlelabs/content-kit-editor/pull/53#discussion_r36903458"},"pull_request":{"href":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/53"}}},"pull_request":{"url":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/53","id":42041598,"html_url":"https://github.com/bustlelabs/content-kit-editor/pull/53","diff_url":"https://github.com/bustlelabs/content-kit-editor/pull/53.diff","patch_url":"https://github.com/bustlelabs/content-kit-editor/pull/53.patch","issue_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues/53","number":53,"state":"closed","locked":false,"title":"Handle newline at start or end of section","user":{"login":"bantic","id":2023,"avatar_url":"https://avatars.githubusercontent.com/u/2023?v=3","gravatar_id":"","url":"https://api.github.com/users/bantic","html_url":"https://github.com/bantic","followers_url":"https://api.github.com/users/bantic/followers","following_url":"https://api.github.com/users/bantic/following{/other_user}","gists_url":"https://api.github.com/users/bantic/gists{/gist_id}","starred_url":"https://api.github.com/users/bantic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bantic/subscriptions","organizations_url":"https://api.github.com/users/bantic/orgs","repos_url":"https://api.github.com/users/bantic/repos","events_url":"https://api.github.com/users/bantic/events{/privacy}","received_events_url":"https://api.github.com/users/bantic/received_events","type":"User","site_admin":false},"body":"Handle newline at start of section\r\n\r\n  * simplify section#splitMarker\r\n  * tests for hitting enter in middle and end of section\r\n  * add test for hitting enter in first section\r\n  * fix bug with PostNodeBuilder not assigning a builder to the blank marker\r\n\r\nfixes #39","created_at":"2015-08-10T16:55:58Z","updated_at":"2015-08-12T19:34:41Z","closed_at":"2015-08-11T18:37:47Z","merged_at":"2015-08-11T18:37:47Z","merge_commit_sha":"995a7f1dfbc9ee32bdb5893381fc947cf442fcd2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/53/commits","review_comments_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/53/comments","review_comment_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues/53/comments","statuses_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/statuses/3f113b303fd1addf79a05a87e0c3d58eb4b7ade8","head":{"label":"bustlelabs:newline-at-section-start","ref":"newline-at-section-start","sha":"3f113b303fd1addf79a05a87e0c3d58eb4b7ade8","user":{"login":"bustlelabs","id":2198187,"avatar_url":"https://avatars.githubusercontent.com/u/2198187?v=3","gravatar_id":"","url":"https://api.github.com/users/bustlelabs","html_url":"https://github.com/bustlelabs","followers_url":"https://api.github.com/users/bustlelabs/followers","following_url":"https://api.github.com/users/bustlelabs/following{/other_user}","gists_url":"https://api.github.com/users/bustlelabs/gists{/gist_id}","starred_url":"https://api.github.com/users/bustlelabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bustlelabs/subscriptions","organizations_url":"https://api.github.com/users/bustlelabs/orgs","repos_url":"https://api.github.com/users/bustlelabs/repos","events_url":"https://api.github.com/users/bustlelabs/events{/privacy}","received_events_url":"https://api.github.com/users/bustlelabs/received_events","type":"Organization","site_admin":false},"repo":{"id":21694966,"name":"content-kit-editor","full_name":"bustlelabs/content-kit-editor","owner":{"login":"bustlelabs","id":2198187,"avatar_url":"https://avatars.githubusercontent.com/u/2198187?v=3","gravatar_id":"","url":"https://api.github.com/users/bustlelabs","html_url":"https://github.com/bustlelabs","followers_url":"https://api.github.com/users/bustlelabs/followers","following_url":"https://api.github.com/users/bustlelabs/following{/other_user}","gists_url":"https://api.github.com/users/bustlelabs/gists{/gist_id}","starred_url":"https://api.github.com/users/bustlelabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bustlelabs/subscriptions","organizations_url":"https://api.github.com/users/bustlelabs/orgs","repos_url":"https://api.github.com/users/bustlelabs/repos","events_url":"https://api.github.com/users/bustlelabs/events{/privacy}","received_events_url":"https://api.github.com/users/bustlelabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bustlelabs/content-kit-editor","description":"A modern, minimalist WYSIWYG editor","fork":false,"url":"https://api.github.com/repos/bustlelabs/content-kit-editor","forks_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/forks","keys_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/teams","hooks_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/hooks","issue_events_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues/events{/number}","events_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/events","assignees_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/assignees{/user}","branches_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/branches{/branch}","tags_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/tags","blobs_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/refs{/sha}","trees_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/statuses/{sha}","languages_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/languages","stargazers_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/stargazers","contributors_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/contributors","subscribers_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/subscribers","subscription_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/subscription","commits_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/commits{/sha}","git_commits_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/commits{/sha}","comments_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/comments{/number}","issue_comment_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues/comments{/number}","contents_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/contents/{+path}","compare_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/merges","archive_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/downloads","issues_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues{/number}","pulls_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls{/number}","milestones_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/milestones{/number}","notifications_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/labels{/name}","releases_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/releases{/id}","created_at":"2014-07-10T13:22:19Z","updated_at":"2015-08-11T14:39:23Z","pushed_at":"2015-08-12T17:40:41Z","git_url":"git://github.com/bustlelabs/content-kit-editor.git","ssh_url":"git@github.com:bustlelabs/content-kit-editor.git","clone_url":"https://github.com/bustlelabs/content-kit-editor.git","svn_url":"https://github.com/bustlelabs/content-kit-editor","homepage":"","size":1932,"stargazers_count":69,"watchers_count":69,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":8,"forks":7,"open_issues":8,"watchers":69,"default_branch":"master"}},"base":{"label":"bustlelabs:master","ref":"master","sha":"b4efbef396d84736b9465315e6f29f061875957c","user":{"login":"bustlelabs","id":2198187,"avatar_url":"https://avatars.githubusercontent.com/u/2198187?v=3","gravatar_id":"","url":"https://api.github.com/users/bustlelabs","html_url":"https://github.com/bustlelabs","followers_url":"https://api.github.com/users/bustlelabs/followers","following_url":"https://api.github.com/users/bustlelabs/following{/other_user}","gists_url":"https://api.github.com/users/bustlelabs/gists{/gist_id}","starred_url":"https://api.github.com/users/bustlelabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bustlelabs/subscriptions","organizations_url":"https://api.github.com/users/bustlelabs/orgs","repos_url":"https://api.github.com/users/bustlelabs/repos","events_url":"https://api.github.com/users/bustlelabs/events{/privacy}","received_events_url":"https://api.github.com/users/bustlelabs/received_events","type":"Organization","site_admin":false},"repo":{"id":21694966,"name":"content-kit-editor","full_name":"bustlelabs/content-kit-editor","owner":{"login":"bustlelabs","id":2198187,"avatar_url":"https://avatars.githubusercontent.com/u/2198187?v=3","gravatar_id":"","url":"https://api.github.com/users/bustlelabs","html_url":"https://github.com/bustlelabs","followers_url":"https://api.github.com/users/bustlelabs/followers","following_url":"https://api.github.com/users/bustlelabs/following{/other_user}","gists_url":"https://api.github.com/users/bustlelabs/gists{/gist_id}","starred_url":"https://api.github.com/users/bustlelabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bustlelabs/subscriptions","organizations_url":"https://api.github.com/users/bustlelabs/orgs","repos_url":"https://api.github.com/users/bustlelabs/repos","events_url":"https://api.github.com/users/bustlelabs/events{/privacy}","received_events_url":"https://api.github.com/users/bustlelabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bustlelabs/content-kit-editor","description":"A modern, minimalist WYSIWYG editor","fork":false,"url":"https://api.github.com/repos/bustlelabs/content-kit-editor","forks_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/forks","keys_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/teams","hooks_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/hooks","issue_events_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues/events{/number}","events_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/events","assignees_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/assignees{/user}","branches_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/branches{/branch}","tags_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/tags","blobs_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/refs{/sha}","trees_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/statuses/{sha}","languages_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/languages","stargazers_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/stargazers","contributors_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/contributors","subscribers_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/subscribers","subscription_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/subscription","commits_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/commits{/sha}","git_commits_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/git/commits{/sha}","comments_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/comments{/number}","issue_comment_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues/comments{/number}","contents_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/contents/{+path}","compare_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/merges","archive_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/downloads","issues_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues{/number}","pulls_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls{/number}","milestones_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/milestones{/number}","notifications_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/labels{/name}","releases_url":"https://api.github.com/repos/bustlelabs/content-kit-editor/releases{/id}","created_at":"2014-07-10T13:22:19Z","updated_at":"2015-08-11T14:39:23Z","pushed_at":"2015-08-12T17:40:41Z","git_url":"git://github.com/bustlelabs/content-kit-editor.git","ssh_url":"git@github.com:bustlelabs/content-kit-editor.git","clone_url":"https://github.com/bustlelabs/content-kit-editor.git","svn_url":"https://github.com/bustlelabs/content-kit-editor","homepage":"","size":1932,"stargazers_count":69,"watchers_count":69,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":8,"forks":7,"open_issues":8,"watchers":69,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/53"},"html":{"href":"https://github.com/bustlelabs/content-kit-editor/pull/53"},"issue":{"href":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues/53"},"comments":{"href":"https://api.github.com/repos/bustlelabs/content-kit-editor/issues/53/comments"},"review_comments":{"href":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/53/comments"},"review_comment":{"href":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bustlelabs/content-kit-editor/pulls/53/commits"},"statuses":{"href":"https://api.github.com/repos/bustlelabs/content-kit-editor/statuses/3f113b303fd1addf79a05a87e0c3d58eb4b7ade8"}}}}