@@ -95,53 +95,6 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
9595 let getPos ( p : Point ) =
9696 int( p.X / m_ glyphsize.Width), int( p.Y / m_ glyphsize.Height)
9797
98- let cursorConfig () =
99- if theme.mode_ defs.Length = 0 || m_ cursor_ vm.modeidx < 0 then ()
100- elif m_ gridbuffer.GetLength( 0 ) <= m_ cursor_ vm.row || m_ gridbuffer.GetLength( 1 ) <= m_ cursor_ vm.col then ()
101- else
102- let _ , _ , target_vm , target_row , target_col , _ : int * int * GridViewModel * int * int * int = this.FindTargetVm m_ cursor_ vm.row m_ cursor_ vm.col
103- let mode = theme.mode_ defs.[ m_ cursor_ vm.modeidx]
104- let hlid = target_ vm.[ target_ row, target_ col]. hlid
105- let hlid = Option.defaultValue hlid mode.attr_ id
106- let fg , bg , sp , attrs = theme.GetDrawAttrs hlid
107- let origin : Point = this.GetPoint m_ cursor_ vm.row m_ cursor_ vm.col
108- let text = target_ vm.[ target_ row, target_ col]. text
109- let text_type = wswidth text
110- let width = float( max <| 1 <| CharTypeWidth text_ type) * m_ glyphsize.Width
111-
112- let on , off , wait =
113- match mode with
114- | { blinkon = Some on; blinkoff = Some off; blinkwait = Some wait }
115- when on > 0 && off > 0 && wait > 0 -> on, off, wait
116- | _ -> 0 , 0 , 0
117-
118- // do not use the default colors for cursor
119- let colorf = if hlid = 0 then GetReverseColor else id
120- let fg , bg , sp = colorf fg, colorf bg, colorf sp
121-
122- m_ cursor_ vm.typeface <- theme.guifont
123- m_ cursor_ vm.wtypeface <- theme.guifontwide
124- m_ cursor_ vm.fontSize <- m_ fontsize
125- m_ cursor_ vm.text <- text
126- m_ cursor_ vm.fg <- fg
127- m_ cursor_ vm.bg <- bg
128- m_ cursor_ vm.sp <- sp
129- m_ cursor_ vm.underline <- attrs.underline
130- m_ cursor_ vm.undercurl <- attrs.undercurl
131- m_ cursor_ vm.bold <- attrs.bold
132- m_ cursor_ vm.italic <- attrs.italic
133- m_ cursor_ vm.cellPercentage <- Option.defaultValue 100 mode.cell_ percentage
134- m_ cursor_ vm.blinkon <- on
135- m_ cursor_ vm.blinkoff <- off
136- m_ cursor_ vm.blinkwait <- wait
137- m_ cursor_ vm.shape <- Option.defaultValue CursorShape.Block mode.cursor_ shape
138- m_ cursor_ vm.X <- origin.X
139- m_ cursor_ vm.Y <- origin.Y
140- m_ cursor_ vm.Width <- width
141- m_ cursor_ vm.Height <- m_ glyphsize.Height
142- m_ cursor_ vm.RenderTick <- m_ cursor_ vm.RenderTick + 1
143- //trace _gridid "set cursor info, color = %A %A %A" fg bg sp
144-
14598 let markAllDirty () =
14699 m_ griddirty <- true
147100 for c in m_ child_ grids do
@@ -155,7 +108,7 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
155108
156109 // if the buffer under cursor is updated, also notify the cursor view model
157110 if row = m_ cursor_ vm.row && col <= m_ cursor_ vm.col && m_ cursor_ vm.col < col + w
158- then cursorConfig ()
111+ then this.CursorConfig ()
159112
160113 // the workarounds below will extend the dirty region -- if we are drawing
161114 // a base grid displaying the grid boundaries, do not apply them.
@@ -239,6 +192,8 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
239192 m_ extmarks.Remove m.mark |> ignore
240193 m_ gridbuffer.[ row, col]. marks <- []
241194 col <- col + 1
195+ if m_ cursor_ vm.row = row && m_ cursor_ vm.col = col then
196+ this.CursorConfig()
242197 markDirty { row = row; col = line.col_ start; height = 1 ; width = col - line.col_ start }
243198
244199 let clearMarks () =
@@ -270,7 +225,7 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
270225
271226 let changeMode ( name : string ) ( index : int ) =
272227 m_ cursor_ vm.modeidx <- index
273- cursorConfig ()
228+ this.CursorConfig ()
274229
275230 let setCursorEnabled v =
276231 m_ cursor_ vm.enabled <- v
@@ -356,7 +311,7 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
356311 && left <= m_ cursor_ vm.col
357312 && m_ cursor_ vm.col <= right
358313 then
359- cursorConfig ()
314+ this.CursorConfig ()
360315
361316 m_ drawops.Add( Scroll( top, bot, left, right, rows, cols))
362317
@@ -486,7 +441,7 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
486441 //trace _gridid "fontConfig: glyphsize=%A, measured font size=%A" m_glyphsize m_fontsize
487442
488443 // sync font to cursor vm
489- cursorConfig ()
444+ this.CursorConfig ()
490445 // sync font to popupmenu vm
491446 m_ popupmenu_ vm.SetFont( theme.guifont, theme.fontsize)
492447 markAllDirty()
@@ -551,7 +506,7 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
551506 this.ObservableForProperty( fun x -> x.IsFocused)
552507 |> Observable.subscribe ( fun x ->
553508 trace _ gridid " focus state changed: %A " x.Value
554- cursorConfig ()
509+ this.CursorConfig ()
555510 )
556511
557512 rpc.register.notify " OnBufWinEnter" this.OnBufWinEnter
@@ -594,35 +549,85 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
594549 m_ z <- - 100
595550 markAllDirty()
596551
552+ member __.CursorConfig () =
553+ if m_ parent.IsSome then m_ parent.Value.CursorConfig()
554+ else
555+ if theme.mode_ defs.Length = 0 || m_ cursor_ vm.modeidx < 0 then ()
556+ elif m_ gridbuffer.GetLength( 0 ) <= m_ cursor_ vm.row || m_ gridbuffer.GetLength( 1 ) <= m_ cursor_ vm.col then ()
557+ else
558+ let _ , _ , target_vm , target_row , target_col , _ : int * int * GridViewModel * int * int * int = this.FindTargetVm m_ cursor_ vm.row m_ cursor_ vm.col
559+ let mode = theme.mode_ defs.[ m_ cursor_ vm.modeidx]
560+ let hlid = target_ vm.[ target_ row, target_ col]. hlid
561+ let hlid = Option.defaultValue hlid mode.attr_ id
562+ let fg , bg , sp , attrs = theme.GetDrawAttrs hlid
563+ let origin : Point = this.GetPoint m_ cursor_ vm.row m_ cursor_ vm.col
564+ let text = target_ vm.[ target_ row, target_ col]. text
565+ let text_type = wswidth text
566+ let width = float( max <| 1 <| CharTypeWidth text_ type) * m_ glyphsize.Width
567+
568+ let on , off , wait =
569+ match mode with
570+ | { blinkon = Some on; blinkoff = Some off; blinkwait = Some wait }
571+ when on > 0 && off > 0 && wait > 0 -> on, off, wait
572+ | _ -> 0 , 0 , 0
573+
574+ // do not use the default colors for cursor
575+ let colorf = if hlid = 0 then GetReverseColor else id
576+ let fg , bg , sp = colorf fg, colorf bg, colorf sp
577+
578+ m_ cursor_ vm.typeface <- theme.guifont
579+ m_ cursor_ vm.wtypeface <- theme.guifontwide
580+ m_ cursor_ vm.fontSize <- m_ fontsize
581+ m_ cursor_ vm.text <- text
582+ m_ cursor_ vm.fg <- fg
583+ m_ cursor_ vm.bg <- bg
584+ m_ cursor_ vm.sp <- sp
585+ m_ cursor_ vm.underline <- attrs.underline
586+ m_ cursor_ vm.undercurl <- attrs.undercurl
587+ m_ cursor_ vm.bold <- attrs.bold
588+ m_ cursor_ vm.italic <- attrs.italic
589+ m_ cursor_ vm.cellPercentage <- Option.defaultValue 100 mode.cell_ percentage
590+ m_ cursor_ vm.blinkon <- on
591+ m_ cursor_ vm.blinkoff <- off
592+ m_ cursor_ vm.blinkwait <- wait
593+ m_ cursor_ vm.shape <- Option.defaultValue CursorShape.Block mode.cursor_ shape
594+ m_ cursor_ vm.X <- origin.X
595+ m_ cursor_ vm.Y <- origin.Y
596+ m_ cursor_ vm.Width <- width
597+ m_ cursor_ vm.Height <- m_ glyphsize.Height
598+ m_ cursor_ vm.RenderTick <- m_ cursor_ vm.RenderTick + 1
599+ //trace _gridid "set cursor info, color = %A %A %A" fg bg sp
600+
601+
602+
597603 member __.CursorGoto id row col =
604+ if id = _ gridid then
605+ m_ cursor_ vm.row <- row
606+ m_ cursor_ vm.col <- col
598607 // translation back to parent
599- if m_ parent.IsSome && id = _ gridid then
608+ if m_ parent.IsSome then
600609 #if DEBUG
601610 trace _ gridid " CursorGoto parent"
602611 #endif
603- m_ cursor_ vm.row <- row
604- m_ cursor_ vm.col <- col
605612 m_ parent.Value.CursorGoto m_ parent.Value.GridId ( row + m_ anchor_ row) ( col + m_ anchor_ col)
606613 // goto me
607- elif id = _ gridid then
614+ else
608615 #if DEBUG
609616 trace _ gridid " CursorGoto me"
610617 #endif
611618 m_ cursor_ vm.focused <- true
612- m_ cursor_ vm.row <- row
613- m_ cursor_ vm.col <- col
614619 this.IsFocused <- true
615- cursorConfig ()
616- // goto my child
617- elif m_ child_ grids.FindIndex( fun x -> x.GridId = id) > - 1 then
618- ()
619- // was me, but not anymore
620- elif m_ cursor_ vm.focused then
621- #if DEBUG
622- trace _ gridid " CursorGoto notme"
623- #endif
624- m_ cursor_ vm.focused <- false
625- m_ cursor_ vm.RenderTick <- m_ cursor_ vm.RenderTick + 1
620+ this.CursorConfig ()
621+ // goto my child
622+ elif m_ child_ grids.FindIndex( fun x -> x.GridId = id) > - 1 then
623+ ()
624+ // was me, but not anymore
625+ elif m_ cursor_ vm.focused then
626+ #if DEBUG
627+ trace _ gridid " CursorGoto notme"
628+ #endif
629+ m_ cursor_ vm.focused <- false
630+ m_ cursor_ vm.RenderTick <- m_ cursor_ vm.RenderTick + 1
626631
627632 member __.ShowPopupMenu grid ( items : CompleteItem []) selected row col =
628633 if m_ parent.IsSome && grid = _ gridid then
0 commit comments