Controller: subtitle line actions, Button Style, keyboard-only mode pause, Alt+C fixes (#316)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
YashaNoosandClaude Opus 5.5 authored and GitHub committed 2026-11-02 21:41:46 -08:00
1 parent 6d0f37ac21
commit b99409bbcd
60 files changed
+1900 -219

No files matched your search

+236 -41
View File
@@ -2,7 +2,11 @@ import assert from 'node:assert/strict';
import test from 'node:test';
import { createRendererState } from '../state.js';
import { createControllerSelectModal } from './controller-select.js';
import {
createControllerSelectModal,
findMostRecentlyUsedIndex,
shortControllerName,
} from './controller-select.js';
import { getDefaultControllerReviewBindings } from '../../shared/controller-review';
import { getDefaultControllerFieldGroupingBindings } from '../../shared/controller-field-grouping';
@@ -159,6 +163,10 @@ function buildContext() {
holdSecondarySub: { kind: 'none' },
previousEntry: { kind: 'none' },
nextEntry: { kind: 'none' },
previousSubtitle: { kind: 'none' },
nextSubtitle: { kind: 'none' },
replaySubtitle: { kind: 'none' },
playNextSubtitle: { kind: 'none' },
leftStickHorizontal: { kind: 'axis', axisIndex: 0, dpadFallback: 'horizontal' },
leftStickVertical: { kind: 'axis', axisIndex: 1, dpadFallback: 'vertical' },
rightStickHorizontal: { kind: 'axis', axisIndex: 3, dpadFallback: 'none' },
@@ -179,6 +187,7 @@ function buildContext() {
controllerSelectModal: { classList: createClassList(['hidden']), setAttribute: () => {} },
controllerSelectClose: createFakeElement(),
controllerSelectPicker: createFakeElement(),
controllerSelectFaceButtonStyle: createFakeElement(),
controllerSelectSummary: createFakeElement(),
controllerConfigList: createFakeElement(),
controllerSelectStatus: { textContent: '', classList: createClassList() },
@@ -328,6 +337,7 @@ test('controller select modal reset control stores the default binding in the se
state.controllerConfig.profiles = {
'pad-1': {
label: 'pad-1',
faceButtonLabels: state.controllerConfig.faceButtonLabels,
buttonIndices: state.controllerConfig.buttonIndices,
bindings: {
...state.controllerConfig.bindings,
@@ -429,7 +439,7 @@ test('controller select modal binding badge starts learn mode and persists bindi
}
});
test('controller select modal learn mode falls back to global bindings without a controller', async () => {
test('controller select modal locks editing until this window sees a controller', async () => {
const domHandle = installFakeDom();
const saved: unknown[] = [];
@@ -448,44 +458,45 @@ test('controller select modal learn mode falls back to global bindings without a
try {
const { state, dom } = buildContext();
// A freshly opened window sees no pad until a button is pressed in it.
state.connectedGamepads = [];
// No controller visible and none saved: edits go to the global bindings.
state.controllerConfig!.preferredGamepadId = '';
state.activeGamepadId = null;
const modal = createControllerSelectModal({ state, dom } as never, {
modalStateReader: { isAnyModalOpen: () => false },
syncSettingsModalSubtitleSuppression: () => {},
notifyControllerDisabled: () => {},
});
modal.wireDomEvents();
modal.openControllerSelectModal();
const firstRow = dom.controllerConfigList.children[1];
firstRow.dispatch('click');
const editPanel = dom.controllerConfigList.children[2];
const learnButton = editPanel.children[0].children[1].children[0];
learnButton.dispatch('click');
const press = 'Press any button on your controller to edit its bindings.';
assert.equal(dom.controllerSelectStatus.textContent, press);
assert.equal(dom.controllerConfigList.classList.contains('controller-config-locked'), true);
assert.equal(dom.controllerSelectFaceButtonStyle.disabled, true);
state.controllerRawButtons = Array.from({ length: 12 }, () => ({
value: 0,
pressed: false,
touched: false,
// Learn and Clear do nothing yet.
const row = findReviewRow(dom.controllerConfigList, 'Toggle Lookup');
row.children[1].children[0].dispatch('click');
state.controllerRawButtons = Array.from({ length: 12 }, (_, index) => ({
value: index === 11 ? 1 : 0,
pressed: index === 11,
touched: index === 11,
}));
state.controllerRawButtons[11] = { value: 1, pressed: true, touched: true };
modal.updateDevices();
await Promise.resolve();
assert.deepEqual(saved, []);
assert.equal(dom.controllerSelectStatus.textContent, press, 'kept across frames');
assert.deepEqual(saved.at(-1), {
bindings: {
toggleLookup: { kind: 'button', buttonIndex: 11 },
},
});
assert.deepEqual(state.controllerConfig?.bindings.toggleLookup, {
kind: 'button',
buttonIndex: 11,
});
// The press makes the pad visible: editing unlocks for it.
state.connectedGamepads = [{ id: 'pad-1', index: 0, mapping: 'standard', connected: true }];
state.activeGamepadId = 'pad-1';
modal.updateDevices();
assert.equal(dom.controllerConfigList.classList.contains('controller-config-locked'), false);
assert.equal(dom.controllerSelectFaceButtonStyle.disabled, false);
assert.equal(
dom.controllerSelectStatus.textContent,
'Choose a controller or click Learn to remap an action.',
);
} finally {
domHandle.restore();
}
@@ -799,7 +810,7 @@ test('controller select modal learns a duplicate card button and saves it to the
}
});
test('controller select modal shows and edits the saved controller before this window sees it', async () => {
test('controller select modal previews the saved controller, then edits it once seen', async () => {
const domHandle = installFakeDom();
const saved: unknown[] = [];
@@ -825,6 +836,7 @@ test('controller select modal shows and edits the saved controller before this w
config.profiles = {
'pad-1': {
label: 'pad-1',
faceButtonLabels: config.faceButtonLabels,
buttonIndices: config.buttonIndices,
bindings: config.bindings,
fieldGroupingBindings: config.fieldGroupingBindings,
@@ -846,18 +858,31 @@ test('controller select modal shows and edits the saved controller before this w
modal.wireDomEvents();
modal.openControllerSelectModal();
// The preview is the saved controller's layout, labelled as such.
assert.equal(dom.controllerSelectSummary.textContent, 'Showing pad-1 (saved).');
findByClass(dom.controllerConfigList, 'controller-config-group-toggle').dispatch('click');
const row = findReviewRow(dom.controllerConfigList, 'Start \u22120.1s');
assert.equal(row.children[1].children[0].textContent, 'L2 + D-pad \u25b6');
const waiting = 'Press any button on your controller so this window can see it.';
assert.equal(dom.controllerSelectStatus.textContent, waiting);
const startBack = () => findReviewRow(dom.controllerConfigList, 'Start \u22120.1s');
assert.equal(startBack().children[1].children[0].textContent, 'L2 + D-pad \u25b6');
const press = 'Press any button on your controller to edit its bindings.';
assert.equal(dom.controllerSelectStatus.textContent, press);
// Controller polling keeps publishing snapshots while no pad is visible.
modal.updateDevices();
modal.updateDevices();
assert.equal(dom.controllerSelectStatus.textContent, waiting, 'the prompt stays');
assert.equal(dom.controllerSelectStatus.textContent, press, 'the prompt stays');
// Reset goes to the saved controller's profile, not the global layout.
row.children[1].children[1].dispatch('click');
// Reset is locked until the window sees the pad.
startBack().children[1].children[1].dispatch('click');
await Promise.resolve();
assert.deepEqual(saved, []);
state.connectedGamepads = [{ id: 'pad-1', index: 0, mapping: 'standard', connected: true }];
state.activeGamepadId = 'pad-1';
modal.updateDevices();
assert.equal(
dom.controllerSelectStatus.textContent,
'Choose a controller or click Learn to remap an action.',
);
startBack().children[1].children[1].dispatch('click');
await Promise.resolve();
assert.deepEqual(saved.at(-1), {
profiles: {
@@ -873,19 +898,19 @@ test('controller select modal shows and edits the saved controller before this w
},
});
await new Promise((resolve) => setTimeout(resolve, 0));
const afterReset = dom.controllerSelectStatus.textContent;
assert.equal(afterReset, 'Start \u22120.1s reset.');
assert.equal(dom.controllerSelectStatus.textContent, 'Start \u22120.1s reset.');
modal.updateDevices();
assert.equal(dom.controllerSelectStatus.textContent, afterReset, 'the reset message stays');
assert.equal(
dom.controllerSelectStatus.textContent,
'Start \u22120.1s reset.',
'the reset message stays',
);
// The pad appears, then disappears again.
state.connectedGamepads = [{ id: 'pad-1', index: 0, mapping: 'standard', connected: true }];
state.activeGamepadId = 'pad-1';
modal.updateDevices();
// The pad disappears, then comes back.
state.connectedGamepads = [];
state.activeGamepadId = null;
modal.updateDevices();
assert.equal(dom.controllerSelectStatus.textContent, waiting);
assert.equal(dom.controllerSelectStatus.textContent, press);
state.connectedGamepads = [{ id: 'pad-1', index: 0, mapping: 'standard', connected: true }];
state.activeGamepadId = 'pad-1';
modal.updateDevices();
@@ -897,3 +922,173 @@ test('controller select modal shows and edits the saved controller before this w
domHandle.restore();
}
});
test('controller select modal previews the controller the overlay reports in use', async () => {
const domHandle = installFakeDom();
Object.defineProperty(globalThis, 'window', {
configurable: true,
value: {
focus: () => {},
electronAPI: {
saveControllerConfig: async () => {},
notifyOverlayModalClosed: () => {},
getActiveControllerId: async () => 'DualSense Wireless Controller (STANDARD GAMEPAD)',
},
},
});
try {
const { state, dom } = buildContext();
state.connectedGamepads = [];
state.activeGamepadId = null;
const config = state.controllerConfig!;
// The saved controller is pad-1, but the overlay is reading the DualSense.
config.profiles = {
'DualSense Wireless Controller (STANDARD GAMEPAD)': {
label: 'DualSense',
faceButtonLabels: 'playstation',
buttonIndices: config.buttonIndices,
bindings: { ...config.bindings, mineCard: { kind: 'button', buttonIndex: 3 } },
reviewBindings: config.reviewBindings,
fieldGroupingBindings: config.fieldGroupingBindings,
},
};
const modal = createControllerSelectModal({ state, dom } as never, {
modalStateReader: { isAnyModalOpen: () => false },
syncSettingsModalSubtitleSuppression: () => {},
notifyControllerDisabled: () => {},
});
modal.wireDomEvents();
modal.openControllerSelectModal();
await new Promise((resolve) => setTimeout(resolve, 0));
assert.equal(
dom.controllerSelectSummary.textContent,
'Showing DualSense Wireless Controller (in use).',
);
assert.equal(
findReviewRow(dom.controllerConfigList, 'Mine Card').children[1].children[0].textContent,
'\u25b3',
);
assert.equal(dom.controllerSelectFaceButtonStyle.value, 'playstation');
} finally {
domHandle.restore();
}
});
test('controller select modal selects the controller you pressed when several appear', () => {
const domHandle = installFakeDom();
Object.defineProperty(globalThis, 'window', {
configurable: true,
value: {
focus: () => {},
electronAPI: { saveControllerConfig: async () => {}, notifyOverlayModalClosed: () => {} },
},
});
try {
const { state, dom } = buildContext();
state.connectedGamepads = [];
state.activeGamepadId = null;
const modal = createControllerSelectModal({ state, dom } as never, {
modalStateReader: { isAnyModalOpen: () => false },
syncSettingsModalSubtitleSuppression: () => {},
notifyControllerDisabled: () => {},
});
modal.wireDomEvents();
modal.openControllerSelectModal();
// One press reveals every pad; pad-2 has the newest input, pad-1 is the saved one.
state.connectedGamepads = [
{ id: 'pad-1', index: 0, mapping: 'standard', connected: true, timestamp: 100 },
{ id: 'pad-2', index: 1, mapping: 'standard', connected: true, timestamp: 500 },
];
state.activeGamepadId = 'pad-1';
modal.updateDevices();
assert.equal(state.controllerDeviceSelectedIndex, 1);
assert.equal(state.controllerSelectGamepadId, 'pad-2', 'this window then reads pad-2');
modal.closeControllerSelectModal();
assert.equal(state.controllerSelectGamepadId, null);
} finally {
domHandle.restore();
}
});
test('controller select modal shows and saves the button style per controller', async () => {
const domHandle = installFakeDom();
const saved: unknown[] = [];
Object.defineProperty(globalThis, 'window', {
configurable: true,
value: {
focus: () => {},
electronAPI: {
saveControllerConfig: async (update: unknown) => {
saved.push(update);
},
notifyOverlayModalClosed: () => {},
},
},
});
try {
const { state, dom } = buildContext();
const modal = createControllerSelectModal({ state, dom } as never, {
modalStateReader: { isAnyModalOpen: () => false },
syncSettingsModalSubtitleSuppression: () => {},
notifyControllerDisabled: () => {},
});
modal.wireDomEvents();
modal.openControllerSelectModal();
const stylePicker = dom.controllerSelectFaceButtonStyle;
assert.deepEqual(
stylePicker.children.map((option: any) => option.value),
['xbox', 'nintendo', 'playstation'],
);
assert.equal(stylePicker.value, 'xbox');
stylePicker.value = 'playstation';
stylePicker.dispatch('change');
await new Promise((resolve) => setTimeout(resolve, 0));
assert.deepEqual(saved.at(-1), {
profiles: { 'pad-1': { faceButtonLabels: 'playstation' } },
});
assert.equal(state.controllerConfig?.profiles['pad-1']?.faceButtonLabels, 'playstation');
assert.equal(state.controllerConfig?.faceButtonLabels, 'xbox', 'other controllers keep theirs');
assert.equal(dom.controllerSelectStatus.textContent, 'Button style: PlayStation.');
// Toggle Lookup is on the bottom face button.
assert.equal(
findReviewRow(dom.controllerConfigList, 'Toggle Lookup').children[1].children[0].textContent,
'╳',
);
// The other controller still uses the default style.
dom.controllerSelectPicker.value = 'pad-2:1';
dom.controllerSelectPicker.dispatch('change');
assert.equal(stylePicker.value, 'xbox');
} finally {
domHandle.restore();
}
});
test('shortControllerName drops the driver details in brackets', () => {
assert.equal(
shortControllerName('Xbox Wireless Controller (STANDARD GAMEPAD Vendor: 045e Product: 0b13)'),
'Xbox Wireless Controller',
);
assert.equal(shortControllerName('pad-1'), 'pad-1');
assert.equal(shortControllerName('(only details)'), '(only details)');
});
test('findMostRecentlyUsedIndex picks the newest input and ignores missing timestamps', () => {
assert.equal(findMostRecentlyUsedIndex([{ timestamp: 100 }, { timestamp: 500 }, {}]), 1);
assert.equal(findMostRecentlyUsedIndex([{ timestamp: 900 }, { timestamp: Number.NaN }]), 0);
assert.equal(findMostRecentlyUsedIndex([{}, { timestamp: 0 }]), -1);
assert.equal(findMostRecentlyUsedIndex([]), -1);
});