diff --git a/assets/diagram-js.css b/assets/diagram-js.css index eab5bbccd..f1052ae49 100644 --- a/assets/diagram-js.css +++ b/assets/diagram-js.css @@ -984,7 +984,7 @@ background: var(--search-result-hover-background-color); } -.djs-element.djs-search-preselected .djs-outline { +.djs-search-open .djs-element .djs-outline { fill: var(--search-preselected-background-color) !important; } diff --git a/lib/features/search-pad/SearchPad.js b/lib/features/search-pad/SearchPad.js index a5e91cf3f..94d235c71 100644 --- a/lib/features/search-pad/SearchPad.js +++ b/lib/features/search-pad/SearchPad.js @@ -192,7 +192,6 @@ SearchPad.prototype._search = function(pattern) { }); if (!searchResults.length) { - this._clearMarkers(); this._selection.select(null); return; @@ -269,16 +268,6 @@ SearchPad.prototype._clearResults = function() { }; -/** - * Clears all markers. - */ -SearchPad.prototype._clearMarkers = function() { - for (var id in this._results) { - this._canvas.removeMarker(this._results[id].element, 'djs-search-preselected'); - } -}; - - /** * Get currently selected result. * @@ -347,6 +336,8 @@ SearchPad.prototype.open = function() { this._cachedSelection = this._selection.get(); this._cachedViewbox = this._canvas.viewbox(); + this._selection.select(null); + this._bindEvents(); this._open = true; @@ -395,8 +386,6 @@ SearchPad.prototype.close = function(restoreCached = true) { domClasses(this._canvas.getContainer()).remove('djs-search-open'); domClasses(this._container).remove('open'); - this._clearMarkers(); - this._clearResults(); this._searchInput.value = ''; @@ -437,8 +426,6 @@ SearchPad.prototype._preselect = function(node) { return; } - this._clearMarkers(); - // removing preselection from current node if (selectedNode) { domClasses(selectedNode).remove(SearchPad.RESULT_SELECTED_CLASS); @@ -455,8 +442,6 @@ SearchPad.prototype._preselect = function(node) { this._selection.select(element); - this._canvas.addMarker(element, 'djs-search-preselected'); - this._eventBus.fire('searchPad.preselected', element); }; diff --git a/test/spec/features/search-pad/SearchPadSpec.js b/test/spec/features/search-pad/SearchPadSpec.js index f11eabc95..9abc5e0f8 100644 --- a/test/spec/features/search-pad/SearchPadSpec.js +++ b/test/spec/features/search-pad/SearchPadSpec.js @@ -25,6 +25,7 @@ var EVENTS = { selected: 'searchPad.selected' }; +var SEARCH_OPEN_MARKER_CLS = 'djs-search-open'; describe('features/search-pad', function() { @@ -179,31 +180,58 @@ describe('features/search-pad', function() { })); - it('should open', inject(function(searchPad) { + describe('open', function() { - // when - searchPad.open(); + it('should open', inject(function(searchPad) { - // then - expect(searchPad.isOpen()).to.equal(true); - expect(capturedEvents).to.eql([ EVENTS.opened ]); - })); + // when + searchPad.open(); + // then + expect(searchPad.isOpen()).to.equal(true); + expect(capturedEvents).to.eql([ EVENTS.opened ]); + })); - it('should error on open when provider not registered', inject(function(searchPad) { - // given - searchPad.registerProvider(undefined); + it('should clear selection', inject(function(searchPad, selection) { - // when - expect(function() { + // given + selection.select(elements.one.a); + + // when searchPad.open(); - }).to.throw('no search provider registered'); - // then - expect(searchPad.isOpen()).to.equal(false); - expect(capturedEvents).to.eql([]); - })); + // then + expect(selection.get()).to.be.empty; + })); + + + it('should attach marker to diagram container', inject(function(searchPad) { + + // when + searchPad.open(); + + // then + expectOpenMarker(true); + })); + + + it('should error when provider not registered', inject(function(searchPad) { + + // given + searchPad.registerProvider(undefined); + + // when + expect(function() { + searchPad.open(); + }).to.throw('no search provider registered'); + + // then + expect(searchPad.isOpen()).to.equal(false); + expect(capturedEvents).to.eql([]); + })); + + }); describe('close', function() { @@ -236,6 +264,19 @@ describe('features/search-pad', function() { })); + it('should remove marker from diagram container', inject(function(searchPad) { + + // given + searchPad.open(); + + // when + searchPad.close(); + + // then + expectOpenMarker(false); + })); + + it('should close on and restore', inject(function(eventBus, searchPad) { // given @@ -445,7 +486,6 @@ describe('features/search-pad', function() { expect(domClasses(result_nodes[0]).has(SearchPad.RESULT_SELECTED_CLASS)).to.be.true; expect(capturedEvents).to.eql([ EVENTS.opened, EVENTS.preselected ]); expect(selection.isSelected(elements.two.a)).to.be.true; - expect(domClasses(canvas.getGraphics(elements.two.a)).has('djs-search-preselected')).to.be.true; })); @@ -466,7 +506,6 @@ describe('features/search-pad', function() { ]); expect(selection.isSelected(elements.two.a)).to.be.true; - expect(domClasses(canvas.getGraphics(elements.two.a)).has('djs-search-preselected')).to.be.false; })); @@ -484,8 +523,6 @@ describe('features/search-pad', function() { // then expect(selection.isSelected(elements.one.a)).to.be.true; - - expect(domClasses(canvas.getGraphics(elements.two.a)).has('djs-search-preselected')).to.be.false; })); @@ -732,4 +769,15 @@ function expectResultsHTML(expectedResults) { ); }); }); +} + + +function expectOpenMarker(expected) { + + return getDiagramJS().invoke((canvas) => { + + const container = canvas.getContainer(); + + expect(domClasses(container).has(SEARCH_OPEN_MARKER_CLS)).to.equal(expected); + }); } \ No newline at end of file