diff options
author | Florrie <towerofnix@gmail.com> | 2018-07-04 21:19:19 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-07-04 21:19:21 -0300 |
commit | 4ddc3ece7d713633347f2702c30806b4a2e18ca4 (patch) | |
tree | 4177d66568d6138c2208b5b794ee932e403f3ac6 /ui/form/FocusElement.js | |
parent | 1076bd5e65658a0e846a7892cee787ade7660bb2 (diff) |
Remove FocusElement.isFocused, add isSelected
FocusElement.isSelected behaves a little bit differently - basically it's true if the current selected element is that element, OR any of the ancestors of the current selected element is that element. It's also a getter, so you can't directly override it (assigning to el.isSelected won't work).
Diffstat (limited to 'ui/form/FocusElement.js')
-rw-r--r-- | ui/form/FocusElement.js | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/ui/form/FocusElement.js b/ui/form/FocusElement.js index 79a8afc..9061838 100644 --- a/ui/form/FocusElement.js +++ b/ui/form/FocusElement.js @@ -9,20 +9,14 @@ module.exports = class FocusElement extends DisplayElement { this.cursorVisible = false this.cursorX = 0 this.cursorY = 0 - - this.isFocused = false } focused() { // Should be overridden in subclasses. - - this.isFocused = true } unfocused() { // Should be overridden in subclasses. - - this.isFocused = false } get selectable() { @@ -41,6 +35,11 @@ module.exports = class FocusElement extends DisplayElement { // http://stackoverflow.com/a/11432632/4633828 } + get isSelected() { + const selected = this.root.selected + return selected && [selected, ...selected.directAncestors].includes(this) + } + get absCursorX() { return this.absX + this.cursorX } get absCursorY() { return this.absY + this.cursorY } } |