File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ export default function (mind: MindElixirInstance) {
5959 mind . map . addEventListener ( 'mousemove' , e => {
6060 // click trigger mousemove in windows chrome
6161 if ( ( e . target as HTMLElement ) . contentEditable !== 'true' ) {
62- dragMoveHelper . onMove ( e , mind . container )
62+ dragMoveHelper . onMove ( e , mind )
6363 }
6464 } )
6565 mind . map . addEventListener ( 'mousedown' , e => {
Original file line number Diff line number Diff line change 1+ import type { MindElixirInstance } from '../types/index'
2+
13export default {
24 moved : false , // diffrentiate click and move
35 mousedown : false ,
4- onMove ( e : MouseEvent , container : HTMLElement ) {
6+ onMove ( e : MouseEvent , mind : MindElixirInstance ) {
57 if ( this . mousedown ) {
68 this . moved = true
79 const deltaX = e . movementX
810 const deltaY = e . movementY
9- container . scrollTo ( container . scrollLeft - deltaX , container . scrollTop - deltaY )
11+ const { container, map, scaleVal } = mind
12+ let scrollLeft = container . scrollLeft - deltaX
13+ let scrollTop = container . scrollTop - deltaY
14+ if ( scaleVal < 1 ) {
15+ const minScrollLeft = ( container . scrollWidth - map . clientWidth * scaleVal ) / 2
16+ const minScrollTop = ( container . scrollHeight - map . clientHeight * scaleVal ) / 2
17+ scrollLeft = Math . max ( minScrollLeft , Math . min ( container . scrollWidth - minScrollLeft - container . clientWidth , scrollLeft ) )
18+ scrollTop = Math . max ( minScrollTop , Math . min ( container . scrollHeight - minScrollTop - container . clientHeight , scrollTop ) )
19+ }
20+ container . scrollTo ( scrollLeft , scrollTop )
1021 }
1122 } ,
1223 clear ( ) {
You can’t perform that action at this time.
0 commit comments