todo-tree icon indicating copy to clipboard operation
todo-tree copied to clipboard

Duplicate issues in TODOs view when changing view modes

Open baincd opened this issue 1 year ago • 1 comments

Recreate

Setup

  • Default Todo Tree settings
  • open a new workspace in VS Code

Steps

  1. Create a new file
  2. Add [ ] Hello to the file
  3. Save the file as file1
  4. Add World to the todo line in the file (so it now says "[ ] Hello World") - DO NOT SAVE
  5. Press the refresh button on the TODOs view
  6. Toggle either the flat/tree/tags-only button OR group-by-tags button

Both the todo saved in the file ([ ] Hello) and the todo in the editor ([ ] Hello World) are displayed image

Click refresh cleans up the duplicate (removing the version saved to disk). But pressing the flat/tree/tags-only or group-by-tags button again reintroduces the extra todo

baincd avatar Mar 09 '24 15:03 baincd

This issue seems similar to #637. I was able to track down the starting place for this issue (the refresh() function in src/extension.js), but I am unable to find the root cause.

However, I tried applying similar fixes to this issue as was used to fix #637, and they do appear to fix the issue. I haven't considered the performance impact of rebuilding the tree when changing the view mode, so that may need to be taken into consideration.

src/extension.js
@@ -863,12 +863,18 @@ function activate( context )
     function refresh()
     {
         searchResults.markAsNotAdded();
 
         provider.clear( vscode.workspace.workspaceFolders );
         provider.rebuild();
 
-        refreshOpenFiles();
 
-        addResultsToTree();
+        // FIX1 - just rebuild the entire tree
+        rebuild();
+
+        // OR FIX2 - call these methods the same was as is done in rebuild(), but without having to do the full rebuild
+        iterateSearchList()
+            .finally( refreshOpenFiles )
+            .then( addResultsToTree );
+
         setButtonsAndContext();
     }

baincd avatar Mar 09 '24 15:03 baincd