1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-25 01:05:15 +03:00

Fix violation in motor slider events (#4514)

* Fix violation in motor slider events

* Fixes per review coderabbit
This commit is contained in:
Mark Haslinghuis 2025-06-13 23:06:34 +02:00 committed by GitHub
parent dafacbd8e4
commit 1457bccb76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -705,7 +705,12 @@ motors.initialize = async function (callback) {
const escProtocolElement = $("select.escprotocol");
escProtocols.forEach((protocol, index) => {
const isDisabled = protocol !== "DISABLED" && FC.CONFIG.buildOptions.length && !FC.CONFIG.buildOptions.some(option => protocol.includes(option.substring(4))) ? "disabled" : "";
const isDisabled =
protocol !== "DISABLED" &&
FC.CONFIG.buildOptions.length &&
!FC.CONFIG.buildOptions.some((option) => protocol.includes(option.substring(4)))
? 'disabled="disabled"'
: "";
const option = `<option value="${index + 1}" ${isDisabled}>${protocol}</option>`;
escProtocolElement.append(option);
});
@ -1003,20 +1008,34 @@ motors.initialize = async function (callback) {
}
});
$("div.sliders input:not(.master)").on("input wheel", function (e) {
self.scrollSlider($(this), e);
});
$("div.sliders input.master").on("input", function () {
const val = $(this).val();
function handleWheelEvent(slider, e) {
self.scrollSlider(slider, e);
}
function handleInputEvent(slider) {
const val = slider.val();
$("div.sliders input:not(:disabled, :last)").val(val);
$("div.values li:not(:last)").slice(0, self.numberOfValidOutputs).text(val);
$("div.sliders input:not(:last):first").trigger("input");
});
const valuesList = $("div.values li:not(:last)");
valuesList.slice(0, self.numberOfValidOutputs).text(val);
$("div.sliders input:not(:disabled):not(:last)").first().trigger("input");
}
$("div.sliders input.master").on("input wheel", function (e) {
self.scrollSlider($(this), e);
$("div.sliders input").each(function () {
const slider = $(this);
this.addEventListener(
"wheel",
function (e) {
handleWheelEvent($(this), e);
},
{ passive: false },
);
if (slider.hasClass("master")) {
slider.on("input", function () {
handleInputEvent($(this));
});
}
});
// check if motors are already spinning
@ -1362,14 +1381,18 @@ motors.scrollSlider = function (slider, e) {
return;
}
if (!(e.originalEvent?.deltaY && e.originalEvent?.altKey)) {
// Handle both jQuery wrapped events and native events
const orig = e.originalEvent || e;
const { deltaY, altKey } = orig;
if (!(deltaY && altKey)) {
return;
}
e.preventDefault();
const step = 25;
const delta = e.originalEvent.deltaY > 0 ? -step : step;
const delta = deltaY > 0 ? -step : step;
const val = parseInt(slider.val()) + delta;
const roundedVal = Math.round(val / step) * step;
slider.val(roundedVal);