Skip to content
Open
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
7 changes: 4 additions & 3 deletions lib/controller/custom_text_controller.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_highlight/themes/atom-one-dark-reasonable.dart';
import 'package:highlight/highlight.dart' show highlight, Node;
import 'package:phone_ide/models/editor_language.dart';

class TextEditingControllerIDE extends TextEditingController {
TextEditingControllerIDE({Key? key, this.font, this.language = 'HTML'});
TextEditingControllerIDE({Key? key, this.font, this.language = EditorLanguage.html});

String language;
EditorLanguage language;
final TextStyle? font;

List<TextSpan> _convert(List<Node> nodes) {
Expand Down Expand Up @@ -56,7 +57,7 @@ class TextEditingControllerIDE extends TextEditingController {
TextStyle? style,
required bool withComposing,
}) {
var nodes = highlight.parse(text, language: language).nodes!;
var nodes = highlight.parse(text, language: language.identifier).nodes!;
return TextSpan(style: style, children: _convert(nodes));
}
}
3 changes: 2 additions & 1 deletion lib/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
import 'package:phone_ide/controller/custom_text_controller.dart';
import 'package:phone_ide/editor/editor_options.dart';
import 'package:phone_ide/editor/linebar.dart';
import 'package:phone_ide/models/editor_language.dart';
import 'package:phone_ide/models/textfield_data.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand Down Expand Up @@ -35,7 +36,7 @@ class Editor extends StatefulWidget {
final String defaultValue;

// The starting language of the editor
final String defaultLanguage;
final EditorLanguage defaultLanguage;

// The path e.g. file name "index.html"
final String path;
Expand Down
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:phone_ide/models/editor_language.dart';
import 'package:phone_ide/phone_ide.dart';

void main() {
Expand Down Expand Up @@ -28,7 +29,7 @@ class EditorView extends StatefulWidget {

class EditorViewState extends State<EditorView> {
Editor editor = Editor(
defaultLanguage: 'html',
defaultLanguage: EditorLanguage.html,
defaultValue: '<h1> Hello World</h1>',
path: 'index.html',
options: EditorOptions(),
Expand Down
73 changes: 73 additions & 0 deletions lib/models/editor_language.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/// Supported programming languages for syntax highlighting in the editor.
///
/// This enum represents all languages supported by the highlight.js package
/// used in the phone_ide editor. Each enum value corresponds to a language
/// identifier that can be used for syntax highlighting.
enum EditorLanguage {
// Web Development
html('html'),
css('css'),
javascript('javascript'),
typescript('typescript'),
json('json'),
xml('xml'),

// Markup & Documentation
markdown('markdown'),
yaml('yaml'),

// Mobile Development
dart('dart'),
kotlin('kotlin'),
swift('swift'),

// Systems Programming
c('c'),
cpp('cpp'),
rust('rust'),
go('go'),

// JVM Languages
java('java'),
scala('scala'),
groovy('groovy'),

// Functional Programming
haskell('haskell'),
fsharp('fsharp'),
clojure('clojure'),
elixir('elixir'),
erlang('erlang'),

// Scripting Languages
python('python'),
ruby('ruby'),
php('php'),
perl('perl'),
lua('lua'),

// .NET Languages
csharp('csharp'),

// Shell & Config
bash('bash'),
shell('shell'),
powershell('powershell'),
dockerfile('dockerfile'),

// Database
sql('sql'),
graphql('graphql'),

// Other Popular Languages
r('r'),
coffeescript('coffeescript');

const EditorLanguage(this.identifier);

/// The language identifier string used by highlight.js
final String identifier;

@override
String toString() => identifier;
}
1 change: 1 addition & 0 deletions lib/phone_ide.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ library phone_ide;

export './editor/editor.dart';
export './editor/editor_options.dart';
export './models/editor_language.dart';