moyf_easy-copy/src/type.ts
Andre Light 4ac623b1bd feat: opt-in toggle, editor-paste cooperation, and orphaned-setting fix
Addresses #35 maintainer feedback: gate paste-time resolution behind a
default-off toggle with 5-min TTL on lastCopyMeta. Switch from DOM
paste (capture phase) to editor-paste workspace event with documented
defaultPrevented yield protocol; register only when active.

Also fixes a pre-existing bug where simplifiedHeadingToNoteLink was
never read — the simplification fired unconditionally when filename
matched heading.

Designed, carefully reviewed, and edited by @lightmotive in collaboration with Claude Code.
2026-04-27 20:46:42 -06:00

100 lines
No EOL
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export enum LinkFormat {
OBSIDIAN = 'obsidian',
MDLINK = 'markdown-link',
WIKILINK = 'wiki-link'
}
export enum BlockIdInsertPosition {
END_OF_BLOCK = 'end-of-block', // 当前块的末尾
NEXT_LINE = 'next-line', // 当前块的下方一行
// NEXT_LINE_WITH_GAP = 'next-line-with-gap' // 当前块的下方两行(中间隔一个空行)
}
export enum ContextType {
NULL = 'null',
HEADING = 'heading',
INLINECODE = 'inline-code',
BOLD = 'bold',
ITALIC = 'italic',
HIGHLIGHT = 'highlight',
STRIKETHROUGH = 'strikethrough',
BLOCKID = 'block-id',
INLINELATEX = 'inline-latex',
LINKTITLE = 'link-title',
LINEURL = 'line-url',
WIKILINK = 'wiki-link', // 光标在 [[双链]] 内
CALLOUT = 'callout', // 光标在 callout 区块内
}
export interface ContextData {
type: ContextType;
curLine: string;
match: string | null;
range: [number, number] | null;
}
export interface EasyCopySettings {
useFrontmatterAsDisplay: boolean; // 是否使用 frontmatter 属性作为显示文本
frontmatterKey: string; // frontmatter 属性名
addToMenu: boolean;
addExtraCommands: boolean;
showNotice: boolean;
useHeadingAsDisplayText: boolean;
headingLinkSeparator: string; // 文件名和标题间的连接符
simplifiedHeadingToNoteLink: boolean; // 是否简化标题到笔记链接
strictHeadingMatch: boolean; // 标题与文件名简化匹配时是否使用严格匹配
linkFormat: LinkFormat;
resolveLinkPathOnPaste: boolean; // 当 linkFormat 为 OBSIDIAN 时,粘贴时根据目标文件重新解析链接路径
customizeTargets: boolean;
enableInlineCode: boolean;
enableBold: boolean;
enableHighlight: boolean;
enableItalic: boolean;
enableStrikethrough: boolean;
enableInlineLatex: boolean;
enableLink: boolean;
enableWikiLink: boolean; // 是否启用 Wiki 链接复制
keepWikiBrackets: boolean; // 复制 wiki-link 时保留 [[ ]]
autoEmbedBlockLink: boolean; // 复制块链接时自动添加 !(嵌入块)
enableCalloutCopy: boolean; // 是否启用复制 Callout 内文本
calloutCopyPriority: boolean; // Callout 与块ID冲突时优先复制 Callout
autoAddBlockId: boolean; // 是否自动添加 Block ID
allowManualBlockId: boolean; // 是否允许手动输入 Block ID
blockIdInsertPosition: BlockIdInsertPosition; // 块ID的插入位置
autoBlockDisplayText: boolean; // 自动为 Block 添加显示文本
blockDisplayWordLimit: number; // Block 显示文本英文单词限制(按空格分隔)
blockDisplayCharLimit: number; // Block 显示文本字符限制(非英文语言)
}
export const DEFAULT_SETTINGS: EasyCopySettings = {
useFrontmatterAsDisplay: false,
frontmatterKey: 'title',
addToMenu: true,
addExtraCommands: true,
showNotice: true,
useHeadingAsDisplayText: true,
headingLinkSeparator: '#',
simplifiedHeadingToNoteLink: true,
strictHeadingMatch: false,
linkFormat: LinkFormat.OBSIDIAN,
resolveLinkPathOnPaste: false,
customizeTargets: false,
enableInlineCode: true,
enableBold: true,
enableHighlight: true,
enableItalic: true,
enableStrikethrough: true,
enableInlineLatex: true,
enableLink: true,
enableWikiLink: true,
keepWikiBrackets: true,
autoEmbedBlockLink: false,
enableCalloutCopy: true,
calloutCopyPriority: true,
autoAddBlockId: false, // 默认关闭
allowManualBlockId: false, // 默认关闭
blockIdInsertPosition: BlockIdInsertPosition.END_OF_BLOCK, // 默认在块末尾插入
autoBlockDisplayText: true,
blockDisplayWordLimit: 3, // 英文单词限制3个单词
blockDisplayCharLimit: 5, // 字符限制5个字符
}