Repository navigation
feat: implement toggling between list and plain text #375
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
Merged
vitonsky
merged 12 commits into
master
from
275-implement-toggling-between-list-and-plain-text
Oct 13, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
96d6ad6
feat: convert list to text
katsyuta 615a683
chore: add test
katsyuta 5e3673b
test: add
katsyuta 41c17b3
fix: first unified list
katsyuta 56873e8
fix: handle nested items
katsyuta 48bafd6
fix: incorrect item order
katsyuta d9d3a22
refactor: return guard for empty editor
katsyuta caa7e51
test: improve
katsyuta bda61b5
chore: fix typo
katsyuta 9c98450
refactor: unlist nested lists as single paragraph
vitonsky b9cae16
refactor: move list formatting logic into plugin
vitonsky b618b90
test: cover selection cases
vitonsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...pp/src/features/NoteEditor/RichEditor/plugins/ListFormattingPlugin/$convertListToLines.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { | ||
| $createLineBreakNode, | ||
| $createParagraphNode, | ||
| $isParagraphNode, | ||
| LexicalNode, | ||
| } from 'lexical'; | ||
| import { $isListItemNode, $isListNode, ListNode } from '@lexical/list'; | ||
|
|
||
| const $getLines = (node: LexicalNode): LexicalNode[][] => { | ||
| if ($isListNode(node)) return node.getChildren().flatMap($getLines); | ||
| if (!$isListItemNode(node)) return []; | ||
|
|
||
| const lines: LexicalNode[][] = []; | ||
| let currentLine: LexicalNode[] = []; | ||
|
|
||
| node.getChildren().forEach((child) => { | ||
| if ($isListNode(child)) { | ||
| if (currentLine.length > 0 || lines.length === 0) { | ||
| lines.push(currentLine); | ||
| currentLine = []; | ||
| } | ||
| lines.push(...$getLines(child)); | ||
| } else if ($isParagraphNode(child)) { | ||
| currentLine.push(...child.getChildren()); | ||
| } else { | ||
| currentLine.push(child); | ||
| } | ||
| }); | ||
|
|
||
| if (currentLine.length > 0 || lines.length === 0) lines.push(currentLine); | ||
| return lines; | ||
| }; | ||
|
|
||
| /** | ||
| * Convert list items back into lines, placing nested-list lines in their parent item. | ||
| */ | ||
| export const $convertListToLines = (list: ListNode) => { | ||
| const parent = list.getParent(); | ||
| const lines = $getLines(list); | ||
|
|
||
| if ($isListItemNode(parent)) { | ||
| // Keep converted lines in the item's existing paragraph when it has one. | ||
| const paragraph = parent.getChildren().find($isParagraphNode); | ||
| const append = (node: LexicalNode) => { | ||
| if (paragraph) paragraph.append(node); | ||
| else list.insertBefore(node); | ||
| }; | ||
|
|
||
| lines.forEach((line) => { | ||
| append($createLineBreakNode()); | ||
| line.forEach(append); | ||
| }); | ||
| } else { | ||
| // A top-level list becomes one paragraph per top-level item. Descendants become | ||
| // line breaks within their top-level item's paragraph. | ||
| list.getChildren().forEach((node) => { | ||
| if (!$isListItemNode(node)) return; | ||
|
|
||
| const itemLines = $getLines(node); | ||
| const paragraph = $createParagraphNode(); | ||
| itemLines.forEach((line, index) => { | ||
| if (index > 0) paragraph.append($createLineBreakNode()); | ||
| paragraph.append(...line); | ||
| }); | ||
| list.insertBefore(paragraph); | ||
| }); | ||
| } | ||
|
|
||
| list.remove(); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.