BertrandBev / code_field

A customizable code text field supporting syntax highlighting
https://bertrandbev.github.io/code_field/
MIT License
230 stars 61 forks source link

Invalid value: Only valid value is x: x #72

Closed CurrentIndex closed 1 year ago

CurrentIndex commented 1 year ago

I am implementing undo/redo function. When I assign codeController An exception occurred while texting.

  final codeController =  currentNode.codeController;

  codeController.text = '1';
  codeController.text = '12';
  codeController.text = '123';
  codeController.text = '123';
  codeController.text = '12';
  codeController.text = '1';

error message:

======== Exception caught by gesture ===============================================================
The following RangeError was thrown while handling a gesture:
RangeError (index): Invalid value: Only valid value is 0: -1

When the exception was thrown, this was the stack: 
#0      _StringBase.[] (dart:core-patch/string_patch.dart:258:41)
#1      CodeController.value= (package:code_text_field/src/code_field/code_controller.dart:165:33)
#2      TextEditingController.text= (package:flutter/src/widgets/editable_text.dart:159:5)
#3      EditPage.build.<anonymous closure> (package:summer/view/edit/edit_view.dart:38:26)
#4      _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1077:21)
#5      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:253:24)
#6      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:627:11)
#7      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:306:5)

The above errors are reported only in CodeController and CodeField, but they are normal in TextEditingController and TextField. The above errors can easily be repeated, and the complete code will not be pasted.

BertrandBev commented 1 year ago

@CurrentIndex thanks for pointing it out. It should be fixed on master now