Skip to content

fix: plugin not working on current Logseq versions#96

Open
phillix2 wants to merge 1 commit intosawhney17:mainfrom
phillix2:fix/compatible-with-current-logseq
Open

fix: plugin not working on current Logseq versions#96
phillix2 wants to merge 1 commit intosawhney17:mainfrom
phillix2:fix/compatible-with-current-logseq

Conversation

@phillix2
Copy link
Copy Markdown

Summary

The plugin stopped working on recent Logseq versions (0.10+). Three bugs were identified and fixed:

  1. blockArray never populated (main issue) — In current Logseq, every onChanged event includes a txMeta.outlinerOp (save-block, insert-blocks, etc.). The old code expected some events WITHOUT outlinerOp to accumulate block UUIDs in blockArray, then process them when insert-blocks fired. Since ALL events now have an outlinerOp, blocks always went to the processing branch with an empty array → plugin did nothing.

    • Fix: Process blocks directly from e.blocks in the event instead of the intermediate blockArray.
  2. Regex crash on certain page names — The Chinese character regex (?<!\[)PAGE(?!\]) crashed for page names containing special characters (like UUIDs with dashes), throwing "Range out of order in character class" errors that killed processing for ALL pages.

    • Fix: Added try/catch per page so one bad regex doesn't break everything. Fixed Chinese detection to require at least one Chinese character (+ instead of {0,}).
  3. mod+p shortcut conflict — The default parseSingleBlockKeybinding (mod+p) conflicts with Logseq's built-in :editor/add-property. (Relates to shortcut does not work properly #81, Error message "Keyboard shortcut conflicts with existing shortcut" #68)

    • Fix: Changed default to alt+shift+l.

Additional improvements

Related Issues

Fixes #78 (Escaping out of a block doesn't parse for links — now listens to save-block)
Fixes #67 (Plugin takes too long to load — feedback loop prevention)
Fixes #81 (Command+P shortcut not working — changed default binding)
Fixes #68 (Keyboard shortcut conflicts)
Fixes #86, #90 (Properties and code converted to links)
Incorporates the idea from PR #92 (multiple onChanged firings)

Test plan

  • Enable auto-parse (Ctrl+Shift+L), type text containing an existing page name, press Enter → should auto-link
  • Type text and click away (instead of Enter) → should also auto-link
  • Verify properties (key:: value) are NOT auto-linked
  • Verify existing [[links]] are not double-linked
  • Verify code blocks and inline code are not auto-linked
  • Test right-click → "Parse Block for Links" on a block
  • Test with Chinese page names (if applicable)

🤖 Generated with Claude Code

Three bugs prevented the plugin from working on recent Logseq:

1. blockArray never populated — In current Logseq, every onChanged event
   includes an outlinerOp (save-block, insert-blocks). The old code expected
   some events WITHOUT outlinerOp to accumulate block UUIDs, then process
   them on insert-blocks. Since all events had an outlinerOp, blocks always
   went to the processing branch with an empty array. Fix: process blocks
   directly from e.blocks in the event.

2. Regex crash on certain page names — The Chinese character regex
   (?<!\[)PAGE(?!\]) crashed for page names containing special chars
   (like UUIDs with dashes), causing "Range out of order in character class"
   errors that killed ALL page processing. Fix: added try/catch per page,
   fixed Chinese detection to require at least one Chinese char (+ not {0,}).

3. mod+p shortcut conflict — The default parseSingleBlockKeybinding (mod+p)
   conflicts with Logseq's :editor/add-property. Changed to alt+shift+l.

Additional improvements:
- Added isProcessing guard to prevent updateBlock → onChanged feedback loop
- Null safety for e.blocks[0] access
- try/catch around all datascript queries (fail gracefully)
- Protected entire property lines (key AND values) from auto-linking
- Protected existing [[links]] before processing
- Upgraded @logseq/libs from 0.0.6 to 0.0.17

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants