make TreeSitterService a shared singleton
Each ClideCodeBlock and EditorView created its own TreeSitterService, each allocating a WASM engine, store, parser, and cursor via FFI. When widgets were disposed, multiple instances freeing the same underlying native resources caused double-free corruption on startup. Single shared instance for the app lifetime. Also fixes overlapping tree-sitter spans that caused duplicated text in code blocks — spans are now clipped to avoid re-emitting already-rendered characters. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,7 @@ class EditorView extends StatefulWidget {
|
||||
|
||||
class _EditorViewState extends State<EditorView> {
|
||||
EditorController? _controller;
|
||||
final TreeSitterService _syntax = TreeSitterService();
|
||||
final TreeSitterService _syntax = TreeSitterService.shared;
|
||||
late final SyntaxTextController _text;
|
||||
late final FocusNode _focus;
|
||||
String? _lastRemoteContent;
|
||||
@@ -57,7 +57,6 @@ class _EditorViewState extends State<EditorView> {
|
||||
_focus.dispose();
|
||||
_controller?.removeListener(_onControllerChanged);
|
||||
_controller?.dispose();
|
||||
_syntax.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user