From f1c1f93bd72c89fc44165a163d50fd249bb0e78d Mon Sep 17 00:00:00 2001 From: aarzilli Date: Mon, 23 Jan 2017 16:01:06 +0100 Subject: [PATCH] discard one frame the first time a contextual window is shown --- context.go | 45 ++++++++++++++++++++++++++------------------- nucular.go | 4 ++++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/context.go b/context.go index 19b8b76..24d442a 100644 --- a/context.go +++ b/context.go @@ -26,6 +26,7 @@ type context struct { changed int32 activateEditor *TextEditor cmds []command.Command + trashFrame bool } func contextAllCommands(ctx *context) { @@ -46,31 +47,36 @@ func (ctx *context) setupMasterWindow(layout *panel, updatefn UpdateFn) { } func (ctx *context) Update() { - contextBegin(ctx, ctx.Windows[0].layout) - for i := 0; i < len(ctx.Windows); i++ { - ctx.Windows[i].began = false - } - for i := 0; i < len(ctx.Windows); i++ { // this must not use range or tooltips won't work - win := ctx.Windows[i] - if win.updateFn != nil { - win.specialPanelBegin() - win.updateFn(win) + for count := 0; count < 2; count++ { + contextBegin(ctx, ctx.Windows[0].layout) + for i := 0; i < len(ctx.Windows); i++ { + ctx.Windows[i].began = false } + for i := 0; i < len(ctx.Windows); i++ { // this must not use range or tooltips won't work + win := ctx.Windows[i] + if win.updateFn != nil { + win.specialPanelBegin() + win.updateFn(win) + } - if !win.began { - win.close = true - continue - } + if !win.began { + win.close = true + continue + } - if win.title == tooltipWindowTitle { - win.close = true - } + if win.title == tooltipWindowTitle { + win.close = true + } - if win.flags&windowPopup != 0 { - panelEnd(ctx, win) + if win.flags&windowPopup != 0 { + panelEnd(ctx, win) + } + } + contextEnd(ctx) + if !ctx.trashFrame { + break } } - contextEnd(ctx) } func contextBegin(ctx *context, layout *panel) { @@ -82,6 +88,7 @@ func contextBegin(ctx *context, layout *panel) { w.cmds.Reset() } + ctx.trashFrame = false ctx.Windows[0].layout = layout panelBegin(ctx, ctx.Windows[0], "") layout.Offset = &ctx.Windows[0].Scrollbar diff --git a/nucular.go b/nucular.go index 4079d1b..a91af00 100644 --- a/nucular.go +++ b/nucular.go @@ -509,6 +509,10 @@ func (win *Window) specialPanelBegin() { win.layout.Offset = &win.Scrollbar } + if win.first && (win.flags&windowContextual != 0 || win.flags&windowHDynamic != 0) { + ctx.trashFrame = true + } + win.first = false }