Anyway the following doesn't work and freezes and takes place in OnChange. In OnKeyPress I insert an image named bold if ctrl+b is found.
Code: Select all
CursorPos := RVGetLinearCaretPos( CommandEdit );
I := 0;
while I < CommandEdit.ItemCount - 1 do
begin
EndItemNo := -1;
EndItemOffs := -1;
if CommandEdit.GetItem( I ) is TRVGraphicItemInfo then
begin
if CommandEdit.GetItemText( I ) = 'Bold' then
begin
StartItemNo := I;
StartItemOffs := CommandEdit.GetOffsAfterItem( StartItemNo );
Inc( I );
while I < CommandEdit.ItemCount - 1 do
begin
if CommandEdit.GetItem( I ) is TRVGraphicItemInfo then
begin
if CommandEdit.GetItemText( I ) = 'Bold' then
begin
EndItemNo := I;
EndItemOffs := CommandEdit.GetOffsBeforeItem( EndItemNo );
CommandEdit.SetSelectionBounds( StartItemNo, StartItemOffs, EndItemNo, EndItemOffs );
Break;
end;
end;
Inc( I );
end;
if ( EndItemNo = -1 ) and ( EndItemOffs = -1 ) then
begin
EndItemNo := CommandEdit.ItemCount - 1;
EndItemOffs := CommandEdit.GetOffsBeforeItem( EndItemNo );
Caption := Format('%d %d %d %d',[ StartItemNo, StartItemOffs, EndItemNo, EndItemOffs]);
CommandEdit.SetSelectionBounds( StartItemNo, StartItemOffs, EndItemNo, EndItemOffs );
CommandEdit.ApplyTextStyle( 1 );
end;
end;
end;
Inc( I );
end;
RVSetLinearCaretPos( CommandEdit, CursorPos );
CommandEdit.Invalidate;