@@ -194,9 +194,9 @@ class HitTestContext {
194194 private readonly _context : ViewContext ;
195195 private readonly _viewHelper : IPointerHandlerHelper ;
196196
197- constructor ( context : ViewContext , viewHelper : IPointerHandlerHelper , layoutInfo : EditorLayoutInfo , lastViewCursorsRenderData : IViewCursorRenderData [ ] ) {
197+ constructor ( context : ViewContext , viewHelper : IPointerHandlerHelper , lastViewCursorsRenderData : IViewCursorRenderData [ ] ) {
198198 this . model = context . model ;
199- this . layoutInfo = layoutInfo ;
199+ this . layoutInfo = context . configuration . editor . layoutInfo ;
200200 this . viewDomNode = viewHelper . viewDomNode ;
201201 this . lineHeight = context . configuration . editor . lineHeight ;
202202 this . typicalHalfwidthCharacterWidth = context . configuration . editor . fontInfo . typicalHalfwidthCharacterWidth ;
@@ -317,20 +317,18 @@ class HitTestContext {
317317
318318abstract class BareHitTestRequest {
319319
320- public readonly pos : PageCoordinates ;
321320 public readonly editorPos : EditorPagePosition ;
322-
321+ public readonly pos : PageCoordinates ;
323322 public readonly mouseVerticalOffset : number ;
324-
325323 public readonly isInMarginArea : boolean ;
326324 public readonly isInContentArea : boolean ;
327325 public readonly mouseContentHorizontalOffset : number ;
328326
329327 protected readonly mouseColumn : number ;
330328
331- constructor ( ctx : HitTestContext , pos : PageCoordinates , editorPos : EditorPagePosition ) {
332- this . pos = pos ;
329+ constructor ( ctx : HitTestContext , editorPos : EditorPagePosition , pos : PageCoordinates ) {
333330 this . editorPos = editorPos ;
331+ this . pos = pos ;
334332
335333 this . mouseVerticalOffset = Math . max ( 0 , ctx . getScrollTop ( ) + pos . y - editorPos . y ) ;
336334 this . mouseContentHorizontalOffset = ctx . getScrollLeft ( ) + pos . x - editorPos . x - ctx . layoutInfo . contentLeft ;
@@ -345,8 +343,8 @@ class HitTestRequest extends BareHitTestRequest {
345343 public readonly target : Element ;
346344 public readonly targetPath : Uint8Array ;
347345
348- constructor ( ctx : HitTestContext , pos : PageCoordinates , editorPos : EditorPagePosition , target : Element ) {
349- super ( ctx , pos , editorPos ) ;
346+ constructor ( ctx : HitTestContext , editorPos : EditorPagePosition , pos : PageCoordinates , target : Element ) {
347+ super ( ctx , editorPos , pos ) ;
350348 this . _ctx = ctx ;
351349
352350 if ( target ) {
@@ -367,16 +365,10 @@ class HitTestRequest extends BareHitTestRequest {
367365 }
368366
369367 public withTarget ( target : Element ) : HitTestRequest {
370- return new HitTestRequest ( this . _ctx , this . pos , this . editorPos , this . target ) ;
368+ return new HitTestRequest ( this . _ctx , this . editorPos , this . pos , target ) ;
371369 }
372370}
373371
374- export interface ISimplifiedEditorMouseEvent {
375- readonly page : PageCoordinates ;
376- readonly editorPos : EditorPagePosition ;
377- readonly target : HTMLElement ;
378- }
379-
380372export class MouseTargetFactory {
381373
382374 private _context : ViewContext ;
@@ -404,9 +396,9 @@ export class MouseTargetFactory {
404396 return false ;
405397 }
406398
407- public createMouseTarget ( layoutInfo : EditorLayoutInfo , lastViewCursorsRenderData : IViewCursorRenderData [ ] , e : ISimplifiedEditorMouseEvent , testEventTarget : boolean ) : IMouseTarget {
408- const ctx = new HitTestContext ( this . _context , this . _viewHelper , layoutInfo , lastViewCursorsRenderData ) ;
409- const request = new HitTestRequest ( ctx , e . page , e . editorPos , testEventTarget ? e . target : null ) ;
399+ public createMouseTarget ( lastViewCursorsRenderData : IViewCursorRenderData [ ] , editorPos : EditorPagePosition , pos : PageCoordinates , target : HTMLElement ) : IMouseTarget {
400+ const ctx = new HitTestContext ( this . _context , this . _viewHelper , lastViewCursorsRenderData ) ;
401+ const request = new HitTestRequest ( ctx , editorPos , pos , target ) ;
410402 try {
411403 let r = MouseTargetFactory . _createMouseTarget ( ctx , request , false ) ;
412404 // console.log(r.toString());
@@ -600,8 +592,9 @@ export class MouseTargetFactory {
600592 return null ;
601593 }
602594
603- public getMouseColumn ( layoutInfo : EditorLayoutInfo , e : ISimplifiedEditorMouseEvent ) : number {
604- let mouseContentHorizontalOffset = this . _viewHelper . getScrollLeft ( ) + e . page . x - e . editorPos . x - layoutInfo . contentLeft ;
595+ public getMouseColumn ( editorPos : EditorPagePosition , pos : PageCoordinates ) : number {
596+ let layoutInfo = this . _context . configuration . editor . layoutInfo ;
597+ let mouseContentHorizontalOffset = this . _viewHelper . getScrollLeft ( ) + pos . x - editorPos . x - layoutInfo . contentLeft ;
605598 return MouseTargetFactory . _getMouseColumn ( mouseContentHorizontalOffset , this . _context . configuration . editor . fontInfo . typicalHalfwidthCharacterWidth ) ;
606599 }
607600
@@ -758,15 +751,30 @@ export class MouseTargetFactory {
758751 private static _doHitTestWithCaretPositionFromPoint ( ctx : HitTestContext , coords : ClientCoordinates ) : IHitTestResult {
759752 let hitResult : { offsetNode : Node ; offset : number ; } = ( < any > document ) . caretPositionFromPoint ( coords . clientX , coords . clientY ) ;
760753
761- let range = document . createRange ( ) ;
762- range . setStart ( hitResult . offsetNode , hitResult . offset ) ;
763- range . collapse ( true ) ;
764- let resultPosition = ctx . getPositionFromDOMInfo ( < HTMLElement > range . startContainer . parentNode , range . startOffset ) ;
765- range . detach ( ) ;
754+ if ( hitResult . offsetNode . nodeType === hitResult . offsetNode . TEXT_NODE ) {
755+ // offsetNode is expected to be the token text
756+ let parent1 = hitResult . offsetNode . parentNode ; // expected to be the token span
757+ let parent2 = parent1 ? parent1 . parentNode : null ; // expected to be the view line container span
758+ let parent3 = parent2 ? parent2 . parentNode : null ; // expected to be the view line div
759+ let parent3ClassName = parent3 && parent3 . nodeType === parent3 . ELEMENT_NODE ? ( < HTMLElement > parent3 ) . className : null ;
760+
761+ if ( parent3ClassName === ClassNames . VIEW_LINE ) {
762+ let p = ctx . getPositionFromDOMInfo ( < HTMLElement > hitResult . offsetNode . parentNode , hitResult . offset ) ;
763+ return {
764+ position : p ,
765+ hitTarget : null
766+ } ;
767+ } else {
768+ return {
769+ position : null ,
770+ hitTarget : < HTMLElement > hitResult . offsetNode . parentNode
771+ } ;
772+ }
773+ }
766774
767775 return {
768- position : resultPosition ,
769- hitTarget : null
776+ position : null ,
777+ hitTarget : < HTMLElement > hitResult . offsetNode
770778 } ;
771779 }
772780
0 commit comments