Skip to content

Commit

Permalink
Swap to a better Code Editor
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
TechnicJelle committed Sep 6, 2024
1 parent fe03347 commit cd96faf
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 123 deletions.
71 changes: 47 additions & 24 deletions lib/config_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import "dart:async";
import "dart:io";

import "package:flutter/material.dart";
import "package:flutter_code_editor/flutter_code_editor.dart";
import "package:flutter_highlight/themes/ir-black.dart" show irBlackTheme;
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:highlight/languages/yaml.dart" show yaml;
import "package:re_editor/re_editor.dart";
import "package:re_highlight/languages/yaml.dart" show langYaml;
import "package:re_highlight/styles/ir-black.dart" show irBlackTheme;

import "dual_pane.dart";
import "utils.dart";
Expand All @@ -20,8 +20,7 @@ class ConfigEditor extends ConsumerStatefulWidget {
}

class _ConfigEditorState extends ConsumerState<ConfigEditor> {
final codeController = CodeController(language: yaml); //Not HOCON, but close enough
final vScrollController = ScrollController();
final codeController = CodeLineEditingController();

late File openConfig;
late final Timer autoSaveTimer;
Expand All @@ -41,11 +40,12 @@ class _ConfigEditorState extends ConsumerState<ConfigEditor> {
if (!hasChanged) return;

hasChanged = false;
file.writeAsString(codeController.fullText);
file.writeAsString(codeController.text);
}

void readFile(File file) {
codeController.fullText = file.readAsStringSync();
codeController.text = file.readAsStringSync();
// codeController.clearHistory();
openConfig = file;
}

Expand All @@ -55,7 +55,6 @@ class _ConfigEditorState extends ConsumerState<ConfigEditor> {
writeFile(openConfig);
autoSaveTimer.cancel();
codeController.dispose();
vScrollController.dispose();
}

@override
Expand All @@ -64,25 +63,49 @@ class _ConfigEditorState extends ConsumerState<ConfigEditor> {
if (previous != null && next != null) writeFile(previous);
if (next != null) readFile(next);
});
return ColoredBox(
color: Colors.grey.shade900,
child: SingleChildScrollView(
controller: vScrollController,
child: CodeTheme(
data: CodeThemeData(styles: irBlackTheme),
child: CodeField(
gutterStyle: const GutterStyle(
showFoldingHandles: false,
return ScrollbarTheme(
data: Theme.of(context).scrollbarTheme.copyWith(
thumbColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.dragged)) return Colors.white38;
if (states.contains(WidgetState.hovered)) return Colors.white30;
return Colors.white24;
}),
trackColor: WidgetStateProperty.all(Colors.white10),
trackBorderColor: WidgetStateProperty.all(Colors.white12),
),
child: CodeEditor(
indicatorBuilder: (context, editingController, chunkController, notifier) {
return Padding(
padding: const EdgeInsets.only(left: 16),
child: DefaultCodeLineNumber(
notifier: notifier,
controller: editingController,
),
background: Colors.transparent,
onChanged: (_) => hasChanged = true,
textStyle: pixelCode,
controller: codeController,
minLines: null,
maxLines: null,
// expands: true,
);
},
style: CodeEditorStyle(
textColor: Colors.white,
backgroundColor: Colors.grey.shade900,
fontFamily: pixelCode.fontFamily,
fontSize: pixelCode.fontSize,
fontHeight: pixelCode.height,
codeTheme: CodeHighlightTheme(
theme: irBlackTheme,
languages: {
"yaml": CodeHighlightThemeMode(mode: langYaml),
},
),
),
onChanged: (_) => hasChanged = true,
controller: codeController,
wordWrap: false,
sperator: const SizedBox(width: 12),
scrollbarBuilder: (context, child, details) {
return Scrollbar(
controller: details.controller,
child: child,
);
},
),
);
}
Expand Down
120 changes: 24 additions & 96 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
autotrie:
dependency: transitive
description:
name: autotrie
sha256: "55da6faefb53cfcb0abb2f2ca8636123fb40e35286bb57440d2cf467568188f8"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -78,14 +70,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.0"
charcode:
dependency: transitive
description:
name: charcode
sha256: fb98c0f6d12c920a02ee2d998da788bca066ca5f148492b7085ee23372b12306
url: "https://pub.dev"
source: hosted
version: "1.3.1"
checked_yaml:
dependency: transitive
description:
Expand Down Expand Up @@ -182,14 +166,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.6"
equatable:
dependency: transitive
description:
name: equatable
sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2
url: "https://pub.dev"
source: hosted
version: "2.0.5"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -235,22 +211,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_code_editor:
dependency: "direct main"
description:
name: flutter_code_editor
sha256: "505ad56dcc8a7be4b782c8113574571bc4b9723499b0c1f385b3e2c3fae11f5d"
url: "https://pub.dev"
source: hosted
version: "0.3.2"
flutter_highlight:
dependency: "direct main"
description:
name: flutter_highlight
sha256: "7b96333867aa07e122e245c033b8ad622e4e3a42a1a2372cbb098a2541d8782c"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -301,22 +261,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
highlight:
dependency: "direct main"
description:
name: highlight
sha256: "5353a83ffe3e3eca7df0abfb72dcf3fa66cc56b953728e7113ad4ad88497cf21"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
hive:
dependency: transitive
description:
name: hive
sha256: "8dcf6db979d7933da8217edcec84e9df1bdb4e4edc7fc77dbd5aa74356d6d941"
url: "https://pub.dev"
source: hosted
version: "2.2.3"
hotreloader:
dependency: transitive
description:
Expand All @@ -325,22 +269,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.2.0"
http:
isolate_contactor:
dependency: transitive
description:
name: http
sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
name: isolate_contactor
sha256: "6ba8434ceb58238a1389d6365111a3efe7baa1c68a66f4db6d63d351cf6c3a0f"
url: "https://pub.dev"
source: hosted
version: "1.2.2"
http_parser:
version: "4.1.0"
isolate_manager:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
name: isolate_manager
sha256: "22ed0c25f80ec3b5f21e3a55d060f4650afff33f27c2dff34c0f9409d5759ae5"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
version: "4.1.5+1"
json_annotation:
dependency: transitive
description:
Expand Down Expand Up @@ -373,14 +317,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.1"
linked_scroll_controller:
dependency: transitive
description:
name: linked_scroll_controller
sha256: e6020062bcf4ffc907ee7fd090fa971e65d8dfaac3c62baf601a3ced0b37986a
url: "https://pub.dev"
source: hosted
version: "0.2.0"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -429,14 +365,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.15.0"
mocktail:
dependency: transitive
description:
name: mocktail
sha256: "890df3f9688106f25755f26b1c60589a92b3ab91a22b8b224947ad041bf172d8"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -509,6 +437,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.0"
re_editor:
dependency: "direct main"
description:
name: re_editor
sha256: abae2b015799c936b9f9b68888e2c55007dd159b4654a85da22ce1af84efbd17
url: "https://pub.dev"
source: hosted
version: "0.3.1"
re_highlight:
dependency: "direct main"
description:
name: re_highlight
sha256: "6c4ac3f76f939fb7ca9df013df98526634e17d8f7460e028bd23a035870024f2"
url: "https://pub.dev"
source: hosted
version: "0.0.3"
riverpod:
dependency: transitive
description:
Expand Down Expand Up @@ -541,14 +485,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.28.0"
scrollable_positioned_list:
dependency: transitive
description:
name: scrollable_positioned_list
sha256: "1b54d5f1329a1e263269abc9e2543d90806131aa14fe7c6062a8054d57249287"
url: "https://pub.dev"
source: hosted
version: "0.3.8"
shared_preferences:
dependency: "direct main"
description:
Expand Down Expand Up @@ -682,14 +618,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.2"
tuple:
dependency: transitive
description:
name: tuple
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
url: "https://pub.dev"
source: hosted
version: "2.0.2"
typed_data:
dependency: transitive
description:
Expand Down
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ dependencies:
file_picker: ^8.1.2
flutter:
sdk: flutter
flutter_code_editor: ^0.3.2
flutter_highlight: ^0.7.0
flutter_riverpod: ^2.5.1
highlight: ^0.7.0
path: ^1.9.0
re_editor: ^0.3.1
re_highlight: ^0.0.3
rxdart: ^0.28.0
shared_preferences: ^2.3.2
url_launcher: ^6.3.0
Expand Down

0 comments on commit cd96faf

Please sign in to comment.