Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #142 from jaredly/fix-search-results
Browse files Browse the repository at this point in the history
Fix search results
  • Loading branch information
jaredly committed Aug 12, 2015
2 parents 5cc7547 + a5d4ae0 commit 412073d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions frontend/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class Store extends EventEmitter {
});
} else {
this.searchRoots = this._nodes.entrySeq()
.filter(([key, val]) => nodeMatchesText(val, needle))
.filter(([key, val]) => nodeMatchesText(val, needle, key, this))
.map(([key, val]) => key)
.toList();
}
Expand Down Expand Up @@ -347,7 +347,7 @@ class Store extends EventEmitter {
if (nodeType !== 'Wrapper' && nodeType !== 'Native') {
return id;
}
if (nodeType === 'Native' && this.get(this._parents.get(id)).get('nodeType') !== 'NativeWrapper') {
if (nodeType === 'Native' && (!up || this.get(this._parents.get(id)).get('nodeType') !== 'NativeWrapper')) {
return id;
}
if (up) {
Expand Down Expand Up @@ -427,7 +427,7 @@ class Store extends EventEmitter {
var curNodes = this._nodesByName.get(data.name) || new Set();
this._nodesByName = this._nodesByName.set(data.name, curNodes.add(data.id));
this.emit(data.id);
if (this.searchRoots && nodeMatchesText(map, this.searchText.toLowerCase())) {
if (this.searchRoots && nodeMatchesText(map, this.searchText.toLowerCase(), data.id, this)) {
this.searchRoots = this.searchRoots.push(data.id);
this.emit('searchRoots');
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/nodeMatchesText.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
'use strict';

import type {Map} from 'immutable';
import type Store from './Store';

function nodeMatchesText(node: Map, needle: string): boolean {
function nodeMatchesText(node: Map, needle: string, key: string, store: Store): boolean {
var name = node.get('name');
if (node.get('nodeType') === 'Native' && store.get(store.getParent(key)).get('nodeType') === 'NativeWrapper') {
return false;
}
if (name) {
if (node.get('nodeType') !== 'Wrapper' && name.toLowerCase().indexOf(needle) !== -1) {
return true;
Expand Down

0 comments on commit 412073d

Please sign in to comment.