Skip to content
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

[BUG] Numeric List Continuation Issue #431

Open
1 task done
unreal0901 opened this issue Jan 1, 2025 · 1 comment
Open
1 task done

[BUG] Numeric List Continuation Issue #431

unreal0901 opened this issue Jan 1, 2025 · 1 comment

Comments

@unreal0901
Copy link

unreal0901 commented Jan 1, 2025

Has this bug been raised before?

  • I have checked "open" AND "closed" issues and this is not a duplicate

Description

Bug : Numeric List Continuation Issue with Nested Lists

Description:
When using the numeric list feature in the editor, pressing "Enter" twice to create a new list item does not properly continue the numeric sequence from the previous list. Instead, it breaks the numeric sequence and incorrectly switches to a bullet list before exiting on the third "Enter" key press.

Steps to Reproduce:

  1. Start a numeric list (e.g., "1. First item").
  2. Create a nested list by pressing "Tab" or using the nested list feature.
  3. Press "Enter" inside the nested list to create a new nested item.
    • Expected: A new nested item appears, continuing the nested list.
    • Actual: This works as expected.
  4. Press "Enter" again to exit the nested list and return to the main numeric list.
    • Expected: The numbering of the main numeric list continues from the previous numeric sequence (e.g., "2. Second item").
    • Actual: The editor switches to a bullet list instead of continuing the numeric sequence.
  5. Press "Enter" once more.
    • Expected: The sequence exits the list and starts a new line outside of the list.
    • Actual: Exiting works as expected.

Observed Behavior with Screenshots:

  1. Nested List Creation (Working as Expected):
    Pressing "Enter" inside the nested list creates a new nested item, which works as expected.
    image

  2. Breaking Numeric Sequence:
    On the third "Enter" press, the editor incorrectly switches to a bullet list instead of continuing the numeric sequence.
    image
    image

  3. Exiting the List (Working as Expected):
    Pressing "Enter" again exits the list properly, which works as expected.
    image

Expected Behavior:

  • The numeric list sequence should continue when exiting a nested list.
    For example:
    1. Main item  
        - Nested item  
    2. Next main item  
    

Actual Behavior:

  • The editor switches to a bullet list after exiting the nested list and does not continue the numeric sequence.

Environment:

Additional Notes:
This issue disrupts the flow of numeric lists, especially when working with nested structures, and requires manual intervention to fix the list sequence.

Screenshots

No response

Do you want to work on this issue?

No

@unreal0901
Copy link
Author

unreal0901 commented Jan 1, 2025

When pressing Enter on an empty list block that is not at the first depth, the current implementation decreases the block depth without checking the context of the outer depth. This can cause unexpected behavior, especially in numbered lists, where the numbering should ideally continue from the previous depth.


Code Context:

  • FIle are onKeyDown.tsx (inside plugins > lists> src> events) , decreaseBlockDepth.ts (editor > blocks > ) ,
if (!hasText) {
  if (isBlockIsInFirstDepth) {
    const currentOrder = block.meta.order;

    editor.batchOperations(() => {
      editor.deleteBlock({ blockId: block.id });
      editor.insertBlock(defaultBlock.type, { at: currentOrder, focus: true, blockData: defaultBlock });
    });
    return;
  }

  // Before decreasing the depth, check the previous depth for a numbered list.
  // If the previous depth contains a numbered-list, continue numbering from there.
  // This will ensure that numbered lists remain consistent across depths.
  editor.decreaseBlockDepth({ blockId: block.id });
  return;
}

export function decreaseBlockDepth(editor: YooEditor, options: BlockDepthOptions = {}) {
  const { at = editor.path.current, blockId } = options;

  const block = blockId ? editor.children[blockId] : findPluginBlockByPath(editor, { at });
  if (!block) return;
  const isBulletedList =block.type === 'bulleted-list';
  const parentBlock=  // HOW TO GET PARENT BLOCK??
  if(isBulletedList && parentBlock.type === 'numbered-list'){
    // Then do some other type of transformation, that is we  need to inserting block to numbered one continuing from parent block
  }
  else{
    const newDepth = Math.max(0, block.meta.depth - 1);

    const operation: YooptaOperation = {
      type: 'set_block_meta',
      id: block.id,
      properties: { depth: newDepth },
      prevProperties: { depth: block.meta.depth },
    };
  
    editor.applyTransforms([operation]);
  }

  1. Parent Block Check: Before decreasing the depth, check if the current block is a bulleted list and if its parent block is a numbered list.

  2. Continue Numbering: If the parent is a numbered list, insert a new block in the numbered list, continuing the numbering from the parent, without modifying the parent's type.

  3. Regular Depth Decrease: If the parent is not a numbered list, or the block is not a bulleted list, simply decrease the current block's depth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant