MCPcopy Create free account
hub / github.com/cogentcore/core / scrollCursorToCenterIfHidden

Method scrollCursorToCenterIfHidden

texteditor/nav.go:847–872  ·  view source on GitHub ↗

scrollCursorToCenterIfHidden checks if the cursor is not visible, and if so, scrolls to the center, along both dimensions.

()

Source from the content-addressed store, hash-verified

845// scrollCursorToCenterIfHidden checks if the cursor is not visible, and if
846// so, scrolls to the center, along both dimensions.
847func (ed *Editor) scrollCursorToCenterIfHidden() bool {
848 curBBox := ed.cursorBBox(ed.CursorPos)
849 did := false
850 lht := int(ed.lineHeight)
851 bb := ed.renderBBox()
852 if bb.Size().Y <= lht {
853 return false
854 }
855 if (curBBox.Min.Y-lht) < bb.Min.Y || (curBBox.Max.Y+lht) > bb.Max.Y {
856 did = ed.scrollCursorToVerticalCenter()
857 // fmt.Println("v min:", curBBox.Min.Y, bb.Min.Y, "max:", curBBox.Max.Y+lht, bb.Max.Y, did)
858 }
859 if curBBox.Max.X < bb.Min.X+int(ed.LineNumberOffset) {
860 did2 := ed.scrollCursorToRight()
861 // fmt.Println("h max", curBBox.Max.X, bb.Min.X+int(ed.LineNumberOffset), did2)
862 did = did || did2
863 } else if curBBox.Min.X > bb.Max.X {
864 did2 := ed.scrollCursorToRight()
865 // fmt.Println("h min", curBBox.Min.X, bb.Max.X, did2)
866 did = did || did2
867 }
868 if did {
869 // fmt.Println("scroll to center", did)
870 }
871 return did
872}
873
874///////////////////////////////////////////////////////////////////////////////
875// Scrolling -- Vertical

Callers 11

iSearchSelectMatchMethod · 0.95
qReplaceSelectMatchMethod · 0.95
qReplaceReplaceMethod · 0.95
SetCursorShowMethod · 0.95
CursorToHistoryPrevMethod · 0.95
CursorToHistoryNextMethod · 0.95
cursorBackspaceMethod · 0.95
cursorBackspaceWordMethod · 0.95
undoMethod · 0.95
redoMethod · 0.95
setCursorFromMouseMethod · 0.95

Calls 5

cursorBBoxMethod · 0.95
renderBBoxMethod · 0.95
scrollCursorToRightMethod · 0.95
SizeMethod · 0.65

Tested by

no test coverage detected