Browse Source

fixed filtering of separators (close #37)

Nicolas Cannasse 5 years ago
parent
commit
e7457b970c
2 changed files with 21 additions and 3 deletions
  1. 20 3
      hide/comp/cdb/Editor.hx
  2. 1 0
      hide/comp/cdb/Table.hx

+ 20 - 3
hide/comp/cdb/Editor.hx

@@ -139,17 +139,26 @@ class Editor extends Component {
 		case K.SPACE:
 			e.preventDefault(); // prevent scroll
 		case K.ESCAPE:
-			if( currentFilter != null ) searchFilter(null);
+			if( currentFilter != null ) {
+				searchFilter(null);
+				searchBox.hide();
+			}
 		}
 		return false;
 	}
 
+	public function updateFilter() {
+		searchFilter(currentFilter);
+	}
+
 	function searchFilter( filter : String ) {
 		if( filter == "" ) filter = null;
 		if( filter != null ) filter = filter.toLowerCase();
 
-		var lines = element.find("table.cdb-sheet > tbody > tr").not(".head");
-		lines.removeClass("filtered");
+		var all = element.find("table.cdb-sheet > tbody > tr").not(".head");
+		var seps = all.filter(".separator");
+		var lines = all.not(".separator");
+		all.removeClass("filtered");
 		if( filter != null ) {
 			for( t in lines ) {
 				if( t.textContent.toLowerCase().indexOf(filter) < 0 )
@@ -159,8 +168,16 @@ class Editor extends Component {
 				lines = lines.filter(".list").not(".filtered").prev();
 				lines.removeClass("filtered");
 			}
+			all = all.not(".filtered").not(".hidden");
+			for( s in seps.elements() ) {
+				var idx = all.index(s);
+				if( idx == all.length - 1 || new Element(all.get(idx+1)).hasClass("separator") ) {
+					s.addClass("filtered");
+				}
+			}
 		}
 		currentFilter = filter;
+		cursor.update();
 	}
 
 	function onCopy() {

+ 1 - 0
hide/comp/cdb/Table.hx

@@ -278,6 +278,7 @@ class Table extends Component {
 			for( l in getLines() ) {
 				if( hidden ) l.hide() else l.create();
 			}
+			editor.updateFilter();
 		});
 		return { hidden : hidden, element : sep };
 	}