MCPcopy Create free account
hub / github.com/CatMuse/HiNote / display

Method display

src/settings/components/RegexRuleEditor.ts:31–69  ·  view source on GitHub ↗

* 显示规则列表

()

Source from the content-addressed store, hash-verified

29 * 显示规则列表
30 */
31 private display() {
32 this.rulesContainer.empty();
33
34 // 添加警告提示和示例
35 const warningEl = this.rulesContainer.createDiv({ cls: 'regex-rule-warning' });
36 warningEl.setText(t('Use regex with caution. If there are capture groups (), the first capture group will be used as the highlight text; if there are no capture groups, the entire match will be used.'));
37
38 // 显示现有规则
39 if (this.rules.length === 0) {
40 const emptyEl = this.rulesContainer.createDiv();
41 emptyEl.setText(t('No custom regex rules. Click "+" to add a new rule.'));
42 } else {
43 this.rules.forEach((rule, index) => {
44 this.createRuleItem(rule, index);
45 });
46 }
47
48 // 添加新规则按钮
49 const addButton = this.rulesContainer.createDiv({ cls: 'regex-rule-add' });
50
51 // 添加加号图标和文本
52 const textSpan = addButton.createSpan({ cls: 'regex-rule-add-text' });
53 textSpan.setText(t('Add new rule'));
54
55 // 添加点击事件
56 addButton.addEventListener('click', () => {
57 const newRule: RegexRule = {
58 id: `rule-${Date.now()}`,
59 name: '',
60 pattern: '',
61 color: '#ffeb3b', // 使用固定的默认黄色
62 enabled: true
63 };
64
65 this.rules.push(newRule);
66 void this.saveRules();
67 this.display(); // 重新渲染整个列表
68 });
69 }
70
71 /**
72 * 创建单个规则项

Callers 2

constructorMethod · 0.95
createRuleItemMethod · 0.95

Calls 3

createRuleItemMethod · 0.95
saveRulesMethod · 0.95
tFunction · 0.90

Tested by

no test coverage detected