Skip to content

Commit d70d90a

Browse files
author
Yatao Li
committed
Merge branch 'master' into keyboard_layout
2 parents 3014958 + 7f01739 commit d70d90a

File tree

2 files changed

+74
-90
lines changed

2 files changed

+74
-90
lines changed

ViewModels/CursorViewModel.fs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,3 @@ type CursorViewModel(cursorMode: int option) =
3939
hash this.Height ^^^
4040
hash this.Width
4141

42-
member this.VisualChecksum() =
43-
hash this.typeface ^^^
44-
hash this.wtypeface ^^^
45-
hash this.fontSize ^^^
46-
hash this.text ^^^
47-
hash this.fg ^^^
48-
hash this.bg ^^^
49-
hash this.sp ^^^
50-
hash this.underline ^^^
51-
hash this.undercurl ^^^
52-
hash this.bold ^^^
53-
hash this.italic ^^^
54-
hash this.cellPercentage ^^^
55-
hash this.blinkon ^^^
56-
hash this.blinkoff ^^^
57-
hash this.blinkwait ^^^
58-
hash this.shape ^^^
59-
hash this.Width ^^^
60-
hash this.Height ^^^
61-
hash this.X ^^^
62-
hash this.Y

ViewModels/GridViewModel.fs

Lines changed: 74 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)