Skip to content

Commit 14833cd

Browse files
committed
[#448] Minor: Add Ctrl+0 to focus first widget in model
1 parent 8df59a0 commit 14833cd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

app/assets/javascripts/beak/widgets/accessibility/keybinds.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ keybinds = [
5151
{ description: "Toggle authoring mode for the model." },
5252
{ preventDefault: true }
5353
),
54+
new Keybind(
55+
"focus:model-widgets",
56+
(ractive, event) -> ractive.fire('focus-first-widget')
57+
["#{modKey}+0"],
58+
{ description: "Focus the first widget in the model." },
59+
{ preventDefault: true }
60+
),
5461
new Keybind(
5562
"focus-tab:console",
5663
(ractive, event) -> ractive.fire('set-tab', 'console', { active: true, focus: true })

app/assets/javascripts/beak/widgets/event-traffic-control.coffee

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,18 @@ controlEventTraffic = (controller, performUpdate) ->
282282

283283
return
284284

285+
focusFirstWidget = (ractive) ->
286+
firstWidget = ractive.find('[tabindex="1"]:not(.netlogo-model)')
287+
if firstWidget?
288+
# Hack to force :focus-visible instead of
289+
# :focus, so the focus ring appears.
290+
# - Omar I (Oct 29 2025)
291+
firstWidget.scrollIntoView({ behavior: 'smooth', block: 'center' })
292+
firstWidget.contentEditable = true
293+
firstWidget.focus()
294+
firstWidget.contentEditable = false
295+
return
296+
285297
mousetrap = Mousetrap(ractive.find('.netlogo-model'))
286298
keybinds.forEach((keybindGroup) -> keybindGroup.bind(mousetrap, ractive))
287299
mousetrap.bind('?', onQMark)
@@ -326,6 +338,7 @@ controlEventTraffic = (controller, performUpdate) ->
326338
ractive.on('set-tab', (_, name, options) => setTab(name, options))
327339
ractive.on('toggle-keyboard-help', -> toggleBoolean('isKeyboardHelpVisible'))
328340
ractive.on('refresh-sorting-keys', -> refreshSortingKeys())
341+
ractive.on('focus-first-widget', -> focusFirstWidget(ractive))
329342

330343
return
331344

0 commit comments

Comments
 (0)