Skip to content

Commit

Permalink
track out-of-bound widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
yatli committed Sep 24, 2021
1 parent 96fe49d commit 6619106
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 16 additions & 1 deletion ViewModels/GridViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
let mutable m_scrollbar_row = 0
let mutable m_scrollbar_col = 0
let mutable m_scrollbar_linecount = 0
let mutable m_extmarks = hashmap[] // tracks existing extmarks and last known position -- some may be scrolled out of viewport
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
let mutable m_extmarks_oob = hashmap[] // tracks existing off-screen extmarks and last known position
let m_gridComparer = GridViewModel.MakeGridComparer() :> IComparer<GridViewModel>

let raiseInputEvent id e = m_input_ev.Trigger(id, e)
Expand Down Expand Up @@ -244,6 +245,7 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
for _,cell,_ in m_extmarks.Values do
cell.marks <- []
m_extmarks.Clear()
m_extmarks_oob.Clear()
#if DEBUG
trace _gridid $"clearMarks"
#endif
Expand Down Expand Up @@ -335,6 +337,9 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
// remove dst row marks
for m in dst_cell.marks do
m_extmarks.Remove m.mark |> ignore
if dst < src then
let oob_pos = {trow = dst - (src - dst); tcol = c}
m_extmarks_oob.[m.mark] <- (m, oob_pos)
dst_cell.marks <- []

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

let _removeOob = ResizeArray()
let setWinViewport win top bot row col lc =
let delta = top - m_scrollbar_top
_removeOob.Clear()
for mark,trackpos in m_extmarks_oob.Values do
trackpos.trow <- trackpos.trow - delta
if trackpos.trow >= 0 then
_removeOob.Add(mark.mark)
for m in _removeOob do
ignore <| m_extmarks_oob.Remove(m)
m_winhnd <- win
m_scrollbar_top <- top
m_scrollbar_bot <- bot
Expand Down Expand Up @@ -782,6 +796,7 @@ and GridViewModel(_gridid: int, ?_parent: GridViewModel, ?_gridsize: GridSize) a
member __.IsMsg = m_is_msg
member __.BufNr = m_bufnr
member __.Extmarks = m_extmarks
member __.ExtmarksOob = m_extmarks_oob
member __.FindTargetWidget (r: int) (c: int) (pred: WidgetPlacement -> bool) =
if this.AboveGadgets then -1 else
let placements = getGuiWidgetPlacements m_bufnr
Expand Down
11 changes: 7 additions & 4 deletions Views/Grid.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,8 @@ type Grid() as this =

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

// scrollbar
Expand Down

0 comments on commit 6619106

Please sign in to comment.