MCPcopy Create free account
hub / github.com/WinMerge/winmerge / GetLineFromYPos

Method GetLineFromYPos

Src/LocationView.cpp:814–849  ·  view source on GitHub ↗

* @brief Calculates view/real line in file from given YCoord in bar. * @param [in] nYCoord ycoord in pane * @param [in] bar bar/file * @param [in] bRealLine `true` if real line is returned, `false` for view line * @return 0-based index of view/real line in file [0...lines-1] */

Source from the content-addressed store, hash-verified

812 * @return 0-based index of view/real line in file [0...lines-1]
813 */
814int CLocationView::GetLineFromYPos(int nYCoord, int bar, bool bRealLine /*= true*/)
815{
816 CMergeEditView *pView = GetDocument()->GetActiveMergeGroupView(bar);
817
818 int nSubLineIndex = (int) (m_pixInLines * (nYCoord - Y_OFFSET));
819
820 // Keep sub-line index in range.
821 if (nSubLineIndex < 0)
822 {
823 nSubLineIndex = 0;
824 }
825 else if (nSubLineIndex >= pView->GetSubLineCount())
826 {
827 nSubLineIndex = pView->GetSubLineCount() - 1;
828 }
829
830 // Find the real (not wrapped) line number from sub-line index.
831 int nLine = 0;
832 int nSubLine = 0;
833 pView->GetLineBySubLine(nSubLineIndex, nLine, nSubLine);
834
835 // Convert line number to line index.
836 if (nLine > 0)
837 {
838 nLine -= 1;
839 }
840
841 // We've got a view line now
842 if (!bRealLine)
843 return nLine;
844
845 // Get real line (exclude ghost lines)
846 CMergeDoc* pDoc = GetDocument();
847 const int nRealLine = pDoc->m_ptBuf[bar]->ComputeRealLine(nLine);
848 return nRealLine;
849}
850
851/**
852 * @brief Determines if given coords are inside left/right bar.

Callers

nothing calls this directly

Calls 4

GetSubLineCountMethod · 0.80
GetLineBySubLineMethod · 0.80
ComputeRealLineMethod · 0.45

Tested by

no test coverage detected