SelectionChangedMenulist.sys.mjs (904B)
1 /* - This Source Code Form is subject to the terms of the Mozilla Public 2 - License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 - You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 export class SelectionChangedMenulist { 6 // A menulist wrapper that will open the popup when navigating with the 7 // keyboard on Windows and trigger the provided handler when the popup 8 // is hiding. This matches the behaviour of MacOS and Linux more closely. 9 10 constructor(menulist, onCommand) { 11 let popup = menulist.menupopup; 12 let lastEvent; 13 14 menulist.addEventListener("command", event => { 15 lastEvent = event; 16 if (popup.state != "open" && popup.state != "showing") { 17 popup.openPopup(); 18 } 19 }); 20 21 popup.addEventListener("popuphiding", () => { 22 if (lastEvent) { 23 onCommand(lastEvent); 24 lastEvent = null; 25 } 26 }); 27 } 28 }