瀏覽代碼

[fancytree] Improved search inconsistensies

Clément Espeute 2 月之前
父節點
當前提交
56fdcdda34
共有 2 個文件被更改,包括 30 次插入4 次删除
  1. 5 0
      hide/comp/FancySearch.hx
  2. 25 4
      hide/comp/FancyTree.hx

+ 5 - 0
hide/comp/FancySearch.hx

@@ -5,6 +5,7 @@ class FancySearch extends hide.comp.Component {
 	var open = false;
 	var input : js.html.InputElement;
 
+
 	public override function new(parent: Element = null, target: Element = null) {
 		var el = new hide.Element('
 			<fancy-search>
@@ -28,6 +29,10 @@ class FancySearch extends hide.comp.Component {
 		}
 	}
 
+	public function getValue() {
+		return input.value;
+	}
+
 	public dynamic function onSearch(search: String, enter: Bool) : Void {};
 
 	public function hasFocus() : Bool {

+ 25 - 4
hide/comp/FancyTree.hx

@@ -353,6 +353,9 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 
 			searchBarClosable.toggleOpen(true);
 			searchBar.focus();
+			currentSearch = searchBar.getValue().toLowerCase();
+			queueRefresh(Search);
+			return;
 		}
 
 		if (hide.ui.Keys.matchJsEvent("rename", e, ide.currentConfig) && selection.iterator().hasNext()) {
@@ -361,6 +364,7 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 
 			if (currentItem != null)
 				rename(currentItem.item);
+			return;
 		}
 
 		if (e.key == "Escape") {
@@ -373,10 +377,17 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 				element.get(0).focus();
 				currentSearch = "";
 				queueRefresh(Search);
+				queueRefresh(FocusCurrent);
 			}
+			return;
 		}
 
 		if (e.key.length == 1) {
+			if (searchBar.hasFocus())
+				return;
+			e.stopPropagation();
+			e.preventDefault();
+
 			var time = haxe.Timer.stamp();
 			if (time - gotoFileLastTime > gotoFileKeyMaxDelay) {
 				gotoFileCurrentMatch = "";
@@ -399,6 +410,7 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 					break;
 				}
 			}
+			return;
 		}
 
 		var delta = 0;
@@ -595,11 +607,8 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 
 			if (parentMatch) {
 				child.filterState |= Visible;
-				filterRec(child.children, parentMatch);
-				return true;
 			}
 
-
 			if (currentSearch.length == 0) {
 				child.filterState |= Visible;
 			} else {
@@ -611,7 +620,6 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 				}
 			}
 
-
 			parentMatch = child.filterState.has(MatchSearch);
 
 			if(filterRec(child.children, parentMatch) && currentSearch.length > 0) {
@@ -815,6 +823,9 @@ class FancyTree<TreeItem> extends hide.comp.Component {
 
 
 	function setSelection(data: TreeItemData<TreeItem>, select: Bool) {
+		if (data == null)
+			return;
+
 		if (select) {
 			selection.set(cast data, true);
 		} else {
@@ -968,6 +979,16 @@ 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;
+			}
+		}
+
 		return (openState.get(data.uniqueName) ?? false) || data.filterState.has(Open);
 	}