Print Page | Close Window

[solved] Problem with the "Prev Bookmark"

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Syntax Edit
Forum Description: Topics Related to Codejock Syntax Edit
URL: http://forum.codejock.com/forum_posts.asp?TID=23149
Printed Date: 26 April 2024 at 12:57pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: [solved] Problem with the "Prev Bookmark"
Posted By: Matsu
Subject: [solved] Problem with the "Prev Bookmark"
Date Posted: 04 October 2016 at 4:18am
I'm using ToolkitPro v 17.2 with VisualStudio 2010.

At MDITextEditor.exe in sample.
After open the 100 lines text file, set some book mark(1 line,10 line,20 line,50 line and 90 line),select the last line and click "Prev Bookmark " button then the carret can be moved 10 line, 20 line, 50line and 90 l ine but can't be moved 1 line.

Thanks.



Replies:
Posted By: olebed
Date Posted: 07 October 2016 at 10:37am
Hello Matsu,

Thank you for information. Problem in method CXTPSyntaxEditCtrl::PrevBookmark().

I also found issue with CXTPSyntaxEditCtrl::NextBookmark()  - if cursor is in some invisible top line (but with bottom lines works fine)  then it start searching next bookmark from first visible line.

I have added this issue to our bugs base.

Regards,
 Oleksandr Lebed


Posted By: olebed
Date Posted: 04 November 2017 at 12:26am
Hello Matsu,

I'm finally finish this task!
Problem was in changing range of return values of method CXTPSyntaxEditCtrl::CalculateVisibleRow() some time ago. PrevBookmark() and NextBookmark() expected negative values for rows which are before visible rows. After changes there no difference between first visible row (relative number '1') and any row which higher than first visible row - CalculateVisibleRow() returns also '1'.

I have found out that only PrevBookmark() and NextBookmark()  need these negative values, so we need to add new method.
int CXTPSyntaxEditCtrl::CalculateVisibleRow(int nStartDocumentRow, int nDocumentRow)
{
    return max(CalculateVisibleRow_(nStartDocumentRow, nDocumentRow), 1);
}

int CXTPSyntaxEditCtrl::CalculateVisibleRow_(int nStartDocumentRow, int nDocumentRow)
{
    int nVisRow = nDocumentRow - nStartDocumentRow + 1;
    int nNextCollapsedRow = nStartDocumentRow - 1;
    const int nRowCount = GetRowCount();

    POSITION pos = GetLineMarksManager()->FindNextLineMark(nNextCollapsedRow, xtpEditLMT_Collapsed);
    while (pos != NULL)
    {
        XTP_EDIT_LMDATA* pData = GetLineMarksManager()->GetNextLineMark(pos, xtpEditLMT_Collapsed);
        if (pData && pData->m_nRow >= nNextCollapsedRow) // mark should be not within previous collapsed block
        {
            if (pData->m_nRow >= nDocumentRow) // finish if mark is greater then row to calculate for
                break;

            XTP_EDIT_COLLAPSEDBLOCK* pCoDBlk = (XTP_EDIT_COLLAPSEDBLOCK*)pData->m_Param.GetPtr();
            if (!pCoDBlk)
                continue;

            int nBlkEnd = min(nRowCount, pCoDBlk->collBlock.lcEnd.nLine);
            if (nBlkEnd > nDocumentRow)
                nBlkEnd = nDocumentRow;        // DocumentRow in invisible(collapsed) block
            
            int nHiddenRows = nBlkEnd - pCoDBlk->collBlock.lcStart.nLine;

            nVisRow -= nHiddenRows;
            nNextCollapsedRow = pData->m_nRow + nHiddenRows;
        }
    }
    return nVisRow;
}

void CXTPSyntaxEditCtrl::PrevBookmark()
{
    CXTPSyntaxEditLineMarksManager* pMgr = GetLineMarksManager();
    if (!pMgr)
    {
        ASSERT(FALSE);
        return;
    }
    int nRow = GetCurRow();
    int nVisRow = CalculateVisibleRow_(m_nTopRow, GetCurrentDocumentRow());

    // move up to the prev bookmark before the current collapsed block area
    int nPrevRow = nRow;
    do {
        pMgr->FindPrevLineMark(--nPrevRow, xtpEditLMT_Bookmark);
    } while (nPrevRow > 0 && CalculateVisibleRow_(m_nTopRow, nPrevRow) == nVisRow);

    if (nPrevRow < 0)
    {
        POSITION posLast = pMgr->GetLastLineMark(xtpEditLMT_Bookmark);
        XTP_EDIT_LMDATA* pData = pMgr->GetLineMarkAt(posLast, xtpEditLMT_Bookmark);
        nPrevRow = pData ? pData->m_nRow : -1;
    }
    if (CalculateVisibleRow_(m_nTopRow, nPrevRow) == nVisRow)
    {
        nPrevRow = -1;
    }

    if (nPrevRow >= 0)
    {
        SetCurPos(nPrevRow, 1);

        Invalidate(FALSE);
    }
}

void CXTPSyntaxEditCtrl::NextBookmark()
{
    CXTPSyntaxEditLineMarksManager* pMgr = GetLineMarksManager();
    if (!pMgr)
    {
        ASSERT(FALSE);
        return;
    }

    int nRow = GetCurRow();
    int nVisRow = CalculateVisibleRow_(m_nTopRow, GetCurrentDocumentRow());

    // move down to the next bookmark after the current collapsed block area
    int nNextRow = nRow;
    do {
        pMgr->FindNextLineMark(++nNextRow, xtpEditLMT_Bookmark);
    } while (nNextRow > 0 && CalculateVisibleRow_(m_nTopRow, nNextRow) == nVisRow);

    if (nNextRow < 0)
    {
        // find first line mark
        POSITION posFirst = pMgr->GetFirstLineMark(xtpEditLMT_Bookmark);
        XTP_EDIT_LMDATA* pData = pMgr->GetNextLineMark(posFirst, xtpEditLMT_Bookmark);
        nNextRow = pData ? pData->m_nRow : -1;
    }

    if (CalculateVisibleRow_(m_nTopRow, nNextRow) == nVisRow)
    {
        nNextRow = -1;
    }

    if (nNextRow >= 0)
    {
        SetCurPos(nNextRow, 1);

        Invalidate(FALSE);
    }
}

Also as you can see in new CalculateVisibleRow_() I have fixed navigation by bookmarks when bookmark within collapsed block. Before this cursor was set under collapsed block, not on it's own line.

Unfortunately I'm not sure that this fix will be included in the nearest release.

Regards,
 Oleksandr Lebed



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net