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
27 changes: 15 additions & 12 deletions lib/src/code_field/code_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class _CodeFieldState extends State<CodeField> {

FocusNode? _focusNode;
String? lines;
String longestLine = '';
var longestLine = '';
Size? windowSize;
late TextStyle textStyle;
Color? _backgroundCol;
Expand Down Expand Up @@ -390,9 +390,7 @@ class _CodeFieldState extends State<CodeField> {
);

return SingleChildScrollView(
padding: EdgeInsets.only(
right: widget.padding.right,
),
padding: EdgeInsets.zero,
scrollDirection: Axis.horizontal,
controller: _horizontalCodeScroll,
child: intrinsic,
Expand Down Expand Up @@ -421,22 +419,29 @@ class _CodeFieldState extends State<CodeField> {
);

textStyle = defaultTextStyle.merge(widget.textStyle);
final lineStrutStyle = StrutStyle.fromTextStyle(
textStyle,
forceStrutHeight: true,
);
final contentPadding = const EdgeInsets.only(left: 8).add(widget.padding);

final codeField = TextField(
focusNode: _focusNode,
scrollPadding: widget.padding,
scrollPadding: EdgeInsets.zero,
style: textStyle,
smartDashesType: widget.smartDashesType,
smartQuotesType: widget.smartQuotesType,
controller: widget.controller,
strutStyle: lineStrutStyle,
textAlignVertical: TextAlignVertical.top,
undoController: widget.undoController,
minLines: widget.minLines,
maxLines: widget.maxLines,
expands: widget.expands,
scrollController: _codeScroll,
decoration: const InputDecoration(
isCollapsed: true,
contentPadding: EdgeInsets.symmetric(vertical: 16),
contentPadding: EdgeInsets.zero,
disabledBorder: InputBorder.none,
border: InputBorder.none,
focusedBorder: InputBorder.none,
Expand Down Expand Up @@ -468,7 +473,7 @@ class _CodeFieldState extends State<CodeField> {
decoration: widget.decoration,
color: _backgroundCol,
key: _codeFieldKey,
padding: const EdgeInsets.only(left: 8),
padding: contentPadding,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand All @@ -490,6 +495,7 @@ class _CodeFieldState extends State<CodeField> {
color: lineNumberColor,
fontFamily: textStyle.fontFamily,
fontSize: lineNumberSize,
height: textStyle.height,
);

final gutterStyle = widget.gutterStyle.copyWith(
Expand Down Expand Up @@ -540,7 +546,7 @@ class _CodeFieldState extends State<CodeField> {
}

double _getCaretHeight(TextPainter textPainter) {
final double? caretFullHeight = textPainter.getFullHeightForCaret(
final double caretFullHeight = textPainter.getFullHeightForCaret(
widget.controller.selection.base,
Rect.zero,
);
Expand All @@ -550,7 +556,6 @@ class _CodeFieldState extends State<CodeField> {
double _getPopupLeftOffset(TextPainter textPainter) {
return max(
_getCaretOffset(textPainter).dx +
widget.padding.left -
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

horizontal scroll offset sign looks inverted; popup should stay anchored to caret while scrolling, so this likely needs subtracting scroll offset (not adding).

_horizontalCodeScroll!.offset +
(_editorOffset?.dx ?? 0),
0,
Expand All @@ -561,8 +566,6 @@ class _CodeFieldState extends State<CodeField> {
return max(
_getCaretOffset(textPainter).dy +
caretHeight +
16 +
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vertical scroll offset sign also appears inverted; with current math popup will drift when editor scrolls.

widget.padding.top -
_codeScroll!.offset +
(_editorOffset?.dy ?? 0),
0,
Expand Down Expand Up @@ -603,7 +606,7 @@ class _CodeFieldState extends State<CodeField> {

OverlayEntry _buildSearchOverlay() {
final colorScheme = Theme.of(context).colorScheme;
final borderColor = _getTextColorFromTheme() ?? colorScheme.onBackground;
final borderColor = _getTextColorFromTheme() ?? colorScheme.onSurface;
return OverlayEntry(
builder: (context) {
return Positioned(
Expand Down
23 changes: 14 additions & 9 deletions lib/src/gutter/gutter.dart
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add widget tests covering (1) line-number/text baseline alignment with non-default TextStyle.height, and (2) autocomplete popup position after horizontal/vertical scroll, since this PR changes both text metrics and popup offset math.

Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ class GutterWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: SingleChildScrollView(
controller: scrollController,
child: AnimatedBuilder(
animation: codeController,
builder: _buildOnChange,
),
return SingleChildScrollView(
controller: scrollController,
child: AnimatedBuilder(
animation: codeController,
builder: _buildOnChange,
),
);
}
Expand Down Expand Up @@ -90,6 +87,13 @@ class GutterWidget extends StatelessWidget {

void _fillLineNumbers(List<TableRow> tableRows) {
final code = codeController.code;
final numberStyle = style.textStyle;
final numberStrutStyle = numberStyle == null
? null
: StrutStyle.fromTextStyle(
numberStyle,
forceStrutHeight: true,
);

for (final i in code.hiddenLineRanges.visibleLineNumbers) {
final lineIndex = _lineIndexToTableRowIndex(i);
Expand All @@ -100,7 +104,8 @@ class GutterWidget extends StatelessWidget {

tableRows[lineIndex].children![_lineNumberColumn] = Text(
style.showLineNumbers ? '${i + 1}' : ' ',
style: style.textStyle,
style: numberStyle,
strutStyle: numberStrutStyle,
textAlign: style.textAlign,
);
}
Expand Down