mirror of
https://github.com/venera-app/venera.git
synced 2025-09-28 16:27:25 +00:00
improve editor
This commit is contained in:
@@ -55,25 +55,27 @@ class _CodeEditorState extends State<CodeEditor> {
|
|||||||
|
|
||||||
Widget buildLineNumbers() {
|
Widget buildLineNumbers() {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: 14 * 1.5,
|
width: 32,
|
||||||
child: Column(children: [
|
child: Column(
|
||||||
for (var i = 1; i <= lineCount; i++)
|
children: [
|
||||||
SizedBox(
|
for (var i = 1; i <= lineCount; i++)
|
||||||
height: 14 * 1.5,
|
SizedBox(
|
||||||
child: Center(
|
height: 14 * 1.5,
|
||||||
child: Text(
|
child: Center(
|
||||||
i.toString(),
|
child: Text(
|
||||||
style: TextStyle(
|
i.toString(),
|
||||||
color: context.colorScheme.outline,
|
style: TextStyle(
|
||||||
fontSize: 14,
|
color: context.colorScheme.outline,
|
||||||
height: 1.0,
|
fontSize: 13,
|
||||||
fontFamily: 'consolas',
|
height: 1.0,
|
||||||
fontFamilyFallback: ['Courier New', 'monospace'],
|
fontFamily: 'Consolas',
|
||||||
|
fontFamilyFallback: ['Courier New', 'monospace'],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
).paddingBottom(6),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],),
|
),
|
||||||
).paddingVertical(8);
|
).paddingVertical(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,52 +89,60 @@ class _CodeEditorState extends State<CodeEditor> {
|
|||||||
if (value.connectionState == ConnectionState.waiting) {
|
if (value.connectionState == ConnectionState.waiting) {
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
return Scrollbar(
|
return GestureDetector(
|
||||||
thumbVisibility: true,
|
onTap: () {
|
||||||
controller: verticalScrollController,
|
_controller.selection = TextSelection.collapsed(
|
||||||
notificationPredicate: (notif) => notif.metrics.axis == Axis.vertical,
|
offset: _controller.text.length,
|
||||||
|
);
|
||||||
|
_focusNode.requestFocus();
|
||||||
|
},
|
||||||
child: Scrollbar(
|
child: Scrollbar(
|
||||||
thumbVisibility: true,
|
thumbVisibility: true,
|
||||||
controller: horizontalScrollController,
|
controller: verticalScrollController,
|
||||||
notificationPredicate: (notif) =>
|
notificationPredicate: (notif) =>
|
||||||
notif.metrics.axis == Axis.horizontal,
|
notif.metrics.axis == Axis.vertical,
|
||||||
child: SizedBox.expand(
|
child: Scrollbar(
|
||||||
child: ScrollConfiguration(
|
thumbVisibility: true,
|
||||||
behavior: _CustomScrollBehavior(),
|
controller: horizontalScrollController,
|
||||||
child: SingleChildScrollView(
|
notificationPredicate: (notif) =>
|
||||||
scrollDirection: Axis.horizontal,
|
notif.metrics.axis == Axis.horizontal,
|
||||||
controller: horizontalScrollController,
|
child: SizedBox.expand(
|
||||||
child: Row(
|
child: ScrollConfiguration(
|
||||||
children: [
|
behavior: _CustomScrollBehavior(),
|
||||||
buildLineNumbers(),
|
child: SingleChildScrollView(
|
||||||
IntrinsicWidth(
|
scrollDirection: Axis.horizontal,
|
||||||
stepWidth: 50,
|
controller: horizontalScrollController,
|
||||||
child: TextField(
|
child: SingleChildScrollView(
|
||||||
controller: _controller,
|
scrollDirection: Axis.vertical,
|
||||||
focusNode: _focusNode,
|
controller: verticalScrollController,
|
||||||
maxLines: null,
|
child: Row(
|
||||||
expands: true,
|
children: [
|
||||||
cursorHeight: 1.5 * 14,
|
buildLineNumbers(),
|
||||||
style: TextStyle(
|
IntrinsicWidth(
|
||||||
height: 1.5,
|
stepWidth: 100,
|
||||||
fontSize: 14
|
child: TextField(
|
||||||
|
controller: _controller,
|
||||||
|
focusNode: _focusNode,
|
||||||
|
maxLines: null,
|
||||||
|
cursorHeight: 1.5 * 14,
|
||||||
|
style: TextStyle(height: 1.5, fontSize: 14),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: InputBorder.none,
|
||||||
|
contentPadding: EdgeInsets.all(8),
|
||||||
|
),
|
||||||
|
onChanged: (value) {
|
||||||
|
widget.onChanged?.call(value);
|
||||||
|
if (lineCount != calculateLineCount(value)) {
|
||||||
|
setState(() {
|
||||||
|
lineCount = calculateLineCount(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
decoration: InputDecoration(
|
],
|
||||||
border: InputBorder.none,
|
|
||||||
contentPadding: EdgeInsets.all(8),
|
|
||||||
),
|
|
||||||
onChanged: (value) {
|
|
||||||
widget.onChanged?.call(value);
|
|
||||||
if (lineCount != calculateLineCount(value)) {
|
|
||||||
setState(() {
|
|
||||||
lineCount = calculateLineCount(value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scrollController: verticalScrollController,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -176,8 +186,8 @@ class _CodeTextEditingController extends TextEditingController {
|
|||||||
style = TextStyle(
|
style = TextStyle(
|
||||||
height: 1.5,
|
height: 1.5,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontFamily: 'consolas',
|
fontFamily: 'Consolas',
|
||||||
fontFamilyFallback: ['Courier New', 'monospace'],
|
fontFamilyFallback: ['Courier New', 'Roboto Mono', 'monospace'],
|
||||||
);
|
);
|
||||||
|
|
||||||
return mergeTextStyle(result, style);
|
return mergeTextStyle(result, style);
|
||||||
@@ -186,7 +196,10 @@ class _CodeTextEditingController extends TextEditingController {
|
|||||||
TextSpan mergeTextStyle(TextSpan span, TextStyle style) {
|
TextSpan mergeTextStyle(TextSpan span, TextStyle style) {
|
||||||
var result = TextSpan(
|
var result = TextSpan(
|
||||||
style: style.merge(span.style),
|
style: style.merge(span.style),
|
||||||
children: span.children?.whereType().map((e) => mergeTextStyle(e, style)).toList(),
|
children: span.children
|
||||||
|
?.whereType()
|
||||||
|
.map((e) => mergeTextStyle(e, style))
|
||||||
|
.toList(),
|
||||||
text: span.text,
|
text: span.text,
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user