From 63e57957cd12486bc17bb231a38e5d88b282088b Mon Sep 17 00:00:00 2001 From: Chanakya Bhardwaj Date: Thu, 29 Jul 2021 09:42:15 +0000 Subject: [PATCH 1/2] Compute the index of the current task list item using only other task list items. --- src/task-lists-element.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/task-lists-element.ts b/src/task-lists-element.ts index ce7d318..c103cfa 100644 --- a/src/task-lists-element.ts +++ b/src/task-lists-element.ts @@ -132,7 +132,11 @@ function position(checkbox: HTMLInputElement): [number, number] { const list = taskList(checkbox) if (!list) throw new Error('.contains-task-list not found') const item = checkbox.closest('.task-list-item') - const index = item ? Array.from(list.children).indexOf(item) : -1 + const index = item + ? Array.from(list.children) + .filter(el => el.classList.contains('task-list-item')) + .indexOf(item) + : -1 return [listIndex(list), index] } From fdaa68a9bf17e8f6a919c8a8445e588f039cc013 Mon Sep 17 00:00:00 2001 From: Chanakya Bhardwaj Date: Thu, 29 Jul 2021 14:48:52 +0200 Subject: [PATCH 2/2] Update src/task-lists-element.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kristján Oddsson --- src/task-lists-element.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/task-lists-element.ts b/src/task-lists-element.ts index c103cfa..f710b2a 100644 --- a/src/task-lists-element.ts +++ b/src/task-lists-element.ts @@ -132,11 +132,8 @@ function position(checkbox: HTMLInputElement): [number, number] { const list = taskList(checkbox) if (!list) throw new Error('.contains-task-list not found') const item = checkbox.closest('.task-list-item') - const index = item - ? Array.from(list.children) - .filter(el => el.classList.contains('task-list-item')) - .indexOf(item) - : -1 + const listItems = Array.from(list.children).filter(el => el.classList.contains('task-list-item')) + const index = item ? listItems.indexOf(item) : -1 return [listIndex(list), index] }