Making panel focus on openLintPanel optional

Hi, I was hoping to find an easy way to make the automatic panel focus on openLintPanel optional but from the code it doesn’t look like it’s possible.

As the code is typed in the editor and errors are shown the user has to continuously return focus to the editor to continue typing. I would like any errors to be shown but the user be able to continue typing the code.

Could an option be added to the lintConfig e.g. ‘focusLintPanelOnOpen’ and then openLintPanel command modified to:

export const openLintPanel: Command = (view: EditorView) => {
  let field = view.state.field(lintState, false)
  if (!field || !field.panel)
    view.dispatch({effects: maybeEnableLint(view.state, [togglePanel.of(true)])})
  let panel = getPanel(view, LintPanel.open)
  const {focusLintPanelOnOpen} = view.state.facet(lintConfig)
  if (panel && focusLintPanelOnOpen) (panel.dom.querySelector(".cm-panel-lint ul") as HTMLElement).focus()
  return true
}

I don’t think the panel every refocuses itself unless you call openLintPanel again. Why is the editor losing focus for you in this scenario?

Being able to interact with the lint panel with the keyboard is an important accessibility feature for keyboard-only users, so I’m hesitant to make it something that can be disabled.

I only want the panel to show when there are errors, so I was opening it and closing it. Is there another way to handle this situation?

Would an option that makes the panel automatically open when the number of diagnostics goes from zero to >0, and close when it goes back to zero, work for you? That way you’d also avoid the extra superfluous state updates that calling closeLintPanel/openLintPanel after the changes cause.

That could definitely work. As a workaround I was changing the display property on the element with class “cm-panels cm-panels-bottom” based on the number of diagnostics but what you proposed would be definitely cleaner.

This patch adds such an option. Does it look like it addresses your use case?

Definitely. Thanks for working on this so quickly.