-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Improve code block language selection #15966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
可以 Review 了,如果有问题的话尽量在 PR 内解决,不要合并之后又修改。 |
|
好的,这个只改了一个文件,我先手动拷贝到本地测试一下。 |
|
好像不行,我把 https://github.com/TCOTC/siyuan/edit/feat/code/app/src/protyle/toolbar/index.ts?pr=%2Fsiyuan-note%2Fsiyuan%2Fpull%2F15966 这个拷贝进去有很多改动点又把代码改回去了,是否可以把这个文件的最新代码发我一份?
|
|
我变基了一下,现在应该可以直接复制了 |
There was a problem hiding this 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-updateevent 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(); |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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.
| event.preventDefault(); | |
| event.preventDefault(); | |
| event.stopPropagation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TCOTC 移除这个的原因是?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vanessa219 前面有,后面多余的就删了
| // 转义正则特殊字符 | ||
| const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
| // 创建不区分大小写的正则表达式 | ||
| const regex = new RegExp(escapedSearch, "gi"); | ||
| // 替换匹配内容并保留原始大小写 |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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).
| // 转义正则特殊字符 | |
| 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 |
| matchLanguages = hljsLanguages.filter( | ||
| item => item.toLowerCase().includes(lowerCaseValue) | ||
| ).sort((a, b) => { | ||
| // 不区分大小写 |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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'.
| // 不区分大小写 | |
| // Case-insensitive comparison |
| const aStartsWith = a.toLowerCase().startsWith(lowerCaseValue); | ||
| const bStartsWith = b.toLowerCase().startsWith(lowerCaseValue); | ||
|
|
||
| // 两者都匹配开头时,短字符串优先 |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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'.
| // 两者都匹配开头时,短字符串优先 | |
| // When both match the prefix, shorter strings take priority |
| if (aStartsWith) return -1; | ||
| if (bStartsWith) return 1; | ||
|
|
||
| // 都不匹配时保持原顺序 |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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'.
| // 都不匹配时保持原顺序 | |
| // Maintain original order when neither matches |

code-language-update添加type、value、listElement参数,满足插件需求;需要同步修改 petalvideo.webm
关联前一个 PR:#15610