Get attributes at current cursor location

  • Delphi 2007
    WPTools 6.16.2

    We have some specialized functions that programmatically move the text cursor around to various locations on a TWPRichText, using the Finder to home in on specific key sequences (Finder.MoveToFoundPositionEnd). The existing text at those locations may be in a variety of formats - e.g plain, bold, italic, specific font faces or sizes, etc.

    We have a problem where, for example, the text cursor jumps to a location where the text is bold...

    This is some bold text

    Newly typed text at that location however is not bold.

    This is inserted into some bold text

    If instead of using our programmatic navigation we simply click on that same location with the mouse, the text is bold (or red or italic or whatever) just like it should be. So, clearly in using the Finder we're missing some crucial command that says "Anything typed here should be in the same format as the text around it."

    How can we force the CurrAttr to refresh/update itself to match the text attributes at the text cursor location?

    Thanks

  • Funny thing.
    We've just stumbled upon the very same problem which was reported to us by a user.
    When loading a document, the cursor is placed top left and the font is set to default (Arial 10, black).

    |header of my document

    the user just starts typing

    Important|header of my document

    If the document already contains text, the properties of the text are not applied. However, if I move the cursor to the right and back left manually, the properties are applied.
    My first idea was also to move the cursor by code after loading (quick and dirty), but this seems not to work.

    Is there something like GetFontPropertiesFromRightOfCursorAndApplyToCurrentPosition?

    Thanks![/b]

  • I think I've found the solution for our problem. I've replaced the call to Finder.MoveToFoundPositionEnd with explicitly setting the CPPosition. I would have expected that they'd be functionally the same, but apparently not...

    Code
    if Finder.Next (BookmarkChar) then
    begin
      // Finder.MoveToFoundPositionEnd;
      CPPosition := Finder.FoundPosition + Finder.FoundLength;
    end;
    • Offizieller Beitrag

    Hi,

    It was purpose that the finder will not update the current writing mode.

    But it is possible to casll GetCharAttr to read the attribute of the current position.

    Zitat

    {:: When you modify the cursor position in code (CPMoveNext) you can
    use this procedure to update the current writing attribute. }
    procedure GetCharAttr;

    Julian[/quote]