From 9cc2950cf14233c15a463044ebe10e57aa2dafd6 Mon Sep 17 00:00:00 2001 From: JustOff Date: Mon, 4 Mar 2019 16:53:10 +0200 Subject: [PATCH] Fix the button does not retain its position when it's placed before a 'spring', 'spacer' or 'separator' (#3750) --- platform/firefox/vapi-background.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 37368b7a7..ec5ce3577 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -2768,8 +2768,15 @@ vAPI.toolbarButton = { } // Found our button on this toolbar - but where on it? var before = null; - for ( var i = index + 1; i < currentset.length; i++ ) { - before = toolbar.querySelector('[id="' + currentset[i] + '"]'); + for ( var i = index + 1, special; i < currentset.length; i++ ) { + if ( (special = /^(spring|spacer|separator)$/.exec(currentset[i])) !== null ) { + // Special elements have pseudo-random ids different from specified in the currentset + var specials = toolbar.querySelectorAll('toolbar' + special[1]); + var remain = currentset.slice(i-currentset.length).filter(s => s == special[1]).length; + before = toolbar.querySelector('[id="' + specials[specials.length - remain].id + '"]'); + } else { + before = toolbar.querySelector('[id="' + currentset[i] + '"]'); + } if ( before !== null ) { break; }