1
This commit is contained in:
1 parent
1ab5d52449
commit
5efc778165
18 files changed
+1031
-63
No files matched your search
@@ -330,6 +330,7 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
_textStyle = value;
|
||||
if (comparison.index >= RenderComparison.layout.index) {
|
||||
_calculatePreferredLineHeight();
|
||||
_displayParagraphs.clear();
|
||||
markNeedsLayout();
|
||||
} else {
|
||||
markNeedsPaint();
|
||||
@@ -1342,9 +1343,24 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
if (target <= paddingTop) {
|
||||
startIndex = 0;
|
||||
} else {
|
||||
startIndex = min(((target - paddingTop) / _preferredLineHeight).ceil(), max(0, _codes.length - 1));
|
||||
startIndex = min(((target - paddingTop) / _preferredLineHeight).floor(), max(0, _codes.length - 1));
|
||||
}
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
} else if (_horizontalViewport != null) {
|
||||
// In horizontal scrolling (unwrapped) mode, every line has height == _preferredLineHeight.
|
||||
// There is no line wrapping, so delta is strictly 0 and viewport correction should never occur.
|
||||
final int startIndex;
|
||||
if (target <= paddingTop) {
|
||||
startIndex = 0;
|
||||
} else {
|
||||
startIndex = min(((target - paddingTop) / _preferredLineHeight).floor(), max(0, _codes.length - 1));
|
||||
}
|
||||
if (_displayParagraphs.first.index != startIndex ||
|
||||
target < _displayParagraphs.first.top ||
|
||||
target + size.height > _displayParagraphs.last.bottom) {
|
||||
_displayParagraphs.clear();
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
}
|
||||
} else {
|
||||
if (_codes.length <= _displayParagraphs.first.index) {
|
||||
_displayParagraphs.clear();
|
||||
@@ -1364,7 +1380,11 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_verticalViewport.correctBy(delta);
|
||||
final bool isPinchLocked = _verticalViewport is CodeEditorScrollPosition &&
|
||||
(_verticalViewport as CodeEditorScrollPosition).isPinchLocked;
|
||||
if (!isPinchLocked) {
|
||||
_verticalViewport.correctBy(delta);
|
||||
}
|
||||
_displayParagraphs.clear();
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
} else if (target > _displayParagraphs.last.bottom) {
|
||||
@@ -1372,7 +1392,7 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
if (target <= paddingTop) {
|
||||
startIndex = 0;
|
||||
} else {
|
||||
startIndex = min((target / _preferredLineHeight).floor(), max(0, _codes.length - 1));
|
||||
startIndex = min(((target - paddingTop) / _preferredLineHeight).floor(), max(0, _codes.length - 1));
|
||||
}
|
||||
_displayParagraphs.clear();
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
@@ -1387,7 +1407,11 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
delta += paragraph.paragraph.height - _preferredLineHeight;
|
||||
}
|
||||
assert(startIndex >= 0);
|
||||
_verticalViewport.correctBy(-delta);
|
||||
final bool isPinchLocked = _verticalViewport is CodeEditorScrollPosition &&
|
||||
(_verticalViewport as CodeEditorScrollPosition).isPinchLocked;
|
||||
if (!isPinchLocked) {
|
||||
_verticalViewport.correctBy(-delta);
|
||||
}
|
||||
_displayParagraphs.clear();
|
||||
_displayParagraphs.addAll(_buildDisplayRenderParagraphs(startIndex, effectiveWidth));
|
||||
}
|
||||
@@ -1405,7 +1429,11 @@ class _CodeFieldRender extends RenderBox implements MouseTrackerAnnotation {
|
||||
final double extraBottom = _extraVerticalScroll ?? max(0.0, size.height * 0.5);
|
||||
_verticalViewportSize = max(0, totalHeight - size.height + extraBottom);
|
||||
if (_verticalViewport.pixels > _verticalViewportSize!) {
|
||||
_verticalViewport.correctBy(_verticalViewportSize! - _verticalViewport.pixels);
|
||||
final bool isPinchLocked = _verticalViewport is CodeEditorScrollPosition &&
|
||||
(_verticalViewport as CodeEditorScrollPosition).isPinchLocked;
|
||||
if (!isPinchLocked) {
|
||||
_verticalViewport.correctBy(_verticalViewportSize! - _verticalViewport.pixels);
|
||||
}
|
||||
}
|
||||
_verticalViewport.applyContentDimensions(0, _verticalViewportSize!);
|
||||
if (_horizontalViewport != null) {
|
||||
@@ -1757,7 +1785,7 @@ class _CodeCursorLinePainter extends _CodeFieldExtraPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size, _CodeFieldRender render) {
|
||||
if (_color == null || _color == Colors.transparent || _color!.alpha == 0) {
|
||||
if (_color == null || _color == Colors.transparent || _color!.a == 0.0) {
|
||||
return;
|
||||
}
|
||||
if (!_selection.isCollapsed) {
|
||||
@@ -1811,7 +1839,7 @@ abstract class _CodeFieldSelectionsPainter extends _CodeFieldExtraPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size, _CodeFieldRender render) {
|
||||
if (_color == Colors.transparent || _color.alpha == 0) {
|
||||
if (_color == Colors.transparent || _color.a == 0.0) {
|
||||
return;
|
||||
}
|
||||
final List<CodeLineRenderParagraph> paragraphs = render.displayParagraphs;
|
||||
@@ -1971,7 +1999,7 @@ class _CodeFieldCursorPainter extends _CodeFieldExtraPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size, _CodeFieldRender render) {
|
||||
if (!_visible || !_willDraw || _color == Colors.transparent || _color.alpha == 0) {
|
||||
if (!_visible || !_willDraw || _color == Colors.transparent || _color.a == 0.0) {
|
||||
return;
|
||||
}
|
||||
final CodeLineRenderParagraph? paragraph = render.findDisplayParagraphByLineIndex(_position.index);
|
||||
@@ -2053,7 +2081,7 @@ class _CodeFieldFloatingCursorPainter extends _CodeFieldExtraPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size, _CodeFieldRender render) {
|
||||
if (!_position.isActive() || _color == Colors.transparent || _color.alpha == 0) {
|
||||
if (!_position.isActive() || _color == Colors.transparent || _color.a == 0.0) {
|
||||
return;
|
||||
}
|
||||
_drawFloatingCaret(canvas, _position.floatingCursorOffset!, size);
|
||||
|
||||
@@ -21,9 +21,12 @@ class _ParagraphImpl extends IParagraph {
|
||||
required this.paragraph,
|
||||
required bool trucated,
|
||||
required double preferredLineHeight,
|
||||
bool isSingleLine = false,
|
||||
}) : _trucated = trucated,
|
||||
_preferredLineHeight = preferredLineHeight,
|
||||
_lineCount = (paragraph.height / preferredLineHeight).ceil();
|
||||
_lineCount = isSingleLine
|
||||
? 1
|
||||
: max(1, (paragraph.height / preferredLineHeight).round());
|
||||
|
||||
int get runeLength => text.runes.length;
|
||||
|
||||
@@ -314,12 +317,14 @@ class _CodeParagraphProvider {
|
||||
span.build(builder);
|
||||
final ui.Paragraph paragraph = builder.build();
|
||||
paragraph.layout(_constraints!);
|
||||
final bool isSingleLine = _constraints!.width.isInfinite;
|
||||
return _ParagraphImpl(
|
||||
text: plainText,
|
||||
span: span,
|
||||
paragraph: paragraph,
|
||||
trucated: trucated,
|
||||
preferredLineHeight: _preferredLineHeight!,
|
||||
isSingleLine: isSingleLine,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ typedef CodeScrollbarBuilder = Widget Function(BuildContext context, Widget chil
|
||||
/// to swipe twice horizontally to start horizontal scrolling. Overriding
|
||||
/// [shouldIgnorePointer] to return false allows bidirectional scroll gestures to
|
||||
/// seamlessly take over on the very first swipe.
|
||||
|
||||
class CodeEditorScrollPosition extends ScrollPositionWithSingleContext {
|
||||
CodeEditorScrollPosition({
|
||||
required super.physics,
|
||||
@@ -23,6 +24,24 @@ class CodeEditorScrollPosition extends ScrollPositionWithSingleContext {
|
||||
super.debugLabel,
|
||||
});
|
||||
|
||||
bool _isPinchLocked = false;
|
||||
bool get isPinchLocked => _isPinchLocked;
|
||||
set isPinchLocked(bool value) {
|
||||
if (_isPinchLocked == value) return;
|
||||
_isPinchLocked = value;
|
||||
if (value) {
|
||||
stopScrolling();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void applyUserOffset(double delta) {
|
||||
if (_isPinchLocked) {
|
||||
return;
|
||||
}
|
||||
super.applyUserOffset(delta);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get shouldIgnorePointer => false;
|
||||
|
||||
@@ -49,13 +68,25 @@ class CodeEditorScrollController extends ScrollController {
|
||||
super.onDetach,
|
||||
});
|
||||
|
||||
bool _isPinchLocked = false;
|
||||
bool get isPinchLocked => _isPinchLocked;
|
||||
set isPinchLocked(bool value) {
|
||||
if (_isPinchLocked == value) return;
|
||||
_isPinchLocked = value;
|
||||
for (final position in positions) {
|
||||
if (position is CodeEditorScrollPosition) {
|
||||
position.isPinchLocked = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
ScrollPosition createScrollPosition(
|
||||
ScrollPhysics physics,
|
||||
ScrollContext context,
|
||||
ScrollPosition? oldPosition,
|
||||
) {
|
||||
return CodeEditorScrollPosition(
|
||||
final position = CodeEditorScrollPosition(
|
||||
physics: physics,
|
||||
context: context,
|
||||
initialPixels: delegate?.initialScrollOffset ?? initialScrollOffset,
|
||||
@@ -63,11 +94,16 @@ class CodeEditorScrollController extends ScrollController {
|
||||
oldPosition: oldPosition,
|
||||
debugLabel: delegate?.debugLabel ?? debugLabel,
|
||||
);
|
||||
position.isPinchLocked = _isPinchLocked;
|
||||
return position;
|
||||
}
|
||||
|
||||
@override
|
||||
void attach(ScrollPosition position) {
|
||||
super.attach(position);
|
||||
if (position is CodeEditorScrollPosition) {
|
||||
position.isPinchLocked = _isPinchLocked;
|
||||
}
|
||||
if (delegate != null && !delegate!.positions.contains(position)) {
|
||||
delegate!.attach(position);
|
||||
}
|
||||
@@ -86,7 +122,7 @@ class CodeEditorScrollController extends ScrollController {
|
||||
for (final position in positions) {
|
||||
if (position is CodeEditorScrollPosition) {
|
||||
position.stopScrolling();
|
||||
} else if (position is ScrollPositionWithSingleContext && position.activity?.isScrolling == true) {
|
||||
} else if (position is ScrollPositionWithSingleContext) {
|
||||
position.goIdle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,6 +300,7 @@ class TerminalViewState extends State<TerminalView> {
|
||||
terminalView: this,
|
||||
terminalController: _controller,
|
||||
onTapUp: _onTapUp,
|
||||
onSingleTapUp: _onSingleTapUp,
|
||||
onTapDown: _onTapDown,
|
||||
onSecondaryTapDown:
|
||||
widget.onSecondaryTapDown != null ? _onSecondaryTapDown : null,
|
||||
@@ -345,8 +346,8 @@ class TerminalViewState extends State<TerminalView> {
|
||||
widget.onTapUp?.call(details, offset);
|
||||
}
|
||||
|
||||
void _onTapDown(_) {
|
||||
if (_controller.selection != null) {
|
||||
void _onSingleTapUp(TapUpDetails details) {
|
||||
if (_controller.selection != null && !_controller.selection!.isCollapsed) {
|
||||
_controller.clearSelection();
|
||||
} else {
|
||||
if (!widget.hardwareKeyboardOnly) {
|
||||
@@ -355,6 +356,13 @@ class TerminalViewState extends State<TerminalView> {
|
||||
_focusNode.requestFocus();
|
||||
}
|
||||
}
|
||||
final offset = renderTerminal.getCellOffset(details.localPosition);
|
||||
widget.onTapUp?.call(details, offset);
|
||||
}
|
||||
|
||||
void _onTapDown(_) {
|
||||
// Intentionally empty: tapping down (PointerDown) must not open the soft keyboard,
|
||||
// ensuring long-press can select text without triggering keyboard pop-up or scroll jumps.
|
||||
}
|
||||
|
||||
void _onSecondaryTapDown(TapDownDetails details) {
|
||||
@@ -431,7 +439,8 @@ class TerminalViewState extends State<TerminalView> {
|
||||
}
|
||||
|
||||
void _onKeyboardShow() {
|
||||
if (_focusNode.hasFocus) {
|
||||
if (_focusNode.hasFocus &&
|
||||
(_controller.selection == null || _controller.selection!.isCollapsed)) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_scrollToBottom();
|
||||
});
|
||||
|
||||
@@ -64,6 +64,13 @@ class _TerminalGestureDetectorState extends State<TerminalGestureDetector> {
|
||||
// subsequent tap up / tap hold of the same tap.
|
||||
bool _isDoubleTap = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_doubleTapTimer?.cancel();
|
||||
_doubleTapTimer = null;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// The down handler is force-run on success of a single tap and optimistically
|
||||
// run before a long press success.
|
||||
void _handleTapDown(TapDownDetails details) {
|
||||
@@ -84,12 +91,19 @@ class _TerminalGestureDetectorState extends State<TerminalGestureDetector> {
|
||||
void _handleTapUp(TapUpDetails details) {
|
||||
if (!_isDoubleTap) {
|
||||
widget.onSingleTapUp?.call(details);
|
||||
widget.onTapUp?.call(details);
|
||||
_lastTapOffset = details.globalPosition;
|
||||
_doubleTapTimer = Timer(kDoubleTapTimeout, _doubleTapTimeout);
|
||||
}
|
||||
_isDoubleTap = false;
|
||||
}
|
||||
|
||||
void _handleTapCancel() {
|
||||
_doubleTapTimer?.cancel();
|
||||
_doubleTapTimeout();
|
||||
_isDoubleTap = false;
|
||||
}
|
||||
|
||||
void _doubleTapTimeout() {
|
||||
_doubleTapTimer = null;
|
||||
_lastTapOffset = null;
|
||||
@@ -115,6 +129,7 @@ class _TerminalGestureDetectorState extends State<TerminalGestureDetector> {
|
||||
instance
|
||||
..onTapDown = _handleTapDown
|
||||
..onTapUp = _handleTapUp
|
||||
..onTapCancel = _handleTapCancel
|
||||
..onSecondaryTapDown = widget.onSecondaryTapDown
|
||||
..onSecondaryTapUp = widget.onSecondaryTapUp
|
||||
..onTertiaryTapDown = widget.onTertiaryTapDown
|
||||
|
||||
Reference in new issue
Block a user