Improve inserting a new item at the end of a list via Alt+Enter#16314
Improve inserting a new item at the end of a list via Alt+Enter#16314TCOTC wants to merge 5 commits intosiyuan-note:devfrom
Alt+Enter#16314Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Protyle editor’s list and hotkey behavior to better support inserting list sub-items (Alt+Enter) and to make “last child block” detection more robust by centralizing block-element checks.
Changes:
- Added
isBlockElement()helper and refactored callers to use it. - Introduced
getLastChildBlock()and replaced multiplelastElementChild.previousElementSiblingusages in list logic. - Reworked Alt+Enter handling to prioritize code-block language selection, list sub-item insertion, and callout type/title updates.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/src/protyle/wysiwyg/list.ts | Adds getLastChildBlock() and reworks sub-list insertion / indent-outdent logic to use it. |
| app/src/protyle/wysiwyg/keydown.ts | Refactors Alt+Enter dispatch between code blocks, lists, and callouts. |
| app/src/protyle/util/hasClosest.ts | Adds isBlockElement() and uses it inside hasClosestBlock(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (previousLastBlock.getAttribute("fold") === "1" && | ||
| previousLastBlock.getAttribute("data-type") === "NodeHeading") { | ||
| foldElement = previousLastBlock; | ||
| } |
There was a problem hiding this comment.
previousLastBlock can be null when getLastChildBlock(previousElement) fails to find any Node* child (e.g. a list item temporarily/accidentally containing only .protyle-action + .protyle-attr). In that case this branch will throw on previousLastBlock.getAttribute(...). Add a null-guard here (and decide on a fallback insertion point / foldElement behavior) before accessing attributes on previousLastBlock.
Alt+Enter之后,如果当前列表项块中没有子列表块,则在最后一个子块的后面新建列表块 https://ld246.com/article/1762643983269.lastElementChild.previousElementSibling获取最后一个子块的方式修改为通过新增的 getLastChildBlock 函数获取,也许能解决使用一些主题或插件时编辑列表会导致状态异常的情况(主题或插件会在编辑器中插入自定义的元素,导致.lastElementChild.previousElementSibling获取到的不是最后一个子块)