Skip to content

Latest commit

 

History

History
70 lines (55 loc) · 2.38 KB

File metadata and controls

70 lines (55 loc) · 2.38 KB

Tag Autocomplete Implementation

Overview

I've successfully implemented a hashtag autocomplete feature for your Tiptap editor using the @tiptap/suggestion extension. Here's what was created:

Components Created

1. TagSuggestion.tsx

  • Main suggestion extension that handles the hashtag trigger (#)
  • Provides autocomplete dropdown with existing tags
  • Allows creation of new tags by typing and pressing Enter
  • Integrates with the notes store to persist tags

2. TagExtension.tsx

  • Custom Tiptap extension for rendering tags
  • Makes tags clickable (currently set to navigate to /tags/{tagname})
  • Provides proper styling and hover effects

3. useTags.ts Hook

  • Reusable hook for tag management
  • Handles tag creation, addition to notes, and retrieval
  • Integrates with the existing notes store

4. Backend Integration

  • Added createTag API method in api.ts
  • Added create_tag Tauri command in Rust backend
  • Properly exposed the command in the invoke handler

5. Styling

  • Added tag styles to index.css
  • Tags appear as rounded pills with primary color
  • Hover effects and smooth transitions
  • Dropdown styling for the autocomplete menu

Usage

  1. Type # in the editor - This triggers the autocomplete dropdown
  2. Type to search - The dropdown filters existing tags as you type
  3. Select a tag - Use arrow keys and Enter, or click to select
  4. Create new tags - If your text doesn't match any existing tag, press Enter to create it
  5. Click tags - Tags are clickable and will navigate to tag search (you can customize this behavior)

Features

  • Real-time tag filtering
  • Create tags on the fly
  • Keyboard navigation (Arrow keys + Enter/Tab)
  • Mouse support
  • Escape key to dismiss
  • Automatic tag persistence to database
  • Visual feedback with hover states
  • Responsive positioning (dropdown adjusts to viewport boundaries)

Customization Options

You can customize:

  • Tag click behavior (currently navigates to /tags/{tagname})
  • Tag appearance via CSS
  • Number of suggestions shown (currently 8)
  • Tag creation logic
  • Integration with your existing tag management system

Next Steps

To fully integrate this feature, you may want to:

  1. Implement the /tags/{tagname} route for tag-based search
  2. Add tag management UI (edit/delete tags)
  3. Display tag counts in the autocomplete
  4. Add tag colors support
  5. Implement tag-based filtering in your notes view