Skip to content

Commit 2cb25fe

Browse files
committed
Fix dragging item frame
1 parent 42dafbe commit 2cb25fe

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Sources/STTextViewAppKit/STTextLayoutRangeView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ open class STTextLayoutRangeView: NSView {
3030
var frame: CGRect = textLayoutManager.textSegmentFrame(in: self.textRange, type: .standard)!
3131
textLayoutManager.enumerateTextLayoutFragments(in: self.textRange) { textLayoutFragment in
3232
frame = CGRect(
33-
x: min(frame.origin.x, textLayoutFragment.layoutFragmentFrame.minX),
34-
y: min(frame.origin.y, textLayoutFragment.layoutFragmentFrame.minY),
33+
x: 0,
34+
y: 0,
3535
width: max(frame.size.width, textLayoutFragment.layoutFragmentFrame.maxX + textLayoutFragment.leadingPadding + textLayoutFragment.trailingPadding),
3636
height: max(frame.size.height, textLayoutFragment.layoutFragmentFrame.maxY + textLayoutFragment.topMargin + textLayoutFragment.bottomMargin)
3737
)

Sources/STTextViewAppKit/STTextView+DragGestureRecognizer.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ extension STTextView {
2222
let rangeView = STTextLayoutRangeView(textLayoutManager: textLayoutManager, textRange: textRange)
2323
let draggingImage = rangeView.image()
2424

25+
let draggingFrame = gestureRecognizer.view?.convert(rangeView.frame, from: contentView) ?? rangeView.frame
26+
2527
let draggingItem = NSDraggingItem(pasteboardWriter: selectionsAttributedString)
26-
draggingItem.setDraggingFrame(rangeView.frame, contents: draggingImage)
28+
draggingItem.setDraggingFrame(draggingFrame, contents: draggingImage)
2729

2830
draggingSession = beginDraggingSession(with: [draggingItem], event: NSApp.currentEvent!, source: self)
2931
}

0 commit comments

Comments
 (0)