支持上传脚本

This commit is contained in:
jyuesong
2022-06-16 14:37:47 +08:00
parent 2005083d2e
commit 1298dba590
58 changed files with 1702 additions and 774 deletions

View File

@@ -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);
},
),
);