@@ -880,20 +880,25 @@ open class TerminalView: NSView, NSTextInputClient, NSUserInterfaceValidations,
880880 }
881881
882882 func calculateMouseHit ( with event: NSEvent ) -> ( grid: Position , pixels: Position )
883+ {
884+ let point = convert ( event. locationInWindow, from: nil )
885+ return calculateMouseHit ( at: point)
886+ }
887+
888+ func calculateMouseHit ( at point: CGPoint ) -> ( grid: Position , pixels: Position )
883889 {
884890 func toInt ( _ p: NSPoint ) -> Position {
885-
891+
886892 let x = min ( max ( p. x, 0 ) , bounds. width)
887893 let y = min ( max ( p. y, 0 ) , bounds. height)
888894 return Position ( col: Int ( x) , row: Int ( bounds. height- y) )
889895 }
890- let point = convert ( event. locationInWindow, from: nil )
891896 let col = Int ( point. x / cellDimension. width)
892- let row = Int ( ( frame. height- point. y) / cellDimension. height)
897+ let row = Int ( ( frame. height- point. y) / cellDimension. height) + terminal . buffer . yDisp
893898 if row < 0 {
894899 return ( Position ( col: 0 , row: 0 ) , toInt ( point) )
895900 }
896- return ( Position ( col: min ( max ( 0 , col) , terminal. cols- 1 ) , row: min ( row, terminal . rows - 1 ) ) , toInt ( point) )
901+ return ( Position ( col: min ( max ( 0 , col) , terminal. cols- 1 ) , row: row) , toInt ( point) )
897902 }
898903
899904 private func sharedMouseEvent ( with event: NSEvent )
0 commit comments