tiptap-editor
Tiptap Editor API Patterns
Overview
This skill documents proper Tiptap API usage patterns for vmark development. It helps distinguish when to use Tiptap's high-level API vs direct ProseMirror access.
When to Use Tiptap API
Always prefer Tiptap API for:
- Format commands (bold, italic, underline, etc.)
- Block type changes (heading, paragraph, code block)
- List operations (bullet, ordered, toggle, indent/outdent)
- Table operations via Tiptap table extension
- Content insertion and replacement
- Editor state queries (
isActive,getAttributes)
Tiptap patterns to use:
// Direct commands
editor.commands.toggleBold()
editor.commands.setHeading({ level: 2 })
editor.commands.setContent(doc, { emitUpdate: false })
// Chained commands (for multiple operations)
editor.chain().focus().setHeading({ level: 2 }).run()
editor.chain().focus().toggleMark("underline").run()
// State queries
editor.isActive("blockquote")
editor.isActive("heading", { level: 2 })
editor.getAttributes("link")
When Direct ProseMirror is Appropriate
Use ProseMirror directly for:
- Markdown conversion layer (
proseMirrorToMdast.ts,mdastToProseMirror.ts) - Multi-cursor/selection subclassing (
MultiSelection.ts) - Custom node views
- Low-level transaction manipulation
- Schema-level operations
Known Issues in vmark
1. cursorHandlers.ts Block Boundary Issue
src/hooks/mcpBridge/cursorHandlers.ts uses doc.textContent which flattens the document and loses block boundaries. The correct approach is to use $pos helpers:
// WRONG - loses block structure
const text = doc.textContent;
// RIGHT - respects block boundaries
const $pos = doc.resolve(from);
const currentNode = $pos.parent;
const blockStart = $pos.before($pos.depth);
const blockEnd = $pos.after($pos.depth);
2. Cursor Sync Drift After WYSIWYG Edits
sourceLine attributes are only set on initial parse. After WYSIWYG edits that add/remove blocks, line numbers no longer match the source. This is a known limitation.
3. HtmlNodeView.ts Store Issue
src/plugins/markdownArtifacts/HtmlNodeView.ts writes cursor info to wrong store.
References
references/patterns.md- Detailed API patterns and $pos usagereferences/examples.md- Real code examples from vmark codebase
Workflow
- Identify operation type (format, block, selection, traversal)
- Check if Tiptap has a built-in command for it
- Use
editor.commands.xxx()for single operations - Use
editor.chain().focus().xxx().run()when focus is needed or chaining - For node traversal, use
doc.resolve(pos)to get$poshelpers - For state queries, use
editor.isActive()oreditor.getAttributes()
More from xiaolai/vmark
ai-coding-agents
Comprehensive guide for using Codex CLI (OpenAI) and Claude Code CLI (Anthropic) - AI-powered coding agents. Use when orchestrating CLI commands, automating tasks, configuring agents, or troubleshooting issues.
138tiptap-dev
Expert guidance for building rich text editors with Tiptap - a headless, framework-agnostic editor built on ProseMirror. Use when creating custom nodes, marks, or extensions for Tiptap, implementing input rules or paste rules, working with the Tiptap commands API, building React integrations with useEditor, extending existing extensions, or creating custom node views.
71tauri-app-dev
Expert guidance for building cross-platform desktop applications with Tauri 2.0 and Rust. Use when developing Tauri apps including commands and IPC, file system operations, window management, state management, system tray, menus, plugin development, security configuration (capabilities/permissions), bundling/distribution, and auto-updates. Covers patterns for editor applications requiring file dialogs, native menus, and frontend-backend communication.
67tauri-mcp-testing
E2E testing expert for Tauri applications using Tauri MCP server. Use when testing running Tauri apps - session management, webview interaction, IPC verification, screenshot capture, and debugging. ALWAYS use tauri_* tools, NEVER Chrome DevTools MCP for Tauri apps.
65rust-tauri-backend
Implement or modify VMark's Rust/Tauri backend. Use when adding Tauri commands, menu items, filesystem integration, or platform behaviors in src-tauri.
61plan-audit
Audit an implementation against a plan (dev-docs/plans/*). Use when a user asks to check for gaps, logic errors, or missing tests relative to a plan or Work Items.
60