From: Laurent Ganier Date: Wed, 16 Jul 2003 11:44:59 +0000 (+0000) Subject: [ 771503 ] correct UpdateView context in internalInsertText X-Git-Tag: 2.16.5~7928 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=34f1d88a641fe4ae7e121fcfce03098a117e83dd;p=winmerge-jp%2Fwinmerge-jp.git [ 771503 ] correct UpdateView context in internalInsertText --- diff --git a/Src/editlib/ccrystaltextbuffer.cpp b/Src/editlib/ccrystaltextbuffer.cpp index 2df927516..b6b828f56 100644 --- a/Src/editlib/ccrystaltextbuffer.cpp +++ b/Src/editlib/ccrystaltextbuffer.cpp @@ -1116,6 +1116,7 @@ InternalInsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR psz } + int nInsertedLines = 0; int nCurrentLine = nLine; BOOL bNewLines = FALSE; int nTextPos; @@ -1149,6 +1150,7 @@ InternalInsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR psz else { InsertLine (pszText, nTextPos, nCurrentLine); + nInsertedLines ++; bNewLines = TRUE; } @@ -1167,10 +1169,13 @@ InternalInsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR psz nEndLine = nCurrentLine; nEndChar = GetLineLength(nEndLine); } - if (!sTail.IsEmpty()) + if (!sTail.IsEmpty()) { if (haseol) + { InsertLine(sTail, -1, nEndLine); + nInsertedLines ++; + } else AppendLine (nCurrentLine, sTail, nRestCount); } @@ -1180,6 +1185,7 @@ InternalInsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR psz // which is an illegal cursor position // so manufacture a new trailing ghost line InsertLine(_T("")); + nInsertedLines ++; } break; } @@ -1188,8 +1194,20 @@ InternalInsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR psz pszText += nTextPos; } - context.m_ptEnd.x = nEndChar; - context.m_ptEnd.y = nEndLine; + // if we insert in a ghost line, with a pszText which is EOL finished, + // we create just (nEndLine-nLine-1) lines and not (nEndLine-nLine) lines + // the cursor, because of EOL terminated pszText, falls one line below, + // but the real text limit is (nEndLine-1, GetFullLineLength(nEndLine-1)) + if (nEndLine - nLine != nInsertedLines) + { + context.m_ptEnd.y = nEndLine-1; + context.m_ptEnd.x = GetFullLineLength(nEndLine-1); + } + else + { + context.m_ptEnd.x = nEndChar; + context.m_ptEnd.y = nEndLine; + } if (nLine != nEndLine) { @@ -1198,18 +1216,19 @@ InternalInsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR psz } if (pSource!=NULL) - { - if (bNewLines) - UpdateViews (pSource, &context, UPDATE_HORZRANGE | UPDATE_VERTRANGE, nLine); - else - UpdateViews (pSource, &context, UPDATE_SINGLELINE | UPDATE_HORZRANGE, nLine); - } + { + if (bNewLines) + UpdateViews (pSource, &context, UPDATE_HORZRANGE | UPDATE_VERTRANGE, nLine); + else + UpdateViews (pSource, &context, UPDATE_SINGLELINE | UPDATE_HORZRANGE, nLine); + } if (!m_bModified) SetModified (TRUE); //BEGIN SW // remember current cursor position as last editing position - m_ptLastChange = context.m_ptEnd; + m_ptLastChange.x = nEndChar; + m_ptLastChange.y = nEndLine; //END SW return TRUE; } diff --git a/Src/readme.txt b/Src/readme.txt index be7d858ef..cbb64101a 100644 --- a/Src/readme.txt +++ b/Src/readme.txt @@ -1,3 +1,7 @@ +2003-07-16 Laoran + PATCH: [ 771503 ] correct UpdateView context in internalInsertText + editlib: ccrystaltextbuffer.cpp + 2003-07-16 Kimmo PATCH: [ 768740 ] Additional color options Submitted by Gilbert Wellisch