Repository navigation
QA Testing: Heading Plugin
Determining which heading levels are available at any point within the document
The original algorithm was based on finding the previous heading (PH) relative to the current insertion point (CIP), if such heading exists. The variable used for storing the tag name of that heading was named lastHeading, and its value is null when there is no previous heading.
The new algorithm is based on the recognition that looking ahead from the CIP to the next heading (NH), if it exists, could prevent enabling the insertion of a heading level that would create an out-of-sequence (OOS) situation. In the new algorithm, the lastHeading variable name was changed to prevHeading and a new variable named nextHeading was created.
For example, if the CIP is between an h3 and an h4, the old algorithm, which took into account only the previous heading (PH), would have allowed headings ranging from the top-most level in the configuration (based on startIndex -- see below), which, for this example, let us assume is an h2, down to the heading that is one level below the previous heading.
Thus, the available headings list (AHL) would be ['h2', 'h3', 'h4']. However, if an h2 heading is inserted between the h3 and h4, this creates an OOS situation, due to the gap between the (new) h2 and the h4.
Continuing with the example of the CIP being between an h3 and an h4, by determining that the next heading (NH) is an h4, the new algorithm excludes headings above the level of the previous heading (PH). The AHL it returns is ['h3', 'h4'] and the OOS situation is avoided.
-
CIP is not on a heading
-
No headings exist in the document (i.e. there is no previous or next heading)
-
CIP is before the first heading (i.e. there is no previous heading)
-
CIP is after the last heading (i.e. there is no next heading)
-
CIP is between two headings (i.e. there is both a previous and next heading)
-
-
CIP is on a heading
-
It's the only heading (n = 1) (i.e. there is no previous or next heading)
-
It's the first heading of n > 1 (i.e. there is no previous heading, there is a next heading)
-
It's the last heading of n > 1 (i.e. there is no next heading, there is a previous heading)
-
It's neither the first or last heading of n > 2 (i.e. there is both a previous and next heading)
-
It seems that we do need to distinguish between the CIP being on a heading or not. To see why that is, consider the difference between the following two example situations:
-
With the current (new) algorithm, which does not distinguish between the CIP being on a heading or not, when the CIP is on a heading, the algorithm considers the next heading to be the heading on which the CIP currently rests. In the case where the PH is
h3and the CIP/NH ish4, changing theh4to anh2is disallowed. In this case, the AHL for the CIP/NH is['h3', 'h4']. -
If the algorithm where changed such that when the CIP is on a heading, it would find the next heading after the current CIP heading, the algorithm becomes less restrictive. In the case where PH is
h3, the CIP/CH ish4and NH ish3, then it would allow changing the CIP/CH fromh4toh2. In this case, the AHL for the CIP/CH is['h2', 'h3', 'h4'].
By modifying the algorithm (i.e. the first algorithm that was based on both prevHeading and nextHeading) to always find nextHeading beyond the selectedElement (based on CIP), even when the CIP is on a heading, it makes it irrelevant whether the selectedElement is a heading or not.
Thus, the hypotheses, which needs further testing, is: The allowedHeadings, when based on both prevHeading and nextHeading, are the same, regardless of whether the selectedElement is a heading or not.
In other words, determining which heading levels I can insert between two headings is the same as determining the heading levels that are available for a heading that is between those same two headings.
It is important to understand the following variables and how they are used.
This is an array of heading tag names based on the a11yheading configuration. For example, if the configuration specifies headings h1 through h6, the headingTags array would have the value
['h1','h2','h3','h4','h5','h6']
If there is a prevHeading and it is in the
- What if the CIP is placed before an
h1, andconfig.allow_only_one_h1 === true?