From 8efa7cc5b5f33b69827b44440472641ae0d954a7 Mon Sep 17 00:00:00 2001 From: Kleber Silva Date: Thu, 16 Sep 2021 01:35:54 -0300 Subject: [PATCH] scroll to selection --- TODO.todo | 4 ++-- example/game.js | 10 ++++++++++ src/editor-view/object-tree/tree-node/tree-node.ts | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/TODO.todo b/TODO.todo index 920d673..6c4a6e3 100644 --- a/TODO.todo +++ b/TODO.todo @@ -44,8 +44,8 @@ BASIC: [x] automatic expand when selecting [x] expand / collapse all with alt key [x] vertical scroll - [ ] horizontal scroll - [ ] scroll to selection + [x] horizontal scroll + [x] scroll to selection General Features: [x] editor layout diff --git a/example/game.js b/example/game.js index 8bafbb6..5ed28f0 100644 --- a/example/game.js +++ b/example/game.js @@ -107,11 +107,21 @@ function create() { child.anchor.set(0.5, 0.5); child.pivot.set(SIZE, SIZE); + for (let i = 0; i < 10; i++) { + const c = el(0, 0, SIZE, SIZE, child, 'child-a.5-p1'); + child = c; + } + // 1 0 child = el(DIST * 0, DIST * 2, SIZE, SIZE, parent, 'child-a1-p0'); child.anchor.set(1, 1); + for (let i = 0; i < 10; i++) { + const c = el(0, 0, SIZE, SIZE, child, 'child-a.5-p1'); + child = c; + } + // 1 .5 child = el(DIST * 1, DIST * 2, SIZE, SIZE, parent, 'child-a1-p.5'); child.anchor.set(1, 1); diff --git a/src/editor-view/object-tree/tree-node/tree-node.ts b/src/editor-view/object-tree/tree-node/tree-node.ts index eb065de..d881edf 100644 --- a/src/editor-view/object-tree/tree-node/tree-node.ts +++ b/src/editor-view/object-tree/tree-node/tree-node.ts @@ -54,7 +54,11 @@ export class TreeNode extends HTMLElement { private onClick() { if (this.onNodeSelect) this.onNodeSelect(this); } - public select() { this.classList.add(SELECTED_CLASS); } + public select() { + this.classList.add(SELECTED_CLASS); + this.collapseIcon.scrollIntoView(); + } + public clearSelection() { this.classList.remove(SELECTED_CLASS); } public onCollapseIconClick(e: MouseEvent) {