Skip to content

Commit 6619106

Browse files
author
Yatao Li
committed
track out-of-bound widgets
1 parent 96fe49d commit 6619106

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

ViewModels/GridViewModel.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
8686
let mutable m_scrollbar_row = 0
8787
let mutable m_scrollbar_col = 0
8888
let mutable m_scrollbar_linecount = 0
89-
let mutable m_extmarks = hashmap[] // tracks existing extmarks and last known position -- some may be scrolled out of viewport
89+
let mutable m_extmarks = hashmap[] // tracks existing on-screen extmarks and last known position -- some may be scrolled out of viewport, and moved into oob
90+
let mutable m_extmarks_oob = hashmap[] // tracks existing off-screen extmarks and last known position
9091
let m_gridComparer = GridViewModel.MakeGridComparer() :> IComparer<GridViewModel>
9192

9293
let raiseInputEvent id e = m_input_ev.Trigger(id, e)
@@ -244,6 +245,7 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
244245
for _,cell,_ in m_extmarks.Values do
245246
cell.marks <- []
246247
m_extmarks.Clear()
248+
m_extmarks_oob.Clear()
247249
#if DEBUG
248250
trace _gridid $"clearMarks"
249251
#endif
@@ -335,6 +337,9 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
335337
// remove dst row marks
336338
for m in dst_cell.marks do
337339
m_extmarks.Remove m.mark |> ignore
340+
if dst < src then
341+
let oob_pos = {trow = dst - (src - dst); tcol = c}
342+
m_extmarks_oob.[m.mark] <- (m, oob_pos)
338343
dst_cell.marks <- []
339344

340345
if rows > 0 then
@@ -419,7 +424,16 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
419424
(this:>IGridUI).Detach()
420425
CreateFrame this
421426

427+
let _removeOob = ResizeArray()
422428
let setWinViewport win top bot row col lc =
429+
let delta = top - m_scrollbar_top
430+
_removeOob.Clear()
431+
for mark,trackpos in m_extmarks_oob.Values do
432+
trackpos.trow <- trackpos.trow - delta
433+
if trackpos.trow >= 0 then
434+
_removeOob.Add(mark.mark)
435+
for m in _removeOob do
436+
ignore <| m_extmarks_oob.Remove(m)
423437
m_winhnd <- win
424438
m_scrollbar_top <- top
425439
m_scrollbar_bot <- bot
@@ -782,6 +796,7 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
782796
member __.IsMsg = m_is_msg
783797
member __.BufNr = m_bufnr
784798
member __.Extmarks = m_extmarks
799+
member __.ExtmarksOob = m_extmarks_oob
785800
member __.FindTargetWidget (r: int) (c: int) (pred: WidgetPlacement -> bool) =
786801
if this.AboveGadgets then -1 else
787802
let placements = getGuiWidgetPlacements m_bufnr

Views/Grid.xaml.fs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,8 @@ type Grid() as this =
364364

365365
// gui widgets
366366
let placements = getGuiWidgetPlacements vm.BufNr
367-
let drawGuiWidgets ({ns = ns; mark = mark}, cell: GridBufferCell, {trow=r;tcol=c}) =
368-
// if cell.marks does not have this mark, it means cell has scrolled out of view.
369-
if ns = guiwidgetNamespace && cell.ContainsMark mark then
367+
let drawGuiWidgets ({ns = ns; mark = mark}, {trow=r;tcol=c}) =
368+
if ns = guiwidgetNamespace then
370369
match (placements.TryGetValue mark) with
371370
| false, _ -> ()
372371
| true, ({widget=wid; w=grid_w; h=grid_h} as p) ->
@@ -408,7 +407,11 @@ type Grid() as this =
408407
let text = FormattedText(text, font, size, TextAlignment.Left, TextWrapping.Wrap, bounds.Size)
409408
ctx.DrawText(m_gadget_brush, bounds.TopLeft, text)
410409
| _ -> ()
411-
for tup in vm.Extmarks.Values do
410+
for ({mark=mark} as m, cell, pos) in vm.Extmarks.Values do
411+
// if cell.marks does not have this mark, it means cell has scrolled out of view.
412+
if cell.ContainsMark mark then
413+
drawGuiWidgets(m,pos)
414+
for tup in vm.ExtmarksOob.Values do
412415
drawGuiWidgets tup
413416

414417
// scrollbar

0 commit comments

Comments
 (0)