Skip to content

Conversation

@TCOTC
Copy link
Contributor

@TCOTC TCOTC commented Sep 26, 2025

  1. 如果用户输入的文本能直接匹配任意一个语言及其别名(支持大小写混合输入),则排序到列表首位(#15610 (comment)
  2. 不支持高亮的“自定义语言”排序到列表末尾(投票
  3. 给选项添加 data-id 属性(#12518
  4. 给事件 code-language-update 添加 typevaluelistElement 参数,满足插件需求;需要同步修改 petal
video.webm

关联前一个 PR:#15610

@TCOTC
Copy link
Contributor Author

TCOTC commented Sep 26, 2025

可以 Review 了,如果有问题的话尽量在 PR 内解决,不要合并之后又修改。

@TCOTC TCOTC marked this pull request as ready for review September 26, 2025 17:16
@88250 88250 requested a review from Vanessa219 September 27, 2025 01:58
@88250 88250 modified the milestones: 3.3.4, 3.3.5 Sep 27, 2025
@88250 88250 modified the milestones: 3.3.5, 3.3.6 Oct 14, 2025
@Vanessa219
Copy link
Member

好的,这个只改了一个文件,我先手动拷贝到本地测试一下。

@Vanessa219
Copy link
Member

好像不行,我把 https://github.com/TCOTC/siyuan/edit/feat/code/app/src/protyle/toolbar/index.ts?pr=%2Fsiyuan-note%2Fsiyuan%2Fpull%2F15966 这个拷贝进去有很多改动点又把代码改回去了,是否可以把这个文件的最新代码发我一份?

QQ_1760931616741

@TCOTC
Copy link
Contributor Author

TCOTC commented Oct 20, 2025

我变基了一下,现在应该可以直接复制了

@Vanessa219 Vanessa219 requested a review from Copilot October 20, 2025 09:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request improves the code block language selection functionality in the editor by enhancing the search and filtering behavior.

Key Changes

  • Exact language matches (case-insensitive) are now prioritized and moved to the top of the language list
  • Custom languages without syntax highlighting support are moved to the end of the list
  • The code-language-update event now includes additional parameters (type, value, listElement) for plugin integration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

upDownHint(listElement, event);
if (event.key === "Enter") {
this.updateLanguage(languageElements, protyle, this.subElement.querySelector(".b3-list-item--focus").textContent);
event.preventDefault();
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event.stopPropagation() call was removed from line 1276 after the Enter key handler. This could allow the event to bubble up unexpectedly. Consider whether event propagation should still be stopped here to maintain consistent behavior with the Escape key handler on line 1281.

Suggested change
event.preventDefault();
event.preventDefault();
event.stopPropagation();

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TCOTC 移除这个的原因是?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vanessa219 前面有,后面多余的就删了

Image

Comment on lines +1285 to +1289
// 转义正则特殊字符
const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// 创建不区分大小写的正则表达式
const regex = new RegExp(escapedSearch, "gi");
// 替换匹配内容并保留原始大小写
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline comments are in Chinese while the codebase appears to use English elsewhere. Consider translating these comments to English for consistency: '转义正则特殊字符' (Escape regex special characters), '创建不区分大小写的正则表达式' (Create case-insensitive regex), '替换匹配内容并保留原始大小写' (Replace matches while preserving original case).

Suggested change
// 转义正则特殊字符
const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// 创建不区分大小写的正则表达式
const regex = new RegExp(escapedSearch, "gi");
// 替换匹配内容并保留原始大小写
// Escape regex special characters
const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
// Create case-insensitive regex
const regex = new RegExp(escapedSearch, "gi");
// Replace matches while preserving original case

Copilot uses AI. Check for mistakes.
matchLanguages = hljsLanguages.filter(
item => item.toLowerCase().includes(lowerCaseValue)
).sort((a, b) => {
// 不区分大小写
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline comment '不区分大小写' is in Chinese. Consider translating to English: 'Case-insensitive comparison'.

Suggested change
// 不区分大小写
// Case-insensitive comparison

Copilot uses AI. Check for mistakes.
const aStartsWith = a.toLowerCase().startsWith(lowerCaseValue);
const bStartsWith = b.toLowerCase().startsWith(lowerCaseValue);

// 两者都匹配开头时,短字符串优先
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline comment '两者都匹配开头时,短字符串优先' is in Chinese. Consider translating to English: 'When both match the prefix, shorter strings take priority'.

Suggested change
// 两者都匹配开头时,短字符串优先
// When both match the prefix, shorter strings take priority

Copilot uses AI. Check for mistakes.
if (aStartsWith) return -1;
if (bStartsWith) return 1;

// 都不匹配时保持原顺序
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline comment '都不匹配时保持原顺序' is in Chinese. Consider translating to English: 'Maintain original order when neither matches'.

Suggested change
// 都不匹配时保持原顺序
// Maintain original order when neither matches

Copilot uses AI. Check for mistakes.
@Vanessa219 Vanessa219 merged commit a059372 into siyuan-note:dev Oct 20, 2025
@TCOTC TCOTC deleted the feat/code branch October 20, 2025 11:04
@TCOTC TCOTC mentioned this pull request Oct 21, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants