Skip to content

fix(editor): prevent length mismatch assertion error in QueryaHighlightController for scripts > 8KB #909

Closed

Description

@ZhuchkaTriplesix

Summary

In QueryaHighlightController.buildTextSpan (lib/core/editor/querya_highlight_controller.dart, lines 70–82):
When editing text whose length exceeds kSyntaxHighlightIsolateThreshold (8192 characters), syntax highlighting is offloaded to an isolate with a 100ms debounce.

While waiting for the background isolate to complete:

if (_cachedSpan != null) {
  return TextSpan(style: style, children: [_cachedSpan!]);
}
return TextSpan(style: style, text: text);

If the user is actively typing or deleting characters, _cachedSpan holds the TextSpan from the previous text version (_cachedText), while text has changed.

Flutter's RenderEditable requires that span.toPlainText() == text. Returning a stale _cachedSpan with mismatched length causes Assertion failed: span.toPlainText() == text in debug mode, and corrupts cursor rendering and selection offsets in release mode.

Repro

  1. Open a SQL script larger than 8 KB in Querya SQL Editor.
  2. Type or delete characters in the editor.
  3. Observe AssertionError: span.toPlainText() == text or cursor offset jumping while typing before the 100ms debounce finishes.

Scope

  • In QueryaHighlightController.buildTextSpan, verify _cachedText == text before returning _cachedSpan.
  • Fall back to plain TextSpan(style: style, text: text) while new highlight tokens are pending from the isolate.

Out of scope

  • Grammar parsing logic in syntax_highlight package.

Activity

  1. added this to the 0.4.18 milestone on Sep 23, 2026
  2. ZhuchkaTriplesix commented on Sep 27, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Resolved by #944 (already merged into dev; not auto-closed since this repo's default branch is main and PRs merge into dev).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingeditorCode/SQL editor

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions