reqable / re-editor

Re-Editor is a powerful lightweight text and code editor widget.
https://pub.dev/packages/re_editor
MIT License
527 stars 51 forks source link

Allow clearing of CodeLineEditingController's undo stack #37

Closed TechnicJelle closed 2 months ago

TechnicJelle commented 2 months ago

Is your feature request related to a problem? Please describe. I have a code editor that can switch between multiple files. When that happens, I do this: codeController.text = file.readAsStringSync(); to make the code editor switch to the new file. However, this still allows the user to undo (Ctrl+Z) to the previous file, which effectively deletes one file, and duplicates another in its place.

Describe the solution you'd like The solution I would like is being able to clear the history of a CodeLineEditingController. So I can do something like this:

void readFile(File file) {
  codeLineEditingController.text = file.readAsStringSync();
  codeLineEditingController.clearHistory();
  openFile = file;
}

Describe alternatives you've considered I could rebuild the entire CodeEditor widget instead of changing the CodeLineEditingController.text, but that makes the code highlighting reset every time, as per #2.

Additional context I found that this library uses a _CodeLineEditingCache under the hood, to keep track of the history. It has a method void markNewRecord(bool flag), which I think already does exactly what I want. The only thing necessary would be to open this method up to the end user. (I think)

Thank you for making this library, by the way! It is super amazing! I love it a lot!

MegatronKing commented 2 months ago

Done on v0.4.0.

TechnicJelle commented 2 months ago

Wow, that was super fast! Thank you so much!!! :purple_heart: