Skip to content

Issue 172: Delete CodeController.theme, bump version to 0.3.0 #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.0

* **BREAKING:** Deleted `CodeController.stringMap`.
* **BREAKING:** Deleted `theme` from `CodeController`, (Issue [172](https://github.com/akvelon/flutter-code-editor/issues/172)).

## 0.2.24

* Hide the suggestion box when `CodeField` is disposed (Issue [241](https://github.com/akvelon/flutter-code-editor/issues/241)).
Expand Down
50 changes: 0 additions & 50 deletions lib/src/code_field/code_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ class CodeController extends TextEditingController {
/// A map of specific regexes to style
final Map<String, TextStyle>? patternMap;

/// A map of specific keywords to style
final Map<String, TextStyle>? stringMap;

/// Common editor params such as the size of a tab in spaces
///
/// Will be exposed to all [modifiers]
Expand Down Expand Up @@ -101,7 +98,6 @@ class CodeController extends TextEditingController {

final _styleList = <TextStyle>[];
final _modifierMap = <String, CodeModifier>{};
RegExp? _styleRegExp;
late PopupController popupController;
final autocompleter = Autocompleter();
late final historyController = CodeHistoryController(codeController: this);
Expand Down Expand Up @@ -143,12 +139,9 @@ class CodeController extends TextEditingController {
this.namedSectionParser,
Set<String> readOnlySectionNames = const {},
Set<String> visibleSectionNames = const {},
@Deprecated('Use CodeTheme widget to provide theme to CodeField.')
Map<String, TextStyle>? theme,
this.analysisResult = const AnalysisResult(issues: []),
this.patternMap,
this.readOnly = false,
this.stringMap,
this.params = const EditorParams(),
this.modifiers = const [
IndentModifier(),
Expand Down Expand Up @@ -178,15 +171,10 @@ class CodeController extends TextEditingController {

// Build styleRegExp
final patternList = <String>[];
if (stringMap != null) {
patternList.addAll(stringMap!.keys.map((e) => r'(\b' + e + r'\b)'));
_styleList.addAll(stringMap!.values);
}
if (patternMap != null) {
patternList.addAll(patternMap!.keys.map((e) => '($e)'));
_styleList.addAll(patternMap!.values);
}
_styleRegExp = RegExp(patternList.join('|'), multiLine: true);

popupController = PopupController(onCompletionSelected: insertSelectedWord);

Expand Down Expand Up @@ -911,47 +899,9 @@ class CodeController extends TextEditingController {
).build();
}

if (_styleRegExp != null) {
return _processPatterns(text, style);
}

return TextSpan(text: text, style: style);
}

TextSpan _processPatterns(String text, TextStyle? style) {
final children = <TextSpan>[];

text.splitMapJoin(
_styleRegExp!,
onMatch: (Match m) {
if (_styleList.isEmpty) {
return '';
}

int idx;
for (idx = 1;
idx < m.groupCount &&
idx <= _styleList.length &&
m.group(idx) == null;
idx++) {}

children.add(
TextSpan(
text: m[0],
style: _styleList[idx - 1],
),
);
return '';
},
onNonMatch: (String span) {
children.add(TextSpan(text: span, style: style));
return '';
},
);

return TextSpan(style: style, children: children);
}

CodeThemeData _getTheme(BuildContext context) {
return CodeTheme.of(context) ?? CodeThemeData();
}
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: flutter_code_editor
description: A customizable code field supporting syntax highlighting and code folding.
version: 0.2.24
version: 0.3.0
repository: https://github.com/akvelon/flutter-code-editor

environment:
Expand Down