src/js/codemirror/fixOrderedListNumber.js
function fixNumber(lineNumber, prevIndentLength, startIndex, cm) {
  let indent, delimiter, text, indentLength;
  let index = startIndex;
  let lineText = cm.getLine(lineNumber);

  do {
    [, indent, , , delimiter, text] = listRE.exec(lineText);
    indentLength = indent.length;

    if (indentLength === prevIndentLength) {
      // fix number
      cm.replaceRange(`${indent}${index}${delimiter}${text}`, {
        line: lineNumber,
        ch: 0
      }, {
        line: lineNumber,
        ch: lineText.length
      });
      index += 1;
      lineNumber += 1;
    } else if (indentLength > prevIndentLength) {
      // nested list start
      lineNumber = fixNumber(lineNumber, indentLength, 1, cm);
    } else {
      // nested list end
      return lineNumber;
    }

    lineText = cm.getLine(lineNumber);
  } while (listRE.test(lineText));

  return lineNumber;
}
function fixNumber(lineNumber, prevIndentLength, startIndex, cm) {
  let indent, delimiter, text, indentLength;
  let index = startIndex;
  let lineText = cm.getLine(lineNumber);

  do {
    [, indent, , , delimiter, text] = listRE.exec(lineText);
    indentLength = indent.length;

    if (indentLength === prevIndentLength) {
      // fix number
      cm.replaceRange(`${indent}${index}${delimiter}${text}`, {
        line: lineNumber,
        ch: 0
      }, {
        line: lineNumber,
        ch: lineText.length
      });
      index += 1;
      lineNumber += 1;
    } else if (indentLength > prevIndentLength) {
      // nested list start
      lineNumber = fixNumber(lineNumber, indentLength, 1, cm);
    } else {
      // nested list end
      return lineNumber;
    }

    lineText = cm.getLine(lineNumber);
  } while (listRE.test(lineText));

  return lineNumber;
}
function fixNumber ( lineNumber , prevIndentLength , startIndex , cm ) { let indent , delimiter , text , indentLength ; let index = startIndex ; let lineText = cm . getLine ( lineNumber ) ; do { [ , indent , , , delimiter , text ] = listRE . exec ( lineText ) ; indentLength = indent . length ; if ( indentLength === prevIndentLength ) { // fix number cm . replaceRange ( ` ${ indent } ${ index } ${ delimiter } ${ text } ` , { line : lineNumber , ch : 0 } , { line : lineNumber , ch : lineText . length } ) ; index += 1 ; lineNumber += 1 ; } else if ( indentLength > prevIndentLength ) { // nested list start lineNumber = fixNumber ( lineNumber , indentLength , 1 , cm ) ; } else { // nested list end return lineNumber ; } lineText = cm . getLine ( lineNumber ) ; } while ( listRE . test ( lineText ) ) ; return lineNumber ; }
fix list numbers
@param {number} lineNumber - line number of list item to be normalized
@param {number} prevIndentLength - previous indent length
@param {number} startIndex - start index
@param {CodeMirror} cm - CodeMirror instance
@returns {number} - next line number
@ignore
fix list numbers