Skip to content

Commit

Permalink
feat: support chinese embed tiddler trigger brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Sep 25, 2024
1 parent 7c86f7c commit 5127a5f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
`1.8.0`: 帮助菜单支持连续触发补全弹窗
`1.8.2`: 代码片段预览改成纯文本
`1.8.4`: 修复嵌入标题含有特殊引号的问题
`1.8.4`: 修复嵌入标题含有特殊引号的问题
`1.8.5`: 支持中文`【【` 触发
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"registry": "https://registry.npmjs.org"
},
"license": "MIT",
"version": "1.8.4",
"version": "1.8.5",
"packageManager": "[email protected]",
"scripts": {
"update:config": " pnpm ts-node scripts/generateConfig.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/lang-tiddlywiki/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lang-tiddlywiki",
"version": "1.8.4",
"version": "1.8.5",
"description": "",
"scripts": {
"build": "cm-buildhelper src/tiddlywiki.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import snippets from './snippets';
import tags from './tags';
import template from './template';
import tiddlers from './tiddlers';
import tiddlersCn from './tiddlers-cn';
import tiddlersEmbed from './tiddlers-embed';
import widget from './widget';
// import markdown from './markdown';
Expand All @@ -29,6 +30,7 @@ const sources = [
tags,
tiddlersEmbed,
tiddlers,
tiddlersCn,
widget,
template
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Completion } from '@codemirror/autocomplete';
import conf from '@/cm6/config';
import { renderTid } from '@/cm6/utils/renderTiddler';
import { EditorView } from '@codemirror/view';

const type = 'cm-tiddler';
const section = 'tiddlers';
const delimiter = '【【';
const description = 'Tiddler Embed in Chinese';

export function getAllTiddlers(delimiter: string) {
const systemFilter =
'[all[tiddlers+shadows]!has[draft.of]!prefix[$:/status]!preifx[$:/temp]!prefix[$:/state]!tag[$:/tags/TextEditor/Snippet]!prefix[$:/language]!prefix[$:/config/Server/]!prefix[Draft of]]';
const filter = conf.enableSystemTiddlersCompletion()
? systemFilter
: '[!is[system]!has[draft.of]]';
const allTiddlers = $tw.wiki.filterTiddlers(filter);

return allTiddlers.map(
(title) =>
({
label: delimiter + title,
displayLabel: title.length > 35 ? title.slice(0, 35) + ' …' : title,
type,
section,
boost: title.startsWith('$') ? 0 : 1,
// NOTE: TypeError: Cannot set property parentNode of #<Node> which has only a getter, 部分 widget 使用到$tw 的 fakedom api, 会导致报错。
info: () => renderTid(title),
apply: (view: EditorView, completion, from, to) => {
view.dispatch({
changes: { from, to, insert: '[[' + title + ']]' }
});
}
}) as Completion
);
}

export default {
section,
type,
delimiter,
description,
snippets: () => getAllTiddlers(delimiter)
};
2 changes: 1 addition & 1 deletion src/tiddlywiki-codemirror-6/plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "$:/plugins/oeyoews/tiddlywiki-codemirror-6",
"name": "CodeMirror6",
"description": "CodeMirror 6 editor",
"version": "1.8.4",
"version": "1.8.5",
"core-version": ">=5.3.3",
"list": "readme usage"
}

0 comments on commit 5127a5f

Please sign in to comment.