From f23e47b9a2ac96e2c75e6c847d84a8014944e502 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 10 Nov 2020 17:50:01 -0800 Subject: [PATCH] Extract getParentFlowToElement --- src/vs/base/browser/dom.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index f16be74d631..cdeb92b8da4 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -671,6 +671,14 @@ export function setParentFlowTo(fromChildElement: HTMLElement, toParentElement: fromChildElement.dataset[parentFlowToDataKey] = toParentElement.id; } +function getParentFlowToElement(node: HTMLElement): HTMLElement | null { + const flowToParentId = node.dataset[parentFlowToDataKey]; + if (typeof flowToParentId === 'string') { + return document.getElementById(flowToParentId); + } + return null; +} + /** * Check if `testAncestor` is an ancessor of `testChild`, observing the explicit * parents set by `setParentFlowTo`. @@ -683,13 +691,10 @@ export function isAncestorUsingFlowTo(testChild: Node, testAncestor: Node): bool } if (node instanceof HTMLElement) { - const flowToParentId = node.dataset[parentFlowToDataKey]; - if (typeof flowToParentId === 'string') { - const flowToParentElement = document.getElementById(flowToParentId); - if (flowToParentElement) { - node = flowToParentElement; - continue; - } + const flowToParentElement = getParentFlowToElement(node); + if (flowToParentElement) { + node = flowToParentElement; + continue; } } node = node.parentNode; -- GitLab