Skip to content

Commit

Permalink
crystaledit: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Dec 2, 2023
1 parent 4e2ab96 commit 2c866f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
8 changes: 3 additions & 5 deletions Externals/crystaledit/editlib/ccrystaltextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3183,16 +3183,15 @@ 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;

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 };
}

/**
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Externals/crystaledit/editlib/ccrystaltextview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions Externals/crystaledit/editlib/ccrystaltextview2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c866f7

Please sign in to comment.