Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(store): function for selecting element by it’s id
Browse files Browse the repository at this point in the history
  • Loading branch information
telemetry-tech-user authored and lkuechler committed Feb 19, 2018
1 parent 79bbb1a commit d2ee04a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,29 @@ export class Store {
return pageRef ? pageRef.getProject() : undefined;
}

/**
* Returns the page element for a given ID
* @return The page element.
*/
public getElementById(id: number[], startElement?: PageElement): PageElement | undefined {
if (!startElement) {
const currentPage: Page | undefined = this.getCurrentPage();
if (!currentPage) {
return;
}
startElement = currentPage.getRoot();
id.splice(0, 1);
}

const foundElement: PageElement = startElement.getChildren()[id[0]];

if (id.length === 1) {
return foundElement;
}

return this.getElementById(id.slice(1), foundElement);
}

/**
* Returns the path of the root folder of the designs (projects, pages)
* in the currently opened styleguide.
Expand Down Expand Up @@ -549,4 +572,16 @@ export class Store {
public setSelectedElement(selectedElement: PageElement | undefined): void {
this.selectedElement = selectedElement;
}

/**
* Sets the currently selected element ID in the element list.
* The properties pane shows the properties of this element,
* and keyboard commands like cut, copy, or delete operate on this element.
* May be empty if no element is selected.
* @param selectedElementId The selected element or undefined.
* @see setElementFocussed
*/
public setSelectedElementById(selectedElementId: number[]): void {
this.selectedElement = this.getElementById(selectedElementId);
}
}

0 comments on commit d2ee04a

Please sign in to comment.