Fix Border Instability

This commit is contained in:
Sarah Jamie Lewis 2022-10-08 21:29:35 -07:00
parent 01eb1e24b1
commit 96e4f0e32c
4 changed files with 17 additions and 18 deletions

View File

@ -89,11 +89,9 @@ class CursorProvider extends ChangeNotifier {
clearSelection();
}
publishCursor(backingLines);
notifyListeners();
} else if (inMouseSelection == false) {
clearSelection();
publishCursor(backingLines);
notifyListeners();
}
inMouseSelection = true;
}
@ -107,11 +105,9 @@ class CursorProvider extends ChangeNotifier {
clearSelection();
}
publishCursor(backingLines);
notifyListeners();
} else if (inMouseSelection == false) {
clearSelection();
publishCursor(backingLines);
notifyListeners();
}
inMouseSelection = true;
}

View File

@ -37,6 +37,7 @@ class LineInfo extends ChangeNotifier {
return LayoutBuilder(
builder: (context, constraints) {
var highlightedLine = RichText(
text: TextSpan(
children: spans,
@ -48,7 +49,7 @@ class LineInfo extends ChangeNotifier {
var charWidth = (fontSize / 2.0);
var lineHeight = (fontSize * 1.2);
var usableSize = (constraints.maxWidth - gutterWidth - rightMargin - leftMargin);
var usableSize = (constraints.maxWidth.floorToDouble() - gutterWidth - rightMargin - leftMargin).floorToDouble();
var sidebarContent = List<Widget>.empty(growable: true);
sidebarContent.add(Text('$lineNumber'.padLeft(5), style: gutterStyle));
@ -75,7 +76,7 @@ class LineInfo extends ChangeNotifier {
decoration: BoxDecoration(
color: backgroundStyle.backgroundColor,
),
width: constraints.maxWidth - rightMargin - gutterWidth - leftMargin,
width: usableSize,
height: idealHeight,
child: highlightedLine,
);
@ -84,15 +85,16 @@ class LineInfo extends ChangeNotifier {
if (cursorStart != null) {
var maxCharsBeforeWrapping = (usableSize / charWidth).floorToDouble();
var cursorPosTop = (cursorStart! / maxCharsBeforeWrapping).floorToDouble() * lineHeight;
var cursorPosLeft = ((cursorStart! % maxCharsBeforeWrapping) * charWidth) - charWidth / 2.0;
var cursorPosTop = ((cursorStart! / maxCharsBeforeWrapping).floorToDouble() * lineHeight).roundToDouble();
var cursorPosLeft = max(0, (((cursorStart! % maxCharsBeforeWrapping) * charWidth) - charWidth / 2.0).roundToDouble());
TextStyle cursorStyle = TextStyle(fontFamily: 'Iosevka', fontSize: fontSize, color: foreground, backgroundColor: Colors.transparent, letterSpacing: -2.0);
var cursorPos =
Positioned(top: cursorPosTop.toDouble(), left: leftMargin + cursorPosLeft.toDouble(), child: FadeTransition(opacity: animationController, child: Text("|", style: cursorStyle)));
var cursorPos = Positioned(top: cursorPosTop.toDouble(), left: leftMargin + cursorPosLeft.toDouble(), child: FadeTransition(opacity: animationController, child: Text("|", style: cursorStyle)));
stackElements.add(cursorPos);
}
var cursorOverlay = Stack(children: stackElements);
print("rebuilding line $lineNumber $idealHeight");
// print("$charWidth $lineHeight $usableSize $idealHeight ${constraints.maxWidth}");
return Listener(
onPointerDown: (event) {
@ -135,23 +137,22 @@ class LineInfo extends ChangeNotifier {
}
},
onExit: (event) {
notifyListeners();
},
child: Container(
color: backgroundStyle.backgroundColor,
padding: EdgeInsets.zero,
margin: EdgeInsets.zero,
height: idealHeight,
width: constraints.maxWidth,
width: (usableSize + gutterWidth + rightMargin + leftMargin).floorToDouble(),
child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
Container(
padding: EdgeInsets.zero,
decoration: BoxDecoration(color: sidebarAlt, border: Border(right: BorderSide(width: 1, color: border))),
width: gutterWidth - 1,
decoration: BoxDecoration(color: sidebarAlt),
width: (gutterWidth - 2).floorToDouble(),
height: idealHeight,
margin: EdgeInsets.only(right: 1, top: 0, bottom: 0, left: 0),
alignment: Alignment.centerLeft,
child: Flex(direction: Axis.horizontal, mainAxisAlignment: MainAxisAlignment.start, children: sidebarContent)),
margin: EdgeInsets.only(right: 1, top: 0, bottom: 0, left: 0),
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: sidebarContent)),
cursorOverlay,
]))));
},

View File

@ -50,7 +50,7 @@ class _SarahDownApp extends State<SarahDownApp> {
Widget build(BuildContext context) {
return Material(
color: sidebarAlt,
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,

View File

@ -79,12 +79,14 @@ class _View extends State<View> with SingleTickerProviderStateMixin {
),
);
} else {
return ScrollablePositionedList.builder(
physics: const AlwaysScrollableScrollPhysics(),
itemScrollController: doc.scrollController,
itemCount: doc.lines(),
padding: EdgeInsets.zero,
shrinkWrap: true,
minCacheExtent: 10,
addRepaintBoundaries: true,
itemBuilder: (BuildContext bcontext, int index) {
return ChangeNotifierProvider.value(
value: doc.backingLines[index],