From 96e4f0e32c448854dad248a09ab089ba3b874f4e Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Sat, 8 Oct 2022 21:29:35 -0700 Subject: [PATCH] Fix Border Instability --- lib/cursor_provider.dart | 4 ---- lib/line_info.dart | 25 +++++++++++++------------ lib/main.dart | 2 +- lib/view.dart | 4 +++- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/cursor_provider.dart b/lib/cursor_provider.dart index 68d55e4..e211e8c 100644 --- a/lib/cursor_provider.dart +++ b/lib/cursor_provider.dart @@ -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; } diff --git a/lib/line_info.dart b/lib/line_info.dart index 0d93892..c395311 100644 --- a/lib/line_info.dart +++ b/lib/line_info.dart @@ -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.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, ])))); }, diff --git a/lib/main.dart b/lib/main.dart index 8a26250..e8e7a47 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -50,7 +50,7 @@ class _SarahDownApp extends State { 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, diff --git a/lib/view.dart b/lib/view.dart index 6ef9b03..754601f 100644 --- a/lib/view.dart +++ b/lib/view.dart @@ -79,12 +79,14 @@ class _View extends State 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],