From 2c866f7f95c80564148dc870c772928d0d952d44 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sat, 2 Dec 2023 13:48:04 +0900 Subject: [PATCH] crystaledit: refactor --- Externals/crystaledit/editlib/ccrystaltextview.cpp | 8 +++----- Externals/crystaledit/editlib/ccrystaltextview.h | 4 ++-- Externals/crystaledit/editlib/ccrystaltextview2.cpp | 11 +++++------ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Externals/crystaledit/editlib/ccrystaltextview.cpp b/Externals/crystaledit/editlib/ccrystaltextview.cpp index 485ed109ced..4f076db3fb0 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview.cpp @@ -3183,7 +3183,7 @@ int CCrystalTextView::CursorPointToCharPos( int nLineIndex, const CEPoint &curPo return nIndex; } -void CCrystalTextView::SubLineCursorPosToTextPos( const CEPoint &subLineCurPos, CEPoint &textPos ) +CEPoint CCrystalTextView::SubLineCursorPosToTextPos( const CEPoint &subLineCurPos ) { // Get line breaks int nSubLineOffset, nLine; @@ -3191,8 +3191,7 @@ void CCrystalTextView::SubLineCursorPosToTextPos( const CEPoint &subLineCurPos, GetLineBySubLine( subLineCurPos.y, nLine, nSubLineOffset ); // compute cursor-position - textPos.x = CursorPointToCharPos( nLine, CEPoint( subLineCurPos.x, nSubLineOffset ) ); - textPos.y = nLine; + return { CursorPointToCharPos(nLine, CEPoint(subLineCurPos.x, nSubLineOffset)), nLine }; } /** @@ -3980,8 +3979,7 @@ OnSize (UINT nType, int cx, int cy) //BEGIN SW // get char position of top left visible character with old cached word wrap - CEPoint topPos; - SubLineCursorPosToTextPos( CEPoint( 0, m_nTopSubLine ), topPos ); + CEPoint topPos = SubLineCursorPosToTextPos( CEPoint( 0, m_nTopSubLine ) ); //END SW //BEGIN SW diff --git a/Externals/crystaledit/editlib/ccrystaltextview.h b/Externals/crystaledit/editlib/ccrystaltextview.h index e8825d6b6bd..2f01fd717bc 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview.h +++ b/Externals/crystaledit/editlib/ccrystaltextview.h @@ -369,10 +369,10 @@ protected : @param subLinePos The sublinebased cursor position (see text above for detailed description). - @param textPos The calculated line and character position that best matches + @return The calculated line and character position that best matches the cursor position (see text above for detailed descritpion). */ - void SubLineCursorPosToTextPos( const CEPoint &subLinePos, CEPoint &textPos ); + CEPoint SubLineCursorPosToTextPos( const CEPoint &subLinePos ); /** Returns the character position relative to the given line, that matches diff --git a/Externals/crystaledit/editlib/ccrystaltextview2.cpp b/Externals/crystaledit/editlib/ccrystaltextview2.cpp index 81866f5f41a..01c04427f5c 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview2.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview2.cpp @@ -225,7 +225,7 @@ MoveUp (bool bSelect) nSubLine--; } while (IsEmptySubLineIndex(nSubLine)); - SubLineCursorPosToTextPos( CEPoint( m_nIdealCharPos, nSubLine ), m_ptCursorPos ); + m_ptCursorPos = SubLineCursorPosToTextPos( CEPoint( m_nIdealCharPos, nSubLine ) ); /*ORIGINAL m_ptCursorPos.y --; m_ptCursorPos.x = ApproxActualOffset(m_ptCursorPos.y, m_nIdealCharPos); @@ -269,7 +269,7 @@ MoveDown (bool bSelect) } while (IsEmptySubLineIndex(nSubLine)); } - SubLineCursorPosToTextPos( CEPoint( m_nIdealCharPos, nSubLine ), m_ptCursorPos ); + m_ptCursorPos = SubLineCursorPosToTextPos( CEPoint( m_nIdealCharPos, nSubLine ) ); /*ORIGINAL m_ptCursorPos.y ++; m_ptCursorPos.x = ApproxActualOffset(m_ptCursorPos.y, m_nIdealCharPos); @@ -362,8 +362,7 @@ MovePgUp (bool bSelect) if ( nSubLine < 0 ) nSubLine = 0; - SubLineCursorPosToTextPos( CEPoint( m_nIdealCharPos, nSubLine ), - m_ptCursorPos ); + m_ptCursorPos = SubLineCursorPosToTextPos( CEPoint( m_nIdealCharPos, nSubLine ) ); m_nIdealCharPos = CalculateActualOffset (m_ptCursorPos.y, m_ptCursorPos.x); EnsureVisible (m_ptCursorPos); //todo: no vertical scroll @@ -404,8 +403,8 @@ MovePgDn (bool bSelect) if( nSubLine > nSubLineCount - 1 ) nSubLine = nSubLineCount - 1; - SubLineCursorPosToTextPos( - CEPoint( m_nIdealCharPos, nSubLine ), m_ptCursorPos ); + m_ptCursorPos = SubLineCursorPosToTextPos( + CEPoint( m_nIdealCharPos, nSubLine ) ); m_nIdealCharPos = CalculateActualOffset (m_ptCursorPos.y, m_ptCursorPos.x); EnsureVisible (m_ptCursorPos); //todo: no vertical scroll