Skip to content

Improve inserting a new item at the end of a list via Alt+Enter#16314

Open
TCOTC wants to merge 5 commits intosiyuan-note:devfrom
TCOTC:fix/list
Open

Improve inserting a new item at the end of a list via Alt+Enter#16314
TCOTC wants to merge 5 commits intosiyuan-note:devfrom
TCOTC:fix/list

Conversation

@TCOTC
Copy link
Copy Markdown
Contributor

@TCOTC TCOTC commented Nov 9, 2025

  • Alt+Enter 之后,如果当前列表项块中没有子列表块,则在最后一个子块的后面新建列表块 https://ld246.com/article/1762643983269
  • 把通过 .lastElementChild.previousElementSibling 获取最后一个子块的方式修改为通过新增的 getLastChildBlock 函数获取,也许能解决使用一些主题或插件时编辑列表会导致状态异常的情况(主题或插件会在编辑器中插入自定义的元素,导致 .lastElementChild.previousElementSibling 获取到的不是最后一个子块)

Copy link
Copy Markdown
Contributor

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 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 multiple lastElementChild.previousElementSibling usages 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.

Comment on lines +242 to 245
if (previousLastBlock.getAttribute("fold") === "1" &&
previousLastBlock.getAttribute("data-type") === "NodeHeading") {
foldElement = previousLastBlock;
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread app/src/protyle/wysiwyg/list.ts Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Vanessa219 Vanessa219 removed this from the 3.6.0 milestone Mar 12, 2026
@88250 88250 added this to the 3.6.2 milestone Mar 16, 2026
@TCOTC TCOTC closed this Mar 17, 2026
@TCOTC TCOTC deleted the fix/list branch March 17, 2026 20:14
@TCOTC TCOTC restored the fix/list branch March 17, 2026 20:16
@TCOTC TCOTC reopened this Mar 17, 2026
@88250 88250 modified the milestones: 3.6.2, 3.6.3 Mar 23, 2026
@88250 88250 modified the milestones: 3.6.3, 3.6.4 Mar 31, 2026
@88250 88250 modified the milestones: 3.6.4, 3.6.5, 3.6.6 Apr 9, 2026
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.

4 participants