scrollCursorToCenterIfHidden checks if the cursor is not visible, and if so, scrolls to the center, along both dimensions.
()
| 845 | // scrollCursorToCenterIfHidden checks if the cursor is not visible, and if |
| 846 | // so, scrolls to the center, along both dimensions. |
| 847 | func (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 |
no test coverage detected