Skip to content

Commit

Permalink
Fix folder selection jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
pertsevpv committed Dec 5, 2024
1 parent 93164c8 commit 76fb58f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void onDiffApplied(JsArray<JSObject> jsResult) {
LoggingJs.info("RemoteFolderDiffWindow.onDiffApplied");
var msg = BackendMessage.deserialize(jsResult);
rootModel.update(msg.root);
if (!isFiltered()) lastSendFrontendMsg.openedFolders.updateWithModel(rootModel);
if (!isFiltered()) lastSendFrontendMsg.openedFolders.updateDeepWithModel(rootModel);
updateNodes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,33 @@ public FrontendTreeNode findNode(Deque<String> path) {
return child.findNode(path);
}

public void updateDeepWithModel(RemoteFolderDiffModel model) {
if (children == null) return;
FrontendTreeNode[] newChildren = new FrontendTreeNode[model.children.length];
for (int i = 0; i < model.children.length; i++) {
var modelChild = model.child(i);
var nodeChild = child(i, modelChild.path, modelChild.isFile());
if (nodeChild == null) {
nodeChild = new FrontendTreeNode();
} else {
nodeChild.updateDeepWithModel(modelChild);
}
newChildren[i] = nodeChild;
}
children = newChildren;
}

// model can contain only less or equal elements
public void updateWithModel(RemoteFolderDiffModel model) {
if (children == null) return;
if (children.length != model.children.length) {
FrontendTreeNode[] newChildren = new FrontendTreeNode[model.children.length];
for (int i = 0, j = 0; i < model.children.length; j++) {
var modelChild = model.child(i);
var nodeChild = children[j];
if (modelChild.isFile() == nodeChild.isFile &&
modelChild.path.equals(nodeChild.name)
) newChildren[i++] = nodeChild;
}
children = newChildren;
FrontendTreeNode[] newChildren = new FrontendTreeNode[model.children.length];
for (int i = 0; i < model.children.length; i++) {
var modelChild = model.child(i);
var nodeChild = child(i, modelChild.path, modelChild.isFile());
if (nodeChild == null) nodeChild = new FrontendTreeNode();
newChildren[i] = nodeChild;
}
for (int i = 0; i < children.length; i++) children[i].updateWithModel(model.child(i));
children = newChildren;
}

public void collectPath(int[] path, ArrayWriter pathWriter, FolderDiffModel model, int side) {
Expand Down

0 comments on commit 76fb58f

Please sign in to comment.