{"action":"created","comment":{"url":"https://api.github.com/repos/oltodo/hodorjs/pulls/comments/24970526","id":24970526,"diff_hunk":"@@ -0,0 +1,215 @@\n+'use strict';\n+\n+var Range = require('../../../lib/math/range');\n+var Clone = require('lodash/lang/clone');\n+\n+/**\n+ * @type {{}}\n+ */\n+var ParagraphManager = {};\n+\n+/**\n+ * Manage the paragraph by adding text\n+ *\n+ * @param block\n+ * @param text\n+ * @param offset\n+ * @returns {*|Array}\n+ */\n+ParagraphManager.addText = function (block, text, offset) {\n+  var beforeText = block.text.substring(0, offset);\n+  var afterText  = block.text.substring(offset, block.text.length);\n+\n+  block.text = beforeText + text + afterText;\n+\n+  var textLength = text.length;\n+\n+  if (block.tags === undefined) {\n+    return block;\n+  }\n+\n+  block.tags.map(function(tag) {\n+    if (offset <= tag.offsets.start) {\n+      tag.offsets.start += textLength;\n+      tag.offsets.end += textLength;\n+    } else {\n+      if (offset <= tag.offsets.end) {\n+        tag.offsets.end += textLength;\n+      }\n+    }\n+  });\n+\n+  return block;\n+};\n+\n+\n+/**\n+ * Manage the paragraph by removing text\n+ *\n+ * @param block\n+ * @param length if negative, remove by left else right\n+ * @param offset\n+ * @returns {*|Array}\n+ */\n+ParagraphManager.removeText = function (block, length, offset) {\n+  if (length > 0) {\n+    var startOffset = offset;\n+    var endOffset   = offset + length;\n+  } else {\n+    var startOffset = offset + length;\n+    var endOffset   = offset;\n+  }\n+\n+  var beforeText = block.text.substring(0, startOffset);\n+  var afterText  = block.text.substring(endOffset, block.text.length);\n+\n+  block.text = beforeText + afterText;\n+\n+  if (block.tags === undefined) {\n+    return block;\n+  }\n+\n+  block.tags.map(function(tag) {\n+    if (endOffset < tag.offsets.start) {\n+      tag.offsets.start -= length;\n+      tag.offsets.end -= length;\n+    } else {\n+      if (endOffset < tag.offsets.end) {\n+        if (startOffset < tag.offsets.start) {\n+          var shiftStart = tag.offsets.start - startOffset;\n+          tag.offsets.start -= shiftStart;\n+          var shiftEnd = endOffset - tag.offsets.start;\n+          tag.offsets.end -= shiftEnd;\n+        } else {\n+          var shiftEnd = endOffset - startOffset;\n+          tag.offsets.end -= shiftEnd;\n+        }\n+      } else {\n+        if (startOffset <= tag.offsets.start) {\n+          var shiftStart = tag.offsets.start - startOffset;\n+          tag.offsets.start -= shiftStart;\n+          tag.offsets.end = tag.offsets.start;\n+        } else if (startOffset < tag.offsets.end) {\n+          var shiftEnd = tag.offsets.end - startOffset;\n+          tag.offsets.end -= shiftEnd;\n+        }\n+      }\n+    }\n+  });\n+\n+  return block;\n+};\n+\n+/**\n+ * Manage the paragraph by adding tag\n+ *\n+ * @param block\n+ * @param type\n+ * @param range\n+ * @returns {*|Array}\n+ */\n+ParagraphManager.addTag = function (block, type, range, data) {\n+  data = data || {};\n+  var modifiedTags = [];\n+\n+  if (block.tags === undefined) {\n+    block.tags = [];\n+  }\n+\n+  block.tags.map(function(tag) {\n+    var tagRange = new Range(tag.offsets.start, tag.offsets.end);\n+\n+    if ( tag.type === type && Range.hasIntersection(tagRange, range)) {\n+      range.includeRange(tagRange);\n+    } else {\n+      modifiedTags.push(tag);\n+    }\n+  });\n+\n+  block.tags = modifiedTags;\n+  data.type = type;\n+  data.offsets = {\n+    start: range.start,\n+    end:   range.end\n+  };\n+  block.tags.push(data)\n+\n+  return block;\n+};\n+\n+/**\n+ * Manage the paragraph by removing tag in the range\n+ *\n+ * @param block\n+ * @param type\n+ * @param range\n+ * @returns {*|Array}\n+ */\n+ParagraphManager.removeTag = function (block, type, range) {\n+  if (block.tags === undefined) {\n+    return block;\n+  }\n+\n+  var modifiedTags = [];\n+  block.tags.map(function(tag) {\n+    var tagRange = new Range(tag.offsets.start, tag.offsets.end);\n+    if (tag.type === type && Range.hasIntersection(tagRange, range)) {\n+      if (Range.contains(range, tagRange)) { // If removed range is overlapped the tag, don't conserve the tag\n+        return;\n+      } else if (Range.contains(tagRange, range)) { // If tag is overlapped the removed range, bisect the tag\n+        var firstTag  = Clone(tag, true);\n+        var secondTag = Clone(tag, true);\n+\n+        firstTag.offsets.end = range.start;\n+        secondTag.offsets.start = range.end;\n+\n+        modifiedTags.push(firstTag);\n+        modifiedTags.push(secondTag);\n+        return;\n+      } else if (tagRange.start > range.start) { // If removed range begin before tag\n+        tag.offsets.start = range.end;","path":"src/js/services/manager/paragraph-manager.js","position":170,"original_position":170,"commit_id":"5dd5879250265bf2d21850e650155ad62572143a","original_commit_id":"5dd5879250265bf2d21850e650155ad62572143a","user":{"login":"oltodo","id":483842,"avatar_url":"https://avatars.githubusercontent.com/u/483842?v=3","gravatar_id":"","url":"https://api.github.com/users/oltodo","html_url":"https://github.com/oltodo","followers_url":"https://api.github.com/users/oltodo/followers","following_url":"https://api.github.com/users/oltodo/following{/other_user}","gists_url":"https://api.github.com/users/oltodo/gists{/gist_id}","starred_url":"https://api.github.com/users/oltodo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oltodo/subscriptions","organizations_url":"https://api.github.com/users/oltodo/orgs","repos_url":"https://api.github.com/users/oltodo/repos","events_url":"https://api.github.com/users/oltodo/events{/privacy}","received_events_url":"https://api.github.com/users/oltodo/received_events","type":"User","site_admin":false},"body":"Je comprend pas..","created_at":"2015-02-19T07:51:15Z","updated_at":"2015-02-19T07:51:15Z","html_url":"https://github.com/oltodo/hodorjs/pull/27#discussion_r24970526","pull_request_url":"https://api.github.com/repos/oltodo/hodorjs/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/oltodo/hodorjs/pulls/comments/24970526"},"html":{"href":"https://github.com/oltodo/hodorjs/pull/27#discussion_r24970526"},"pull_request":{"href":"https://api.github.com/repos/oltodo/hodorjs/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/oltodo/hodorjs/pulls/27","id":29455517,"html_url":"https://github.com/oltodo/hodorjs/pull/27","diff_url":"https://github.com/oltodo/hodorjs/pull/27.diff","patch_url":"https://github.com/oltodo/hodorjs/pull/27.patch","issue_url":"https://api.github.com/repos/oltodo/hodorjs/issues/27","number":27,"state":"open","locked":false,"title":"Implementation of paragraph manager","user":{"login":"lotholf","id":1133480,"avatar_url":"https://avatars.githubusercontent.com/u/1133480?v=3","gravatar_id":"","url":"https://api.github.com/users/lotholf","html_url":"https://github.com/lotholf","followers_url":"https://api.github.com/users/lotholf/followers","following_url":"https://api.github.com/users/lotholf/following{/other_user}","gists_url":"https://api.github.com/users/lotholf/gists{/gist_id}","starred_url":"https://api.github.com/users/lotholf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lotholf/subscriptions","organizations_url":"https://api.github.com/users/lotholf/orgs","repos_url":"https://api.github.com/users/lotholf/repos","events_url":"https://api.github.com/users/lotholf/events{/privacy}","received_events_url":"https://api.github.com/users/lotholf/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-17T16:26:16Z","updated_at":"2015-02-19T07:51:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"702f7c84a215b901675202023f81106f964fbf7e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/oltodo/hodorjs/pulls/27/commits","review_comments_url":"https://api.github.com/repos/oltodo/hodorjs/pulls/27/comments","review_comment_url":"https://api.github.com/repos/oltodo/hodorjs/pulls/comments/{number}","comments_url":"https://api.github.com/repos/oltodo/hodorjs/issues/27/comments","statuses_url":"https://api.github.com/repos/oltodo/hodorjs/statuses/5dd5879250265bf2d21850e650155ad62572143a","head":{"label":"feature-paragraph-manager","ref":"feature-paragraph-manager","sha":"5dd5879250265bf2d21850e650155ad62572143a","user":{"login":"oltodo","id":483842,"avatar_url":"https://avatars.githubusercontent.com/u/483842?v=3","gravatar_id":"","url":"https://api.github.com/users/oltodo","html_url":"https://github.com/oltodo","followers_url":"https://api.github.com/users/oltodo/followers","following_url":"https://api.github.com/users/oltodo/following{/other_user}","gists_url":"https://api.github.com/users/oltodo/gists{/gist_id}","starred_url":"https://api.github.com/users/oltodo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oltodo/subscriptions","organizations_url":"https://api.github.com/users/oltodo/orgs","repos_url":"https://api.github.com/users/oltodo/repos","events_url":"https://api.github.com/users/oltodo/events{/privacy}","received_events_url":"https://api.github.com/users/oltodo/received_events","type":"User","site_admin":false},"repo":{"id":29241958,"name":"hodorjs","full_name":"oltodo/hodorjs","owner":{"login":"oltodo","id":483842,"avatar_url":"https://avatars.githubusercontent.com/u/483842?v=3","gravatar_id":"","url":"https://api.github.com/users/oltodo","html_url":"https://github.com/oltodo","followers_url":"https://api.github.com/users/oltodo/followers","following_url":"https://api.github.com/users/oltodo/following{/other_user}","gists_url":"https://api.github.com/users/oltodo/gists{/gist_id}","starred_url":"https://api.github.com/users/oltodo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oltodo/subscriptions","organizations_url":"https://api.github.com/users/oltodo/orgs","repos_url":"https://api.github.com/users/oltodo/repos","events_url":"https://api.github.com/users/oltodo/events{/privacy}","received_events_url":"https://api.github.com/users/oltodo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/oltodo/hodorjs","description":"[WIP] A Javascript Block-Style & Ultra-Structured Text editor","fork":false,"url":"https://api.github.com/repos/oltodo/hodorjs","forks_url":"https://api.github.com/repos/oltodo/hodorjs/forks","keys_url":"https://api.github.com/repos/oltodo/hodorjs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/oltodo/hodorjs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/oltodo/hodorjs/teams","hooks_url":"https://api.github.com/repos/oltodo/hodorjs/hooks","issue_events_url":"https://api.github.com/repos/oltodo/hodorjs/issues/events{/number}","events_url":"https://api.github.com/repos/oltodo/hodorjs/events","assignees_url":"https://api.github.com/repos/oltodo/hodorjs/assignees{/user}","branches_url":"https://api.github.com/repos/oltodo/hodorjs/branches{/branch}","tags_url":"https://api.github.com/repos/oltodo/hodorjs/tags","blobs_url":"https://api.github.com/repos/oltodo/hodorjs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/oltodo/hodorjs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/oltodo/hodorjs/git/refs{/sha}","trees_url":"https://api.github.com/repos/oltodo/hodorjs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/oltodo/hodorjs/statuses/{sha}","languages_url":"https://api.github.com/repos/oltodo/hodorjs/languages","stargazers_url":"https://api.github.com/repos/oltodo/hodorjs/stargazers","contributors_url":"https://api.github.com/repos/oltodo/hodorjs/contributors","subscribers_url":"https://api.github.com/repos/oltodo/hodorjs/subscribers","subscription_url":"https://api.github.com/repos/oltodo/hodorjs/subscription","commits_url":"https://api.github.com/repos/oltodo/hodorjs/commits{/sha}","git_commits_url":"https://api.github.com/repos/oltodo/hodorjs/git/commits{/sha}","comments_url":"https://api.github.com/repos/oltodo/hodorjs/comments{/number}","issue_comment_url":"https://api.github.com/repos/oltodo/hodorjs/issues/comments/{number}","contents_url":"https://api.github.com/repos/oltodo/hodorjs/contents/{+path}","compare_url":"https://api.github.com/repos/oltodo/hodorjs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/oltodo/hodorjs/merges","archive_url":"https://api.github.com/repos/oltodo/hodorjs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/oltodo/hodorjs/downloads","issues_url":"https://api.github.com/repos/oltodo/hodorjs/issues{/number}","pulls_url":"https://api.github.com/repos/oltodo/hodorjs/pulls{/number}","milestones_url":"https://api.github.com/repos/oltodo/hodorjs/milestones{/number}","notifications_url":"https://api.github.com/repos/oltodo/hodorjs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/oltodo/hodorjs/labels{/name}","releases_url":"https://api.github.com/repos/oltodo/hodorjs/releases{/id}","created_at":"2015-01-14T11:52:43Z","updated_at":"2015-02-11T06:56:08Z","pushed_at":"2015-02-18T15:44:22Z","git_url":"git://github.com/oltodo/hodorjs.git","ssh_url":"git@github.com:oltodo/hodorjs.git","clone_url":"https://github.com/oltodo/hodorjs.git","svn_url":"https://github.com/oltodo/hodorjs","homepage":"","size":1380,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":4,"default_branch":"master"}},"base":{"label":"master","ref":"master","sha":"03f2c831872ccd9ca2ed01eccfa79d3230929234","user":{"login":"oltodo","id":483842,"avatar_url":"https://avatars.githubusercontent.com/u/483842?v=3","gravatar_id":"","url":"https://api.github.com/users/oltodo","html_url":"https://github.com/oltodo","followers_url":"https://api.github.com/users/oltodo/followers","following_url":"https://api.github.com/users/oltodo/following{/other_user}","gists_url":"https://api.github.com/users/oltodo/gists{/gist_id}","starred_url":"https://api.github.com/users/oltodo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oltodo/subscriptions","organizations_url":"https://api.github.com/users/oltodo/orgs","repos_url":"https://api.github.com/users/oltodo/repos","events_url":"https://api.github.com/users/oltodo/events{/privacy}","received_events_url":"https://api.github.com/users/oltodo/received_events","type":"User","site_admin":false},"repo":{"id":29241958,"name":"hodorjs","full_name":"oltodo/hodorjs","owner":{"login":"oltodo","id":483842,"avatar_url":"https://avatars.githubusercontent.com/u/483842?v=3","gravatar_id":"","url":"https://api.github.com/users/oltodo","html_url":"https://github.com/oltodo","followers_url":"https://api.github.com/users/oltodo/followers","following_url":"https://api.github.com/users/oltodo/following{/other_user}","gists_url":"https://api.github.com/users/oltodo/gists{/gist_id}","starred_url":"https://api.github.com/users/oltodo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oltodo/subscriptions","organizations_url":"https://api.github.com/users/oltodo/orgs","repos_url":"https://api.github.com/users/oltodo/repos","events_url":"https://api.github.com/users/oltodo/events{/privacy}","received_events_url":"https://api.github.com/users/oltodo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/oltodo/hodorjs","description":"[WIP] A Javascript Block-Style & Ultra-Structured Text editor","fork":false,"url":"https://api.github.com/repos/oltodo/hodorjs","forks_url":"https://api.github.com/repos/oltodo/hodorjs/forks","keys_url":"https://api.github.com/repos/oltodo/hodorjs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/oltodo/hodorjs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/oltodo/hodorjs/teams","hooks_url":"https://api.github.com/repos/oltodo/hodorjs/hooks","issue_events_url":"https://api.github.com/repos/oltodo/hodorjs/issues/events{/number}","events_url":"https://api.github.com/repos/oltodo/hodorjs/events","assignees_url":"https://api.github.com/repos/oltodo/hodorjs/assignees{/user}","branches_url":"https://api.github.com/repos/oltodo/hodorjs/branches{/branch}","tags_url":"https://api.github.com/repos/oltodo/hodorjs/tags","blobs_url":"https://api.github.com/repos/oltodo/hodorjs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/oltodo/hodorjs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/oltodo/hodorjs/git/refs{/sha}","trees_url":"https://api.github.com/repos/oltodo/hodorjs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/oltodo/hodorjs/statuses/{sha}","languages_url":"https://api.github.com/repos/oltodo/hodorjs/languages","stargazers_url":"https://api.github.com/repos/oltodo/hodorjs/stargazers","contributors_url":"https://api.github.com/repos/oltodo/hodorjs/contributors","subscribers_url":"https://api.github.com/repos/oltodo/hodorjs/subscribers","subscription_url":"https://api.github.com/repos/oltodo/hodorjs/subscription","commits_url":"https://api.github.com/repos/oltodo/hodorjs/commits{/sha}","git_commits_url":"https://api.github.com/repos/oltodo/hodorjs/git/commits{/sha}","comments_url":"https://api.github.com/repos/oltodo/hodorjs/comments{/number}","issue_comment_url":"https://api.github.com/repos/oltodo/hodorjs/issues/comments/{number}","contents_url":"https://api.github.com/repos/oltodo/hodorjs/contents/{+path}","compare_url":"https://api.github.com/repos/oltodo/hodorjs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/oltodo/hodorjs/merges","archive_url":"https://api.github.com/repos/oltodo/hodorjs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/oltodo/hodorjs/downloads","issues_url":"https://api.github.com/repos/oltodo/hodorjs/issues{/number}","pulls_url":"https://api.github.com/repos/oltodo/hodorjs/pulls{/number}","milestones_url":"https://api.github.com/repos/oltodo/hodorjs/milestones{/number}","notifications_url":"https://api.github.com/repos/oltodo/hodorjs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/oltodo/hodorjs/labels{/name}","releases_url":"https://api.github.com/repos/oltodo/hodorjs/releases{/id}","created_at":"2015-01-14T11:52:43Z","updated_at":"2015-02-11T06:56:08Z","pushed_at":"2015-02-18T15:44:22Z","git_url":"git://github.com/oltodo/hodorjs.git","ssh_url":"git@github.com:oltodo/hodorjs.git","clone_url":"https://github.com/oltodo/hodorjs.git","svn_url":"https://github.com/oltodo/hodorjs","homepage":"","size":1380,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/oltodo/hodorjs/pulls/27"},"html":{"href":"https://github.com/oltodo/hodorjs/pull/27"},"issue":{"href":"https://api.github.com/repos/oltodo/hodorjs/issues/27"},"comments":{"href":"https://api.github.com/repos/oltodo/hodorjs/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/oltodo/hodorjs/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/oltodo/hodorjs/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/oltodo/hodorjs/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/oltodo/hodorjs/statuses/5dd5879250265bf2d21850e650155ad62572143a"}}}}