Skip to content

Commit

Permalink
attempt to fix #91
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Feb 15, 2020
1 parent 674e863 commit c120939
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ViewModels/EditorViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ type EditorViewModel(GridId: int, ?parent: EditorViewModel, ?_gridsize: GridSize
let editorSize = this.GetPoint m_gridsize.rows m_gridsize.cols

m_popupmenu_vm.Selection <- selected
m_popupmenu_vm.SetItems(items, Rect(startPos, cursorPos), m_glyphsize.Height, bounds, editorSize)
m_popupmenu_vm.SetItems(items, startPos, cursorPos, m_glyphsize.Height, bounds, editorSize)
m_popupmenu_vm.Show <- true

let redraw(cmd: RedrawCommand) =
Expand Down
52 changes: 39 additions & 13 deletions ViewModels/PopupMenuViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type PopupMenuViewModel() =
ignore <| this.RaiseAndSetIfChanged(&m_fontFamily, Avalonia.Media.FontFamily(fontfamily), "FontFamily")
ignore <| this.RaiseAndSetIfChanged(&m_fontSize, fontsize, "FontSize")

member this.SetItems(items: CompleteItem[], textArea: Rect, lineHeight: float, desiredSizeVec: Point, editorSizeVec: Point) =
member this.SetItems(items: CompleteItem[], startPos: Point, cursorPos: Point, lineHeight: float, desiredSizeVec: Point, editorSizeVec: Point) =
m_items.Clear()

// New completion items coming in while old still being added?
Expand All @@ -69,24 +69,50 @@ type PopupMenuViewModel() =
let y = min editorSizeVec.Y (max 0.0 vec.Y)
Point(x, y)

let lineArea = Rect(startPos, cursorPos)

let padding = Point(20.0 + 36.0, 16.0) // extra 36 for icons etc

let se_topleft = textArea.BottomLeft
let se_topleft = lineArea.BottomLeft
let se_bottomright = _cap(se_topleft + desiredSizeVec + padding)

let ne_topleft = _cap(textArea.TopLeft - Point(0.0, desiredSizeVec.Y) - padding)
let ne_bottomright = _cap(textArea.TopLeft + Point(desiredSizeVec.X, 0.0))
let ne_topleft = _cap(lineArea.TopLeft - Point(0.0, desiredSizeVec.Y + padding.Y))
let ne_bottomright = _cap(lineArea.TopLeft + Point(desiredSizeVec.X + padding.X, 0.0))

let sw_topleft = _cap(lineArea.BottomRight - Point(desiredSizeVec.X + padding.X, 0.0))
let sw_bottomright = _cap(lineArea.BottomRight + Point(0.0, desiredSizeVec.Y + padding.Y))

let nw_bottomright = lineArea.TopRight
let nw_topleft = _cap(nw_bottomright - desiredSizeVec - padding)

let r_se = Rect(se_topleft, se_bottomright)
let r_ne = Rect(ne_topleft, ne_bottomright)

let region =
if r_se.Height > desiredSizeVec.Y / 3.0 || r_se.Height > r_ne.Height then
trace "choose region SE: %A" r_se
r_se
else
trace "choose region NE: %A" r_ne
r_ne
let r_sw = Rect(sw_topleft, sw_bottomright)
let r_nw = Rect(nw_topleft, nw_bottomright)

let r_e =
if r_se.Height > desiredSizeVec.Y / 3.0 || r_se.Height > r_ne.Height then
trace "r_e: choose region SE: %A" r_se
r_se
else
trace "r_e: choose region NE: %A" r_ne
r_ne

let r_w =
if r_sw.Height > desiredSizeVec.Y / 3.0 || r_sw.Height > r_nw.Height then
trace "r_w: choose region SW: %A" r_sw
r_sw
else
trace "r_w: choose region NW: %A" r_nw
r_nw

let region =
if r_e.Width > desiredSizeVec.X * 0.75 || r_e.Width > r_w.Width then
trace "region: choose region EAST: %A" r_e
r_e
else
trace "region: choose region WEST: %A" r_w
r_w

this.X <- region.X
this.Y <- region.Y
Expand All @@ -102,7 +128,7 @@ type PopupMenuViewModel() =
|> Array.chunkBySize 16

m_cancelSrc <- new CancellationTokenSource()
m_cancelSrc.CancelAfter(100)
m_cancelSrc.CancelAfter(200)
let token = m_cancelSrc.Token
let asyncAdd = async {
for chunk in chunks do
Expand Down

0 comments on commit c120939

Please sign in to comment.