void JoeAutoCorrect::MyReturnSelected(BOOL bAdjust)
{
if (m_nHighLightLine < 0 || !m_bHighLight)
return;
// I have to cast parentwnd to my own edit control override and friend me to get to all the calls
int nCurrentRow = ((MyEditCtrl *)m_pParentWnd)->GetCurrentDocumentRow();
CString strRet = m_arrACDataFiltered.GetAt(m_nHighLightLine)->m_strText;
if (m_strTmpCloseTag.GetLength() > 0)
{
// strRet += m_strTmpCloseTag; // this is the line I commented out to make it not ((
m_strTmpCloseTag = _T("");
}
else if (bAdjust)
{
strRet = strRet.Left(strRet.GetLength() - 1);
m_nEndReplacePos = max(m_nStartReplacePos, m_nEndReplacePos - 1);
}
m_pParentWnd->Select(nCurrentRow, m_nStartReplacePos, nCurrentRow, m_nEndReplacePos,FALSE);
// begin revisions
CString selText; // up to now, except for bug fix, this was the same. Here through replaceSel we differ
((MyEditCtrl *)m_pParentWnd)->GetSelectionText(selText); // get the current text we are about to replace
int len = selText.GetLength(); // get the length of what was typed so far - could just be ma for Math, for example
if (len > 0 && strRet.Left(len).CompareNoCase(selText) != 0) // if they differ only in case or length, go ahead and accept it
strRet = selText; // otherwise, put the old selected text back in. So if they type 'maw', for example, then they end autocorrect, just accept the 'maw' typing so far.
// end revisions
m_pParentWnd->ReplaceSel(strRet);
m_pParentWnd->SetCurCaretPos(((MyEditCtrl *)m_pParentWnd)->GetCurrentDocumentRow(), ((MyEditCtrl *)m_pParentWnd)->m_nDispCol);
((MyEditCtrl *)m_pParentWnd)->SetDocModified();
}