textSyntaxChangeWindow function

TextSyntaxChangeWindow textSyntaxChangeWindow({
  1. required TextDocument previousDocument,
  2. required TextDocument nextDocument,
  3. required TextDocumentChange change,
  4. int lookBehindLines = 0,
  5. int lookAheadLines = 0,
})

Implementation

TextSyntaxChangeWindow textSyntaxChangeWindow({
  required TextDocument previousDocument,
  required TextDocument nextDocument,
  required TextDocumentChange change,
  int lookBehindLines = 0,
  int lookAheadLines = 0,
}) {
  final previousStartLine = (change.startPosition.line - lookBehindLines).clamp(
    0,
    previousDocument.lineCount,
  );
  final previousEndLine = (change.oldEndPosition.line + lookAheadLines + 1)
      .clamp(previousStartLine, previousDocument.lineCount);
  final nextStartLine = (change.startPosition.line - lookBehindLines).clamp(
    0,
    nextDocument.lineCount,
  );
  final nextEndLine = (change.newEndPosition.line + lookAheadLines + 1).clamp(
    nextStartLine,
    nextDocument.lineCount,
  );
  return TextSyntaxChangeWindow(
    previousLines: TextSyntaxLineWindow(
      startLine: previousStartLine,
      endLine: previousEndLine,
    ),
    nextLines: TextSyntaxLineWindow(
      startLine: nextStartLine,
      endLine: nextEndLine,
    ),
  );
}