From bf2e2b7df29060fc71bba111376a4a360a6068f0 Mon Sep 17 00:00:00 2001 From: VAUsoltsev Date: Thu, 20 Aug 2026 17:32:22 +0300 Subject: [PATCH] Do not fail highlighting when the theme declares no languages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `CodeHighlightTheme(languages: {})` is a legitimate thing to build: an editor that shows a file whose language it does not recognise still wants the theme for its text colours. The payload then carried empty lists of sizes, `_run` reduced them, and `Bad state: No element` was thrown — inside the isolate, so highlighting died silently and all that was left was an unhandled exception in the console. Nothing to highlight is now answered with an empty result, as it already is when there is no theme at all. --- lib/src/_code_highlight.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/_code_highlight.dart b/lib/src/_code_highlight.dart index 6c6af79..639192c 100644 --- a/lib/src/_code_highlight.dart +++ b/lib/src/_code_highlight.dart @@ -213,7 +213,12 @@ class _CodeHighlightEngine { return; } final Map? modes = _theme?.languages; - if (modes == null) { + // An empty language map means there is nothing to highlight, which is not + // a reason to fail. Without this the payload carried empty lists of sizes, + // `_run` reduced them, and `Bad state: No element` was thrown inside the + // isolate: highlighting died silently and left an unhandled exception in + // the console. + if (modes == null || modes.isEmpty) { callback(const []); return; }