I’m updating my addon for 2.1.50, but it seems now when i click my custom added editor buttons the editor field text is deselected, preventing the editing of the selected text by the function associated with button press.
The added editor buttons were made by injecting javascript that basically just clones existing buttons.
can’t use python hook for one button because its a dropdown button
yeah, i noticed the default buttons had an e.preventDefault() on mousedown, but that didn’t seem to fix it. fiddling around with it some more, it seems to work on “normal” buttons but not buttons that have a dropdown when pressed. (before i only tried it on the dropdown button)
perhaps the appearance of the dropdown div itself is what causes the loss of focus?
minimum reproduction (type in web inspector console of editor screen):
const dropdownBtn = document.querySelector("#blockFormatting > div > div").lastElementChild;
const newBtn = dropdownBtn.cloneNode(true);
const newBtnButton = newBtn.querySelector("div > div > button");
newBtnButton.disabled = false;
newBtnButton.addEventListener("mousedown", e => e.preventDefault());
dropdownBtn.parentNode.appendChild(newBtn);