|
@@ -99,29 +99,18 @@ class _TerminalViewState extends State<TerminalView> {
|
|
|
|
|
|
|
|
late CellSize _cellSize;
|
|
late CellSize _cellSize;
|
|
|
|
|
|
|
|
|
|
+ /// Scroll position from the terminal. Not null if terminal scroll extent has
|
|
|
|
|
+ /// been updated and needs to be syncronized to flutter side.
|
|
|
|
|
+ double? _terminalScrollExtent;
|
|
|
|
|
+
|
|
|
void onTerminalChange() {
|
|
void onTerminalChange() {
|
|
|
if (!mounted) {
|
|
if (!mounted) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- final currentScrollExtent =
|
|
|
|
|
|
|
+ _terminalScrollExtent =
|
|
|
_cellSize.cellHeight * widget.terminal.buffer.scrollOffsetFromTop;
|
|
_cellSize.cellHeight * widget.terminal.buffer.scrollOffsetFromTop;
|
|
|
|
|
|
|
|
- final maxScrollExtent = widget.scrollController.position.maxScrollExtent;
|
|
|
|
|
-
|
|
|
|
|
- if (currentScrollExtent > maxScrollExtent) {
|
|
|
|
|
- /// Ensure [maxScrollExtent] is larger than [currentScrollExtent] so
|
|
|
|
|
- /// [currentScrollExtent] won't be limited.
|
|
|
|
|
- ///
|
|
|
|
|
- /// Calling [applyContentDimensions] has unnecessary cost, and the most
|
|
|
|
|
- /// ideal way is to set [scrollController.position._maxScrollExtend]
|
|
|
|
|
- /// directly, however this requires modifying flutter code.
|
|
|
|
|
- widget.scrollController.position
|
|
|
|
|
- .applyContentDimensions(0.0, currentScrollExtent);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- widget.scrollController.position.correctPixels(currentScrollExtent);
|
|
|
|
|
-
|
|
|
|
|
setState(() {});
|
|
setState(() {});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -173,7 +162,7 @@ class _TerminalViewState extends State<TerminalView> {
|
|
|
child: MouseRegion(
|
|
child: MouseRegion(
|
|
|
cursor: SystemMouseCursors.text,
|
|
cursor: SystemMouseCursors.text,
|
|
|
child: LayoutBuilder(builder: (context, constraints) {
|
|
child: LayoutBuilder(builder: (context, constraints) {
|
|
|
- onResize(constraints.maxWidth, constraints.maxHeight);
|
|
|
|
|
|
|
+ onSize(constraints.maxWidth, constraints.maxHeight);
|
|
|
// use flutter's Scrollable to manage scrolling to better integrate
|
|
// use flutter's Scrollable to manage scrolling to better integrate
|
|
|
// with widgets such as Scrollbar.
|
|
// with widgets such as Scrollbar.
|
|
|
return NotificationListener<UserScrollNotification>(
|
|
return NotificationListener<UserScrollNotification>(
|
|
@@ -197,6 +186,14 @@ class _TerminalViewState extends State<TerminalView> {
|
|
|
// set how much the terminal can scroll
|
|
// set how much the terminal can scroll
|
|
|
offset.applyContentDimensions(minScrollExtent, maxScrollExtent);
|
|
offset.applyContentDimensions(minScrollExtent, maxScrollExtent);
|
|
|
|
|
|
|
|
|
|
+ // syncronize terminal scroll extent to ScrollController
|
|
|
|
|
+ if (_terminalScrollExtent != null) {
|
|
|
|
|
+ widget.scrollController.position.correctPixels(
|
|
|
|
|
+ _terminalScrollExtent!,
|
|
|
|
|
+ );
|
|
|
|
|
+ _terminalScrollExtent = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return buildTerminal(context);
|
|
return buildTerminal(context);
|
|
|
},
|
|
},
|
|
|
),
|
|
),
|
|
@@ -268,7 +265,7 @@ class _TerminalViewState extends State<TerminalView> {
|
|
|
int? _lastTerminalWidth;
|
|
int? _lastTerminalWidth;
|
|
|
int? _lastTerminalHeight;
|
|
int? _lastTerminalHeight;
|
|
|
|
|
|
|
|
- void onResize(double width, double height) {
|
|
|
|
|
|
|
+ void onSize(double width, double height) {
|
|
|
final termWidth = (width / _cellSize.cellWidth).floor();
|
|
final termWidth = (width / _cellSize.cellWidth).floor();
|
|
|
final termHeight = (height / _cellSize.cellHeight).floor();
|
|
final termHeight = (height / _cellSize.cellHeight).floor();
|
|
|
|
|
|