MCPcopy
hub / github.com/jesseduffield/lazygit / SetView

Method SetView

pkg/gocui/gui.go:309–352  ·  view source on GitHub ↗

SetView creates a new view with its top-left corner at (x0, y0) and the bottom-right one at (x1, y1). If a view with the same name already exists, its dimensions are updated; otherwise, the error ErrUnknownView is returned, which allows to assert if the View must be initialized. It checks if the pos

(name string, x0, y0, x1, y1 int, overlaps byte)

Source from the content-addressed store, hash-verified

307// ErrUnknownView is returned, which allows to assert if the View must
308// be initialized. It checks if the position is valid.
309func (g *Gui) SetView(name string, x0, y0, x1, y1 int, overlaps byte) (*View, error) {
310 if name == "" {
311 return nil, errors.New("invalid name")
312 }
313
314 if v, err := g.View(name); err == nil {
315 sizeChanged := v.x0 != x0 || v.x1 != x1 || v.y0 != y0 || v.y1 != y1
316
317 v.x0 = x0
318 v.y0 = y0
319 v.x1 = x1
320 v.y1 = y1
321
322 if sizeChanged {
323 v.clearViewLines()
324
325 if v.Editable {
326 cursorX, cursorY := v.TextArea.GetCursorXY()
327 newViewCursorX, newOriginX := updatedCursorAndOrigin(0, v.InnerWidth(), cursorX)
328 newViewCursorY, newOriginY := updatedCursorAndOrigin(0, v.InnerHeight(), cursorY)
329
330 v.SetCursor(newViewCursorX, newViewCursorY)
331 v.SetOrigin(newOriginX, newOriginY)
332 }
333 }
334
335 return v, nil
336 }
337
338 g.Mutexes.ViewsMutex.Lock()
339
340 v := NewView(name, x0, y0, x1, y1, g.outputMode)
341 v.BgColor, v.FgColor = g.BgColor, g.FgColor
342 v.SelBgColor, v.SelFgColor = g.SelBgColor, g.SelFgColor
343 v.Overlaps = overlaps
344 g.views = append(g.views, v)
345
346 v.setOnSelectResult(g.onSelectSearchItem)
347 v.setRenderSearchStatus(g.renderSearchStatus)
348
349 g.Mutexes.ViewsMutex.Unlock()
350
351 return v, errors.Wrap(ErrUnknownView, 0)
352}
353
354func (g *Gui) onSelectSearchItem(v *View, selectedLineIdx int) {
355 if g.onSelectSearchResultFunc != nil {

Callers 11

SetViewBeneathMethod · 0.95
layoutMethod · 0.80
layoutMethod · 0.80
prepareViewMethod · 0.80
resizeMenuMethod · 0.80
resizePromptPanelMethod · 0.80
setupViewsFunction · 0.80

Calls 12

ViewMethod · 0.95
clearViewLinesMethod · 0.95
InnerWidthMethod · 0.95
InnerHeightMethod · 0.95
SetCursorMethod · 0.95
SetOriginMethod · 0.95
setOnSelectResultMethod · 0.95
setRenderSearchStatusMethod · 0.95
updatedCursorAndOriginFunction · 0.85
NewViewFunction · 0.85
GetCursorXYMethod · 0.80
NewMethod · 0.65