|
|
|
|
|
|
this._selection = null; |
|
|
|
this.onSelectionChanged = onSelectionChanged; |
|
|
|
this.selectionColor = selectionColor; |
|
|
|
|
|
|
|
|
|
|
|
this._listenToHoverEvent = this._textPainter.text.needHoverRecognizer; |
|
|
|
this._previousHoverSpan = null; |
|
|
|
this._pointerHoverInside = false; |
|
|
|
|
|
|
|
this._resetHoverHandler(); |
|
|
|
} |
|
|
|
|
|
|
|
public Action onSelectionChanged; |
|
|
|
|
|
|
case RenderComparison.identical: |
|
|
|
case RenderComparison.metadata: |
|
|
|
return; |
|
|
|
case RenderComparison.hoverCallback: |
|
|
|
case RenderComparison.function: |
|
|
|
this._textPainter.text = value; |
|
|
|
break; |
|
|
|
case RenderComparison.paint: |
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
this._listenToHoverEvent = this._textPainter.text.needHoverRecognizer; |
|
|
|
this._previousHoverSpan = null; |
|
|
|
this._pointerHoverInside = false; |
|
|
|
this._resetHoverHandler(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TextSpan _previousHoverSpan; |
|
|
|
bool _pointerHoverInside; |
|
|
|
bool _hasHoverRecognizer; |
|
|
|
|
|
|
|
void _resetHoverHandler() { |
|
|
|
this._hasHoverRecognizer = this._textPainter.text.hasHoverRecognizer; |
|
|
|
this._previousHoverSpan = null; |
|
|
|
this._pointerHoverInside = false; |
|
|
|
} |
|
|
|
|
|
|
|
void _handleKeyEvent(RawKeyEvent keyEvent) { |
|
|
|
//only allow KCommand.copy
|
|
|
|
if (keyEvent is RawKeyUpEvent) { |
|
|
|
|
|
|
this.onSelectionChanged?.Invoke(); |
|
|
|
} |
|
|
|
|
|
|
|
TextSpan _previousHoverSpan = null; |
|
|
|
bool _pointerHoverInside = false; |
|
|
|
bool _listenToHoverEvent = false; |
|
|
|
public override void handleEvent(PointerEvent evt, HitTestEntry entry) { |
|
|
|
D.assert(this.debugHandleEvent(evt, entry)); |
|
|
|
if (evt is PointerDownEvent) { |
|
|
|
this._layoutTextWithConstraints(this.constraints); |
|
|
|
Offset offset = ((BoxHitTestEntry) entry).localPosition; |
|
|
|
TextPosition position = this._textPainter.getPositionForOffset(offset); |
|
|
|
TextSpan span = this._textPainter.text.getSpanForPosition(position); |
|
|
|
span?.recognizer?.addPointer((PointerDownEvent) evt); |
|
|
|
} |
|
|
|
|
|
|
|
if (!this._listenToHoverEvent) { |
|
|
|
void _handlePointerHover(PointerEvent evt) { |
|
|
|
if (!this._hasHoverRecognizer) { |
|
|
|
} else if (evt is PointerLeaveEvent) { |
|
|
|
} |
|
|
|
else if (evt is PointerLeaveEvent) { |
|
|
|
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave(); |
|
|
|
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave?.Invoke(); |
|
|
|
this._previousHoverSpan = null; |
|
|
|
} |
|
|
|
else if (evt is PointerHoverEvent && this._pointerHoverInside) { |
|
|
|
|
|
|
TextSpan span = this._textPainter.text.getSpanForPosition(position); |
|
|
|
|
|
|
|
if (this._previousHoverSpan != span) { |
|
|
|
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave(); |
|
|
|
span?.hoverRecognizer?.OnPointerEnter(); |
|
|
|
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave?.Invoke(); |
|
|
|
span?.hoverRecognizer?.OnPointerEnter?.Invoke((PointerHoverEvent) evt); |
|
|
|
} |
|
|
|
|
|
|
|
public override void handleEvent(PointerEvent evt, HitTestEntry entry) { |
|
|
|
D.assert(this.debugHandleEvent(evt, entry)); |
|
|
|
if (evt is PointerDownEvent) { |
|
|
|
this._layoutTextWithConstraints(this.constraints); |
|
|
|
Offset offset = ((BoxHitTestEntry) entry).localPosition; |
|
|
|
TextPosition position = this._textPainter.getPositionForOffset(offset); |
|
|
|
TextSpan span = this._textPainter.text.getSpanForPosition(position); |
|
|
|
span?.recognizer?.addPointer((PointerDownEvent) evt); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this._handlePointerHover(evt); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void performLayout() { |
|
|
|
|
|
|
foreach (var box in this._selectionRects) { |
|
|
|
barPath.addRect(box.toRect().shift(effectiveOffset)); |
|
|
|
} |
|
|
|
|
|
|
|
canvas.drawPath(barPath, paint); |
|
|
|
} |
|
|
|
|
|
|
|