(mouse_x, mouse_y)
| 3548 | } |
| 3549 | |
| 3550 | function getIndexFromPoint(mouse_x, mouse_y) { |
| 3551 | // Position cursor here |
| 3552 | var pt = svgroot.createSVGPoint(); |
| 3553 | pt.x = mouse_x; |
| 3554 | pt.y = mouse_y; |
| 3555 | |
| 3556 | // No content, so return 0 |
| 3557 | if(chardata.length == 1) return 0; |
| 3558 | // Determine if cursor should be on left or right of character |
| 3559 | var charpos = curtext.getCharNumAtPosition(pt); |
| 3560 | if(charpos < 0) { |
| 3561 | // Out of text range, look at mouse coords |
| 3562 | charpos = chardata.length - 2; |
| 3563 | if(mouse_x <= chardata[0].x) { |
| 3564 | charpos = 0; |
| 3565 | } |
| 3566 | } else if(charpos >= chardata.length - 2) { |
| 3567 | charpos = chardata.length - 2; |
| 3568 | } |
| 3569 | var charbb = chardata[charpos]; |
| 3570 | var mid = charbb.x + (charbb.width/2); |
| 3571 | if(mouse_x > mid) { |
| 3572 | charpos++; |
| 3573 | } |
| 3574 | return charpos; |
| 3575 | } |
| 3576 | |
| 3577 | function setCursorFromPoint(mouse_x, mouse_y) { |
| 3578 | setCursor(getIndexFromPoint(mouse_x, mouse_y)); |
no outgoing calls
no test coverage detected