@@ -1468,6 +1468,8 @@ function onMouseDown(event) {
14681468}
14691469
14701470function pressureToLineWidth ( event ) {
1471+ //event.button === 0 could be wrong, as it can also be the uninitialized state.
1472+ //Therefore we use event.buttons, which works differently.
14711473 if ( event . buttons !== 1 || event . pressure === 0 || event . pointerType === "touch" ) {
14721474 return 0 ;
14731475 }
@@ -1477,11 +1479,32 @@ function pressureToLineWidth(event) {
14771479 return Math . ceil ( event . pressure * 32 ) ;
14781480}
14791481
1482+ // Previously the onMouseMove handled leave, but we do this separately now for
1483+ // proper pen support. Otherwise leave leads to a loss of the pen pressure, as
1484+ // we are handling that with mouseleave instead of pointerleave. pointerlave
1485+ // is not triggered until the pen is let go.
1486+ function onMouseLeave ( event ) {
1487+ if ( allowDrawing
1488+ && lastLineWidth
1489+ && localTool !== fillBucket ) {
1490+
1491+ // calculate the offset coordinates based on client mouse position and drawing board client origin
1492+ const clientRect = drawingBoard . getBoundingClientRect ( ) ;
1493+ const offsetX = ( event . clientX - clientRect . left ) ;
1494+ const offsetY = ( event . clientY - clientRect . top ) ;
1495+
1496+ // drawing functions must check for context boundaries
1497+ drawLineAndSendEvent ( context , lastX , lastY , offsetX , offsetY , lastLineWidth ) ;
1498+ lastX = offsetX ;
1499+ lastY = offsetY ;
1500+ }
1501+ }
1502+
1503+ let lastLineWidth ;
14801504function onMouseMove ( event ) {
14811505 const pressureLineWidth = pressureToLineWidth ( event ) ;
1506+ lastLineWidth = pressureLineWidth ;
14821507
1483- //event.button === 0 could be wrong, as it can also be the uninitialized state.
1484- //Therefore we use event.buttons, which works differently.
14851508 if ( allowDrawing
14861509 && pressureLineWidth
14871510 && localTool !== fillBucket ) {
@@ -1513,7 +1536,7 @@ function onMouseClick(event) {
15131536
15141537drawingBoard . addEventListener ( 'pointerdown' , onMouseDown )
15151538drawingBoard . addEventListener ( 'pointermove' , onMouseMove ) ;
1516- drawingBoard . addEventListener ( 'mouseleave' , onMouseMove ) ;
1539+ drawingBoard . addEventListener ( 'mouseleave' , onMouseLeave ) ;
15171540drawingBoard . addEventListener ( 'click' , onMouseClick ) ;
15181541
15191542function onGlobalMouseMove ( event ) {
0 commit comments