Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2019-01-29 19:46:04 +0300
committerFatih Acet <acetfatih@gmail.com>2019-01-31 01:18:20 +0300
commit58cd21c2ad802c1652311f025c599e0df604669c (patch)
tree0b0ed65bc247bc3d8dfdcd1bfa477ee57a58faff /app/services/task_list_toggle_service.rb
parenta3a847f8624b5f5b10d5665725df2090a1f631ba (diff)
Use the sourcepos attribute for finding tasks
Diffstat (limited to 'app/services/task_list_toggle_service.rb')
-rw-r--r--app/services/task_list_toggle_service.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/services/task_list_toggle_service.rb b/app/services/task_list_toggle_service.rb
index 1b0a5965235..3ba0faa5009 100644
--- a/app/services/task_list_toggle_service.rb
+++ b/app/services/task_list_toggle_service.rb
@@ -11,7 +11,7 @@
class TaskListToggleService
attr_reader :updated_markdown, :updated_markdown_html
- def initialize(markdown, markdown_html, line_source:, line_number:, currently_checked:, index:, sourcepos: false)
+ def initialize(markdown, markdown_html, line_source:, line_number:, currently_checked:, index:, sourcepos: true)
@markdown, @markdown_html = markdown, markdown_html
@line_source, @line_number = line_source, line_number
@currently_checked = currently_checked
@@ -62,6 +62,13 @@ class TaskListToggleService
@updated_markdown_html = html.to_html
end
+ # When using CommonMark, we should be able to use the embedded `sourcepos` attribute to
+ # target the exact line in the DOM. For RedCarpet, we need to use the index of the checkbox
+ # that was checked and match it with what we think is the same checkbox.
+ # The reason `sourcepos` is slightly more reliable is the case where a line of text is
+ # changed from a regular line into a checkbox (or vice versa). Then the checked index
+ # in the UI will be off from the list of checkboxes we've calculated locally.
+ # It's a rare circumstance, but since we can account for it, we do.
def get_html_checkbox(html)
if use_sourcepos
html.css(".task-list-item[data-sourcepos^='#{line_number}:'] > input.task-list-item-checkbox").first