Skip to content

Bug fix — keyboard focus lost after custom actions (txt2tags-it.qml)#291

Merged
pbek merged 1 commit into
qownnotes:mainfrom
luginf:txt2tags-it
May 22, 2026
Merged

Bug fix — keyboard focus lost after custom actions (txt2tags-it.qml)#291
pbek merged 1 commit into
qownnotes:mainfrom
luginf:txt2tags-it

Conversation

@luginf
Copy link
Copy Markdown
Contributor

@luginf luginf commented May 22, 2026

After invoking a custom action via keyboard shortcut (e.g. "Heading 2"), the editor lost focus, forcing the user to
click with the mouse before typing again.

  • Root cause: the toolbar/menu button steals focus when the action fires.
  • First attempt: script.noteTextEditSetFocus() — does not exist, throws TypeError on v26.5.14.
  • Fix: mainWindow.focusNoteTextEdit() added at the end of customActionInvoked(). This is the only official API method for restoring editor focus.

noteToMarkdownHtmlHook optimisations (hot path, called on every keystroke):

  • _isWindows — platformIsWindows() cached in init() (avoids an external call on every render)
  • _headRe — regex /[\s\S]?</head>/ pre-compiled in init() (no more new RegExp(...) on each call + (?:.|\n)? replaced by [\s\S]*? which is significantly faster on large HTML)
  • _urlAttrRe — URL attribute regex pre-compiled in init() + lastIndex = 0 reset before each replace()
  • _cssInject — constant CSS string extracted as a property

txt2tags_autolink optimisation (inline rule, called at every position):

  • charCode fast-fail before src.slice(pos) + exec() — avoids creating a substring for every / and any non-letter character

  After invoking a custom action via keyboard shortcut (e.g. "Heading 2"), the editor lost focus, forcing the user to
   click with the mouse before typing again.

  - Root cause: the toolbar/menu button steals focus when the action fires.
  - First attempt: script.noteTextEditSetFocus() — does not exist, throws TypeError on v26.5.14.
  - Fix: mainWindow.focusNoteTextEdit() added at the end of customActionInvoked(). This is the only official API
  method for restoring editor focus.

noteToMarkdownHtmlHook optimisations (hot path, called on every keystroke):
  - _isWindows — platformIsWindows() cached in init() (avoids an external call on every render)
  - _headRe — regex /<head>[\s\S]*?<\/head>/ pre-compiled in init() (no more new RegExp(...) on each call +
  (?:.|\n)*? replaced by [\s\S]*? which is significantly faster on large HTML)
  - _urlAttrRe — URL attribute regex pre-compiled in init() + lastIndex = 0 reset before each replace()
  - _cssInject — constant CSS string extracted as a property

txt2tags_autolink optimisation (inline rule, called at every position):
  - charCode fast-fail before src.slice(pos) + exec() — avoids creating a substring for every / and any non-letter character
@pbek pbek merged commit b2eb63b into qownnotes:main May 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants