Skip to content

Commit

Permalink
Fix a glitch where the text field would not have the same value of th…
Browse files Browse the repository at this point in the history
…e file
  • Loading branch information
ThomasGysemans committed Jul 31, 2023
1 parent 4cc6087 commit 30f6cbf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [2.0.1] - July 31, 2023
## [2.0.2] - July 31, 2023

+ Fix a lot of typo
+ Fix a glitch (the text field would not have the same value as the current file)
+ Add important note on README

## [2.0.0] - July 31, 2023
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ It's very easy to install :

```yaml
dependencies:
code_editor: ^2.0.1
code_editor: ^2.0.2
```
* Don't forget to update the modifications of the pubspec.yaml file
Expand Down
4 changes: 2 additions & 2 deletions lib/EditorModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class EditorModel extends ChangeNotifier {
}

/// Overwrite the current code of the file where [index] corresponds by [newCode].
void updateCodeOfIndex(int index, String? newCode) {
this.allFiles[index].code = newCode ?? "";
void updateCodeOfIndex(int index, String newCode) {
this.allFiles[index].code = newCode;
}

void notify() => notifyListeners();
Expand Down
9 changes: 5 additions & 4 deletions lib/code_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ class _CodeEditorState extends State<CodeEditor> {
final EditorModelStyleOptions opt = widget.model.styleOptions;

/// Which file in the list of file?
final int? position = widget.model.position;
final int position = widget.model.position;

/// The content of the file where position corresponds to the list of file.
final String? code = widget.model.getCodeWithIndex(position ?? 0);
final String? code = widget.model.getCodeWithIndex(position);

// if the user does not change the value in the text field
newValue = code;
Expand Down Expand Up @@ -554,7 +554,7 @@ class _CodeEditorState extends State<CodeEditor> {
editButton("OK", () {
// Here, the user completed a change in the code
setState(() {
recordBeforeAction(widget.model.getFileWithIndex(position ?? 0)!);
recordBeforeAction(widget.model.getFileWithIndex(position)!);

String newCode = newValue ?? "";
if (widget.textModifier != null) {
Expand All @@ -563,7 +563,8 @@ class _CodeEditorState extends State<CodeEditor> {
if (widget.formatters.contains(widget.model.currentLanguage)) {
newCode = format(newCode, widget.model.currentLanguage);
}
widget.model.updateCodeOfIndex(position ?? 0, newCode);
editingController.text = newCode; // without it editing twice the same file in a row would display the previous content
widget.model.updateCodeOfIndex(position, newCode);
widget.model.toggleEditing();
widget.onSubmit?.call(widget.model.currentLanguage, newCode);
});
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: code_editor
description: A code editor (dart, js, html,...) for Flutter with syntax highlighting and custom theme.
version: 2.0.1
version: 2.0.2
homepage: https://github.com/CodoPixel/code_editor

environment:
Expand Down

0 comments on commit 30f6cbf

Please sign in to comment.