Ignore:
Timestamp:
Mar 1, 2019, 8:09:20 PM (6 years ago)
Author:
ataylor
Message:

DBCS character boundary detection for cursor positioning logic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Components/RichTextView.PAS

    r420 r421  
    8787    FCursorRow: longint;
    8888    FCursorOffset: longint;
     89
     90    FCursorMoveRight: boolean;    // ALT - TRUE if cursor is moving to the right
    8991
    9092    FSelectionStart: longint;
     
    460462Procedure TRichTextView.SetSelectionStartInternal( SelectionStart: longint );
    461463var
     464  Line:   longint;     // ALT
    462465  Offset: longint;     // ALT
    463466begin
     
    470473      ClearSelection;
    471474
    472   // ALT
    473   Offset := FCursorOffset;
    474   MoveToCharacterBoundary( FText, SelectionStart, FCursorOffset, Offset, FLayout.Codepage, false );
     475// Should already be ensured by this point?
     476//  FLayout.FindCharacterBoundary( FText, SelectionStart, false );    // ALT
    475477
    476478  FSelectionStart := SelectionStart;
     
    485487  StartRedrawLine: longint;
    486488  EndRedrawLine: longint;
    487   Offset: longint;         // ALT
     489  Offset: longint;          // ALT
     490  Line:   longint;          // ALT
    488491  OldClip: TRect;
    489492begin
     
    491494    exit;
    492495
    493   // ALT
    494   Offset := FCursorOffset;
    495   MoveToCharacterBoundary( FText, SelectionEnd, FCursorOffset, Offset, FLayout.Codepage, false );
     496// Should already be ensured by this point?
     497//  FLayout.FindCharacterBoundary( FText, SelectionEnd, false );      // ALT
    496498
    497499  if FSelectionStart = -1 then
     
    955957                               Offset,
    956958                               Link );
     959
    957960end;
    958961
     
    12571260  // ALT - move to nearest character boundary
    12581261  Index := FLayout.GetCharIndex( Line.Text ) + FCursorOffset;
    1259   RowStart := FLayout.GetCharIndex( Line.Text );
    1260   MoveToCharacterBoundary( FText, Index, FCursorOffset, RowStart, FLayout.Codepage, false );
     1262
     1263  FLayout.FindCharacterBoundary( FText, Index, FCursorMoveRight );
     1264  FCursorOffset := FLayout.GetOffsetFromCharIndex( Index, CursorRow );
     1265  FCursorMoveRight := false;
     1266  // ALT
    12611267
    12621268  FLayout.GetXFromOffset( FCursorOffset, CursorRow, X );
     
    19982004  Row: longint;
    19992005begin
     2006  FCursorMoveRight := false;    // ALT
     2007
    20002008  if SelectionSet then
    20012009  begin
     
    20372045                                           PreserveSelection: boolean );
    20382046var
    2039 //  P: PChar;                 // ALT
    2040 //  NextP: PChar;             // ALT
    2041 //  Element: TTextElement;    // ALT
    2042 //  InsideDBC: boolean;       // ALT
    20432047  RowStart: longint;        // ALT
    20442048  MoveRight: boolean;       // ALT
     
    20482052
    20492053  Index := FLayout.GetCharIndex( FLayout.FLines[ Row ].Text ) + Offset;
    2050 
    2051 // ALT
    2052 {
    2053   if ( Offset > 0 ) and
    2054      ( FLayout.Codepage in [ 932, 936, 942, 943, 949, 950, 1381, 1386 ]) then
    2055   begin
    2056     RowStart := FLayout.GetCharIndex( FLayout.FLines[ Row ].Text );
    2057     P := FText + RowStart;
    2058     InsideDBC := false;
    2059     while RowStart < Index do
    2060     begin
    2061       Element := ExtractNextTextElement( P, NextP );
    2062       CheckSpecialElementType( Element.Character, Element.ElementType, InsideDBC, FLayout.Codepage );
    2063       P := NextP;
    2064       inc( RowStart );
    2065     end;
    2066     Element := ExtractNextTextElement( P, NextP );
    2067     CheckSpecialElementType( Element.Character, Element.ElementType, InsideDBC, FLayout.Codepage );
    2068     if InsideDBC then
    2069     begin
    2070       dec( Index );
    2071       dec( Offset );
    2072     end;
    2073   end;
    2074 }
    2075 
    20762054  RowStart := FLayout.GetCharIndex( FLayout.FLines[ Row ].Text );
    20772055
    2078   // ALT
    2079   if Offset = ( FCursorOffset + 1 ) then
    2080     MoveRight := true
    2081   else
    2082     MoveRight := false;
    2083   MoveToCharacterBoundary( FText, Index, Offset, RowStart, FLayout.Codepage, MoveRight );
    2084 
    2085   FCursorOffset := Offset;
     2056  Offset := FLayout.FindCharacterBoundary( FText, Index, FCursorMoveRight );  // ALT
     2057  FCursorOffset := FLayout.GetOffsetFromCharIndex( Index, Row );
    20862058  FCursorRow := Row;
    20872059
     
    21062078  Line: TLayoutLine;
    21072079begin
     2080  FCursorMoveRight := true;
    21082081  P := FText + CursorIndex;
    21092082
     
    24232396begin
    24242397  CursorVisible := FSelectionStart <> -1;
     2398  FCursorMoveRight := false;
    24252399
    24262400  Case KeyCode of
Note: See TracChangeset for help on using the changeset viewer.