ONE-vscode icon indicating copy to clipboard operation
ONE-vscode copied to clipboard

[OneExplorer] Keep collapsing state of node

Open dayo09 opened this issue 2 years ago • 3 comments

What?

Previously, when refresh occurs due to a file's creation/change/deletion, all the tree nodes are built from scratch and the collapsing status resets.

By #1401, it's not building the whole tree but from the parent node. Let's try to keep the collapsing status of the node, now.

From

LGTM. Thank you for your effort!

Question: Isn't it possible to keep the Expand/Collapse of the model node in its original state after executing the 'Rename Model' command? It seems to be inconvenient to collapse unconditionally.

Originally posted by @lemmaa in https://github.com/Samsung/ONE-vscode/pull/1361#pullrequestreview-1147570225

Prerequisite

  • [x] #1401

dayo09 avatar Oct 24 '22 08:10 dayo09

How?

Node node -> node.getTreeItem() -> OneNode oneNode
// oneNode.node === node

OneNode has a collapsible state

When refreshed, we need to pass 'initialCollapsibleState' from Node to OneNode, which must be disposed once it's used. Otherwise, the state will be applied everytime the node is re-builded.....

dayo09 avatar Oct 26 '22 01:10 dayo09

How? (2)

By using onDidRenameFiles, we don't need to re-create all the Node&OneNode but just replace the url and the file name. Then, the other contexts including collapsible state will be easy to keep

      vscode.workspace.onDidRenameFiles((e)=>{
        e.files.forEach(file=>{
          console.log(file.oldUri, file.newUri);
        });
      }),

dayo09 avatar Oct 31 '22 01:10 dayo09

DID IT!

1031-rename-keep

How?

  • [x] Replace all the other apis from vscode.fs to vscode.workspace.applyEdit. Otherwise, the above change will triger other create/delete events again which makes unexpected refresh on the tree.
    • #1437
    • It's to use onDidRenameFiles api. It only works with vscode.workspace.applyEdit, not all the file system changes.
  • [ ] Replace rename api from vscode.fs to vscode.workspace.applyEdit and event listener from fileSystemWatcher to vscode.workspace.onDidRenameFiles.
  • [x] Add id to Node
    • #1438
    • id is required to keep the same TreeItem, otherwise the tree view will generate a new TreeItem when the label(path) is different.
  • [ ] Update the node's uri while persisting the Node using rename api.

dayo09 avatar Oct 31 '22 02:10 dayo09