瀏覽代碼

[filetree] Better handling of serach quit keep last selected item open

Clément Espeute 2 月之前
父節點
當前提交
8cd7aa49ac
共有 1 個文件被更改,包括 37 次插入15 次删除
  1. 37 15
      hide/comp/FancyTree.hx

+ 37 - 15
hide/comp/FancyTree.hx

@@ -98,8 +98,7 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 		}
 
 		searchBarClosable.onClose = () -> {
-			currentSearch = "";
-			queueRefresh(Search);
+			onSearchClose();
 		}
 
 		scroll = el.find("fancy-scroll").get(0);
@@ -346,6 +345,21 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 		edit.element.focus();
 	}
 
+	function onSearchClose() {
+		element.get(0).focus();
+		currentSearch = "";
+
+		if (currentItem != null) {
+			var cur = currentItem.parent;
+			while(cur != null) {
+				toggleDataOpen(cur, true);
+				cur = cur.parent;
+			}
+		}
+		queueRefresh(Search);
+		queueRefresh(FocusCurrent);
+	}
+
 	function inputHandler(e: js.html.KeyboardEvent) {
 		if (hide.ui.Keys.matchJsEvent("search", e, ide.currentConfig)) {
 			e.stopPropagation();
@@ -374,10 +388,8 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 
 				searchBarClosable.toggleOpen(false);
 				searchBar.blur();
-				element.get(0).focus();
-				currentSearch = "";
-				queueRefresh(Search);
-				queueRefresh(FocusCurrent);
+
+				onSearchClose();
 			}
 			return;
 		}
@@ -891,6 +903,16 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 		saveState();
 	}
 
+	function childOf(child: TreeItemData<TreeItem>, parent: TreeItemData<TreeItem>) {
+		var current = child;
+		while (current != null) {
+			if (current == parent) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 	function toggleDataOpen(data: TreeItemData<TreeItem>, ?force: Bool) {
 		var want = force ?? !isOpen(data);
 		if (currentSearch.length > 0) {
@@ -979,15 +1001,15 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 	}
 
 	function isOpen(data: TreeItemData<TreeItem>) {
-		// Always open folders that have selected children
-		for (selected => _ in selection) {
-			var cur = (cast selected:TreeItemData<TreeItem>).parent;
-			while (cur != null) {
-				if (data == cur)
-					return true;
-				cur = cur.parent;
-			}
-		}
+		// // Always open folders that have selected children
+		// for (selected => _ in selection) {
+		// 	var cur = (cast selected:TreeItemData<TreeItem>).parent;
+		// 	while (cur != null) {
+		// 		if (data == cur)
+		// 			return true;
+		// 		cur = cur.parent;
+		// 	}
+		// }
 
 		return (openState.get(data.uniqueName) ?? false) || data.filterState.has(Open);
 	}