Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logseq Hashtag Autocomplete

A Logseq plugin (v0.10.14+) that restores the tag autocomplete dropdown when returning the cursor to an existing hashtag.

The Problem

In Logseq, the tag autocomplete menu only appears during the initial typing of the # symbol. If you move the cursor elsewhere (to another line or outside the hashtag) and then return it to the end of an existing #tag to continue typing, the text is edited as plain text—the autocomplete menu does not reappear.

What This Plugin Does

The plugin listens for keystrokes in the block editor. If the cursor is at the end of an existing hashtag and the user types a printable character:

  1. The standard character insertion is canceled (preventDefault).
  2. Step 1: The entire #tag is replaced with a single # via document.execCommand('insertText', ...). This forces Logseq's internal handle-last-input to recognize the # as the last entered character and open the dropdown.
  3. Polling Wait: The plugin waits for a short period (typically 20-40ms) until it detects that the autocomplete popup has physically appeared in the DOM.
  4. Step 2: Once the popup is detected, the plugin inserts the full tag tail (the original text plus the newly typed character) in a single execCommand call. The menu stays open, and its filter updates reactively.

This approach ensures that the undo history only gains 2 steps instead of one step per character, and the search popup correctly anchors to the hashtag.

Installation

  1. Open Logseq.
  2. Go to Settings → Advanced and enable Developer mode.
  3. In the top bar, click the plugin icon (puzzle piece) → Plugins.
  4. Click Load unpacked plugin and select this project directory.
  5. Ensure the plugin is enabled in the list.

Usage

No configuration is required. Once activated, the plugin works automatically:

  • Type #tag — autocomplete opens as usual.
  • Click elsewhere in the document.
  • Click back to the end of #tag and type any character — the autocomplete menu reappears.

Constraints

  • The cursor must be at the end of the hashtag. Inserting characters into the middle of a hashtag will trigger the menu, but trailing text will not be part of the filter (native Logseq limitation).
  • IME (Chinese, Japanese, etc.) is not supported—the plugin listens only for keydown with single-character event.key.
  • Pasting from the clipboard inside a tag does not trigger the menu.
  • Each trigger creates 2 steps in the undo history (Ctrl+Z).
  • The plugin works only in the standard block editor (textarea.normal-block). It does not target code blocks or other special editors.

Technical Details

The index.js file registers a single keydown listener on top.document during the capture phase. It uses a polling mechanism to synchronize with Logseq's asynchronous React rendering, ensuring the autocomplete state is fully initialized before restoring the tag content.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages