mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
支持上传脚本
This commit is contained in:
@@ -64,7 +64,8 @@ class CodeController extends TextEditingController {
|
||||
this.onChange,
|
||||
}) : super(text: text) {
|
||||
// PatternMap
|
||||
if (language != null && theme == null) throw Exception("A theme must be provided for language parsing");
|
||||
if (language != null && theme == null)
|
||||
throw Exception("A theme must be provided for language parsing");
|
||||
// Register language
|
||||
if (language != null) {
|
||||
highlight.registerLanguage(languageId, language!);
|
||||
@@ -152,7 +153,8 @@ class CodeController extends TextEditingController {
|
||||
const _chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
|
||||
final _rnd = Random();
|
||||
return String.fromCharCodes(
|
||||
Iterable.generate(10, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))),
|
||||
Iterable.generate(
|
||||
10, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -178,8 +180,11 @@ class CodeController extends TextEditingController {
|
||||
}
|
||||
}
|
||||
// Now fix the textfield for web
|
||||
if (_webSpaceFix) newValue = newValue.copyWith(text: _spacesToMiddleDots(newValue.text));
|
||||
if (onChange != null) onChange!(_webSpaceFix ? _middleDotsToSpaces(newValue.text) : newValue.text);
|
||||
if (_webSpaceFix)
|
||||
newValue = newValue.copyWith(text: _spacesToMiddleDots(newValue.text));
|
||||
if (onChange != null)
|
||||
onChange!(
|
||||
_webSpaceFix ? _middleDotsToSpaces(newValue.text) : newValue.text);
|
||||
super.value = newValue;
|
||||
}
|
||||
|
||||
@@ -190,7 +195,11 @@ class CodeController extends TextEditingController {
|
||||
onMatch: (Match m) {
|
||||
if (styleList.isEmpty) return '';
|
||||
int idx;
|
||||
for (idx = 1; idx < m.groupCount && idx <= styleList.length && m.group(idx) == null; 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],
|
||||
@@ -221,7 +230,8 @@ class CodeController extends TextEditingController {
|
||||
if (val != null) {
|
||||
if (_webSpaceFix) val = _spacesToMiddleDots(val);
|
||||
var child = TextSpan(text: val, style: theme?[node.className]);
|
||||
if (styleRegExp != null) child = _processPatterns(val, theme?[node.className]);
|
||||
if (styleRegExp != null)
|
||||
child = _processPatterns(val, theme?[node.className]);
|
||||
currentSpans.add(child);
|
||||
} else if (nodeChildren != null) {
|
||||
List<TextSpan> tmp = [];
|
||||
@@ -245,7 +255,8 @@ class CodeController extends TextEditingController {
|
||||
}
|
||||
|
||||
@override
|
||||
TextSpan buildTextSpan({required BuildContext context, TextStyle? style, bool? withComposing}) {
|
||||
TextSpan buildTextSpan(
|
||||
{required BuildContext context, TextStyle? style, bool? withComposing}) {
|
||||
// Retrieve pattern regexp
|
||||
final patternList = <String>[];
|
||||
if (_webSpaceFix) {
|
||||
|
||||
@@ -12,14 +12,16 @@ class LineNumberController extends TextEditingController {
|
||||
LineNumberController(this.lineNumberBuilder);
|
||||
|
||||
@override
|
||||
TextSpan buildTextSpan({required BuildContext context, TextStyle? style, bool? withComposing}) {
|
||||
TextSpan buildTextSpan(
|
||||
{required BuildContext context, TextStyle? style, bool? withComposing}) {
|
||||
final children = <TextSpan>[];
|
||||
final list = text.split("\n");
|
||||
for (int k = 0; k < list.length; k++) {
|
||||
final el = list[k];
|
||||
final number = int.parse(el);
|
||||
var textSpan = TextSpan(text: el, style: style);
|
||||
if (lineNumberBuilder != null) textSpan = lineNumberBuilder!(number, style);
|
||||
if (lineNumberBuilder != null)
|
||||
textSpan = lineNumberBuilder!(number, style);
|
||||
children.add(textSpan);
|
||||
if (k < list.length - 1) children.add(TextSpan(text: "\n"));
|
||||
}
|
||||
@@ -199,7 +201,8 @@ class CodeFieldState extends State<CodeField> {
|
||||
}
|
||||
|
||||
// Wrap the codeField in a horizontal scrollView
|
||||
Widget _wrapInScrollView(Widget codeField, TextStyle textStyle, double minWidth) {
|
||||
Widget _wrapInScrollView(
|
||||
Widget codeField, TextStyle textStyle, double minWidth) {
|
||||
final leftPad = widget.lineNumberStyle.margin / 2;
|
||||
final intrinsic = IntrinsicWidth(
|
||||
child: Column(
|
||||
@@ -239,7 +242,8 @@ class CodeFieldState extends State<CodeField> {
|
||||
final defaultText = Colors.grey.shade200;
|
||||
|
||||
final theme = widget.controller.theme;
|
||||
Color? backgroundCol = widget.background ?? theme?[ROOT_KEY]?.backgroundColor ?? defaultBg;
|
||||
Color? backgroundCol =
|
||||
widget.background ?? theme?[ROOT_KEY]?.backgroundColor ?? defaultBg;
|
||||
if (widget.decoration != null) {
|
||||
backgroundCol = null;
|
||||
}
|
||||
@@ -249,14 +253,16 @@ class CodeFieldState extends State<CodeField> {
|
||||
fontSize: textStyle.fontSize ?? 16.0,
|
||||
);
|
||||
TextStyle numberTextStyle = widget.lineNumberStyle.textStyle ?? TextStyle();
|
||||
final numberColor = (theme?[ROOT_KEY]?.color ?? defaultText).withOpacity(0.7);
|
||||
final numberColor =
|
||||
(theme?[ROOT_KEY]?.color ?? defaultText).withOpacity(0.7);
|
||||
// Copy important attributes
|
||||
numberTextStyle = numberTextStyle.copyWith(
|
||||
color: numberTextStyle.color ?? numberColor,
|
||||
fontSize: textStyle.fontSize,
|
||||
fontFamily: textStyle.fontFamily,
|
||||
);
|
||||
final cursorColor = widget.cursorColor ?? theme?[ROOT_KEY]?.color ?? defaultText;
|
||||
final cursorColor =
|
||||
widget.cursorColor ?? theme?[ROOT_KEY]?.color ?? defaultText;
|
||||
|
||||
final lineNumberCol = TextField(
|
||||
smartQuotesType: widget.smartQuotesType,
|
||||
@@ -315,7 +321,9 @@ class CodeFieldState extends State<CodeField> {
|
||||
child: LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
// Control horizontal scrolling
|
||||
return widget.wrap ? codeField : _wrapInScrollView(codeField, textStyle, constraints.maxWidth);
|
||||
return widget.wrap
|
||||
? codeField
|
||||
: _wrapInScrollView(codeField, textStyle, constraints.maxWidth);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -19,7 +19,8 @@ abstract class CodeModifier {
|
||||
);
|
||||
}
|
||||
|
||||
TextEditingValue? updateString(String text, TextSelection sel, EditorParams params);
|
||||
TextEditingValue? updateString(
|
||||
String text, TextSelection sel, EditorParams params);
|
||||
}
|
||||
|
||||
class IntendModifier extends CodeModifier {
|
||||
@@ -30,7 +31,8 @@ class IntendModifier extends CodeModifier {
|
||||
}) : super('\n');
|
||||
|
||||
@override
|
||||
TextEditingValue? updateString(String text, TextSelection sel, EditorParams params) {
|
||||
TextEditingValue? updateString(
|
||||
String text, TextSelection sel, EditorParams params) {
|
||||
var spacesCount = 0;
|
||||
var braceCount = 0;
|
||||
for (var k = min(sel.start, text.length) - 1; k >= 0; k--) {
|
||||
@@ -53,7 +55,8 @@ class CloseBlockModifier extends CodeModifier {
|
||||
const CloseBlockModifier() : super('}');
|
||||
|
||||
@override
|
||||
TextEditingValue? updateString(String text, TextSelection sel, EditorParams params) {
|
||||
TextEditingValue? updateString(
|
||||
String text, TextSelection sel, EditorParams params) {
|
||||
int spaceCount = 0;
|
||||
for (var k = min(sel.start, text.length) - 1; k >= 0; k--) {
|
||||
if (text[k] == "\n") break;
|
||||
@@ -63,7 +66,8 @@ class CloseBlockModifier extends CodeModifier {
|
||||
}
|
||||
spaceCount += 1;
|
||||
}
|
||||
if (spaceCount >= params.tabSpaces) return replace(text, sel.start - params.tabSpaces, sel.end, "}");
|
||||
if (spaceCount >= params.tabSpaces)
|
||||
return replace(text, sel.start - params.tabSpaces, sel.end, "}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -72,7 +76,8 @@ class TabModifier extends CodeModifier {
|
||||
const TabModifier() : super('\t');
|
||||
|
||||
@override
|
||||
TextEditingValue? updateString(String text, TextSelection sel, EditorParams params) {
|
||||
TextEditingValue? updateString(
|
||||
String text, TextSelection sel, EditorParams params) {
|
||||
final tmp = replace(text, sel.start, sel.end, " " * params.tabSpaces);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user