Skip to content

Commit

Permalink
Fix that the background color of the more frontal float window is not…
Browse files Browse the repository at this point in the history
… painted if the overlapping float windows have the same background color.
  • Loading branch information
akiyosi committed Feb 12, 2024
1 parent 10cb46a commit f5dcc09
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
15 changes: 13 additions & 2 deletions editor/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ func (s *Screen) setHlAttrDef(args []interface{}) {

for _, arg := range args {
id := util.ReflectToInt(arg.([]interface{})[0])
h[id] = s.getHighlight(arg)
h[id] = s.makeHighlight(arg)
}

if s.hlAttrDef == nil {
Expand Down Expand Up @@ -1106,7 +1106,7 @@ func (s *Screen) setHighlightGroup(args []interface{}) {
}
}

func (s *Screen) getHighlight(args interface{}) *Highlight {
func (s *Screen) makeHighlight(args interface{}) *Highlight {
arg := args.([]interface{})
highlight := Highlight{}

Expand Down Expand Up @@ -1237,6 +1237,17 @@ func (s *Screen) getHighlight(args interface{}) *Highlight {
return &highlight
}

func (s *Screen) getHighlight(name string, hex string) (hl *Highlight) {
for _, h := range s.hlAttrDef {
if h.uiName == name && h.bg().Hex() == hex {
hl = h
break
}
}

return
}

func (s *Screen) gridClear(args []interface{}) {
var gridid gridId
for _, arg := range args {
Expand Down
36 changes: 33 additions & 3 deletions editor/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ type inputMouseEvent struct {
type zindex struct {
value int
order int

nearestLowerZOrderWindow *Window
}

// Window is
Expand Down Expand Up @@ -1786,7 +1788,12 @@ func (w *Window) drawBackground(p *gui.QPainter, y int, col int, cols int) {
isDrawDefaultBg := false
if w.isFloatWin || w.isMsgGrid {
// If transparent is true, then we should draw every cell's background color
if editor.config.Editor.Transparent < 1.0 || editor.config.Message.Transparent < 1.0 {
if w.isFloatWin && editor.config.Editor.Transparent < 1.0 {
w.SetAutoFillBackground(false)
isDrawDefaultBg = true
}

if w.isMsgGrid && editor.config.Message.Transparent < 1.0 {
w.SetAutoFillBackground(false)
isDrawDefaultBg = true
}
Expand Down Expand Up @@ -1928,6 +1935,19 @@ func (w *Window) fillCellRect(p *gui.QPainter, lastHighlight *Highlight, lastBg
return
}

// If the background color to be painted is a Normal highlight group and another float window
// that covers the float window and is closest in z-order has the same background color,
// the background color should not be painted.
if w.isFloatWin && !w.isMsgGrid {
if w.zindex.nearestLowerZOrderWindow != nil && w.zindex.nearestLowerZOrderWindow.isFloatWin {
if lastHighlight.uiName == "NormalFloat" || lastHighlight.uiName == "NormalNC" {
if w.s.getHighlight("Normal", lastHighlight.bg().Hex()) != nil {
return
}
}
}
}

width := end - start + 1
if width < 0 {
width = 0
Expand Down Expand Up @@ -3187,8 +3207,18 @@ func (w *Window) raise() {
return false
},
)
for _, win := range floatWins {
win.Raise()

// For each window object, set the pointer of closest window in the z-order
// that covers the target window on the region.
for i := 1; i < len(floatWins); i++ {
if i > 0 {
for j := i - 1; j >= 0; j-- {
if floatWins[j].Geometry().Contains2(floatWins[i].Geometry(), false) {
floatWins[i].zindex.nearestLowerZOrderWindow = floatWins[j]
}
}
}
floatWins[i].Raise()
}

// handle cursor widget
Expand Down

0 comments on commit f5dcc09

Please sign in to comment.