Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Jun 3, 2024
1 parent d556c00 commit 89e5557
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/features/search-pad/SearchPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export default function SearchPad(canvas, eventBus, selection, translate) {
this._open = false;
this._results = [];
this._eventMaps = [];

this._cachedRootElement = null;
this._cachedSelection = null;
this._cachedViewbox = null;

Expand Down Expand Up @@ -317,6 +319,7 @@ SearchPad.prototype.open = function() {
return;
}

this._cachedRootElement = this._canvas.getRootElement();
this._cachedSelection = this._selection.get();
this._cachedViewbox = this._canvas.viewbox();

Expand All @@ -341,6 +344,10 @@ SearchPad.prototype.close = function() {
return;
}

if (this._cachedRootElement) {
this._canvas.setRootElement(this._cachedRootElement);
}

if (this._cachedSelection) {
this._selection.select(this._cachedSelection);
}
Expand Down
48 changes: 45 additions & 3 deletions test/spec/features/search-pad/SearchPadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,29 @@ describe('features/searchPad', function() {

var capturedEvents;
var searchProvider;
var rootElements;
var elements;

var input_node;

beforeEach(inject(function(searchPad, eventBus, canvas) {

canvas.setRootElement({ id: 'root' });
rootElements = {
rootA: { id: 'root-a' },
rootB: { id: 'root-b', }
};

canvas.setRootElement(rootElements.rootA);

canvas.addRootElement(rootElements.rootB);

elements = {
one: {
a: canvas.addShape({ id: 'one-a', x: 0, y: 0, width: 100, height: 100 })
},
two: {
a: canvas.addShape({ id: 'two-a', x: 200, y: 0, width: 100, height: 100 }),
b: canvas.addShape({ id: 'two-b', x: 400, y: 0, width: 100, height: 100 })
b: canvas.addShape({ id: 'two-b', x: 400, y: 0, width: 100, height: 100 }, rootElements.rootB)
}
};

Expand Down Expand Up @@ -87,7 +95,22 @@ describe('features/searchPad', function() {
{ normal: '-a' }
],
element: elements.two.a
},{
}, {
primaryTokens: [
{ matched: 'Two' },
{ normal: ' B' }
],
secondaryTokens: [
{ normal: 'Shape_' },
{ matched: 'two' },
{ normal: '-b' }
],
element: elements.two.b
} ];
}

if (pattern === 'two-b') {
return [ {
primaryTokens: [
{ matched: 'Two' },
{ normal: ' B' }
Expand Down Expand Up @@ -360,6 +383,25 @@ describe('features/searchPad', function() {
}));


it('should reset root element on escape without enter', inject(function(canvas, selection) {

// given
selection.select(elements.one.a);

expect(canvas.getRootElement()).to.equal(rootElements.rootA);

typeText(input_node, 'two-b');

expect(canvas.getRootElement()).to.equal(rootElements.rootB);

// when
triggerKeyEvent(input_node, 'keyup', 'Escape');

// then
expect(canvas.getRootElement()).to.equal(rootElements.rootA);
}));


it('select should apply selection on an element', inject(function(selection) {

// given
Expand Down

0 comments on commit 89e5557

Please sign in to comment.