text after a bookmark is hidden (load+save cursor position)

  • I'm using a 'hidden' bookmark as a cursor starting point in my document. The first time the document is loaded, I attempt to move to that bookmark and if I do, I delete the bookmark. The user can then start typing at that position. Works fine mostly.

    However, I've had a few documents crop up where, when reviewing them, only part of the text was visible. After looking at the rtf code we found that the bookmark code was still there somehow, so we deleted it manually, and now all the text shows up normally.

    Is there a reason that all the text after, and not neccesarily within, a bookmark would be hidden?

  • Also, the BookMarkAttr is set to hidden as is the InsertPointAttr

    Turning showInvisibleText to true does allow us to see past the bookmark and shows the rest of the text. It also shows the insert points, which is bad.

    So, somehow, the text after the bookmark is inheriting the hidden status.

    • Offizieller Beitrag

    There is never 'one bookmark' - this are always two - using BookMarkTextAttr.Hidden hides the text between them. Bookmarks (the code objects) usually are hidden - you can make them visible in property ViewOptions.

    For what you need using bookmarks is overkill. You could do something like
    CurrAttr.AddStyle([afsHidden]);
    WPRichText1.InputString('@@CP@@');
    CurrAttr.DeleteStyle([afsHidden]);

    and delete the next using Finder.Next('@@CP@@')
    , FoundText := ''
    after you loaded the document.

    or, much better, and much easier to
    before save:

    Code
    WPRichText1.RTFVariables.Strings['CursorPos'] :=   IntToStr(WPRichText1.CPPosition);


    after load:

    Code
    WPRichText1.CPPosition := 
      StrToIntDef( WPRichText1.RTFVariables.Strings['CursorPos'],0);


    Please note that WPTools can save and load the selection markers without any additional code - see Header.StoreOptions.

    Julian

  • This seems to work, but there is one problem. My startpoints are generally going to be after some merged text so the actual cursor position seems to be getting skewed because of that. IE the cursor moves to a position in the document that isn't expected. I've checked that the cursorpos number is loading correctly, it's just moving the cursor to the wrong place.