Skip to content
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
4 changes: 4 additions & 0 deletions lib/src/single_line_comments/parser/single_line_comments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'package:highlight/highlight_core.dart';
import 'package:highlight/languages/dart.dart';
import 'package:highlight/languages/go.dart';
import 'package:highlight/languages/java.dart';
import 'package:highlight/languages/javascript.dart';
import 'package:highlight/languages/php.dart';
import 'package:highlight/languages/python.dart';
import 'package:highlight/languages/scala.dart';
import 'package:highlight/languages/typescript.dart';
import 'package:highlight/languages/vhdl.dart';

class SingleLineComments {
Expand All @@ -18,6 +20,8 @@ class SingleLineComments {
python: [_hash],
scala: [_slashes],
vhdl: [_hyphenMinuses],
typescript: [_slashes],
javascript: [_slashes],
};

static const _slashes = '//';
Expand Down
52 changes: 52 additions & 0 deletions test/src/code/code_read_only_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter_code_editor/src/named_sections/parsers/brackets_start_en
import 'package:flutter_test/flutter_test.dart';
import 'package:highlight/languages/angelscript.dart';
import 'package:highlight/languages/java.dart';
import 'package:highlight/languages/javascript.dart';
import 'package:highlight/languages/typescript.dart';

final _language = java;

Expand Down Expand Up @@ -102,5 +104,55 @@ public class MyClass {
expected,
);
});

test('Lines in read-only sections are read-only for JS/TS Language', () {
const text = '''
export class MyTypeScriptClass {
run() { // [START section1]
}
// [END section1]
// [START section2]
method() {
}
// [END section2]
}
''';
const expected = [
false,
true,
true,
true,
false,
false,
false,
false,
false,
false,
];

final codeTypescript = Code(
text: text,
namedSectionParser: const BracketsStartEndNamedSectionParser(),
readOnlySectionNames: {'section1', 'nonexistent'},
language: typescript,
);

final codeJavascript = Code(
text: text,
namedSectionParser: const BracketsStartEndNamedSectionParser(),
readOnlySectionNames: {'section1', 'nonexistent'},
language: javascript,
);

expect(
codeTypescript.lines.lines.map((line) => line.isReadOnly),
expected,
);

expect(
codeJavascript.lines.lines.map((line) => line.isReadOnly),
expected,
);
});
});
}