Skip to content

Incorrect unordered list structure, when indented by tabs #2172

@alexgarbarev

Description

@alexgarbarev

Currently, if we try to parse list like that

* one
\t* nested one
\t* nested two

* two

it would be parsed into following structure

  • one
    • nested one
      • nested two
  • two

while it's expected to be

  • one
    • nested one
    • nested two
  • two

After lots of debugging I found that in the list_syntax.dart file, in the parse method, there are two variables indent and currentIndent that are crucial to detect nested list.
And the currentIndent is calculated as:

final currentIndent = parser.current.content.indentation() +
          (parser.current.tabRemaining ?? 0);

while indent in this case is calculated as

indent = precedingWhitespaces + contentWhitespances

In the case above, when we have list indented by tabs, we have tabRemaining as 2 for both nested lines of second level, but because indent is not taking into account tabRemaining there, it mistakenly adds unwanted nesting later, when we compare indent <= currentIndent (which is 2 <= 2 for the "nested two" element).

So my suggested fix is to change indent calculation by adding tabRemaining there:

indent = precedingWhitespaces +
              contentWhitespances +
              (parser.current.tabRemaining ?? 0)

That way all tests are passing. But I'm not sure if we should also add the same fix to contentWhitespances >= 4 branch above, and I couldn't find a test case for that branch.

Could someone please validate the fix? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions