[Example] DeleteBlankLines, RemoveParagraphBreaks, etc.

Demos, code samples. Only questions related to the existing topics are allowed here.
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Example] DeleteBlankLines, RemoveParagraphBreaks, etc.

Post by Sergey Tkachenko »

Use CanUpdate:

Code: Select all

  SRichViewEdit1.CanUpdate := False;
  DeleteBlankLines(SRichViewEdit1.ActiveEditor.RVData);
  SRichViewEdit1.ActiveEditor.ClearUndo;
  SRichViewEdit1.Format;
  SRichViewEdit1.CanUpdate := True;
filo
Posts: 22
Joined: Wed Apr 12, 2017 12:28 pm

Re: [Example] DeleteBlankLines, RemoveParagraphBreaks, etc.

Post by filo »

Solved, thank you!
jonjon
Posts: 470
Joined: Sat Aug 27, 2005 4:19 pm

Re: [Example] DeleteBlankLines, RemoveParagraphBreaks, etc.

Post by jonjon »

Hi Sergey,
Could you please provide a fix for "Paragraph breaks -> line breaks" which converts the line before the first selected text?
See attached screenshot, when you select from test2 to test5, it will also convert the paragraph break before test2 when it shouldn't.
See attached sample project to quickly reproduce this problem.
Thank you.
Attachments
rv-pb2lb.zip
(2.33 KiB) Downloaded 4384 times
rv-page-break.png
rv-page-break.png (13.04 KiB) Viewed 69032 times
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Example] DeleteBlankLines, RemoveParagraphBreaks, etc.

Post by Sergey Tkachenko »

Code: Select all

procedure MakeSoftLineBreaksEd(rve: TCustomRichViewEdit);
var ItemNo1, Offs1, ItemNo2, Offs2: Integer;
    Whole, FR: Boolean;
  i: Integer;
begin
  rve := rve.TopLevelEditor;
  if not rve.BeforeChange(False) then
    exit;
  rve.GetSelectionBounds(ItemNo1, Offs1, ItemNo2, Offs2, True);
  Whole := (ItemNo1<0) or ((ItemNo1=ItemNo2) and (Offs1=Offs2));
  if Whole then 
  begin
    ItemNo1 := 0;
    ItemNo2 := rve.ItemCount-1;
  end
  
  // ADDED
  
  else 
   inc(ItemNo1); 
  
  // END ADDED
  
  
  rve.BeginUndoGroup(rvutPara);
  rve.SetUndoGroupMode(True);
  if ItemNo1<1 then
    ItemNo1 := 1;
  for i := ItemNo2 downto ItemNo1 do
    if rve.IsParaStart(i) and (rve.GetItemStyle(i)<>rvsListMarker) and
      not rve.GetItem(i-1).GetBoolValue(rvbpFullWidth) then
       TRVEditRVData(rve.RVData).Do_BR(i, True, FR);
  rve.SetUndoGroupMode(False);
  rve.Change;
  rve.Reformat;
end;
jonjon
Posts: 470
Joined: Sat Aug 27, 2005 4:19 pm

Re: [Example] DeleteBlankLines, RemoveParagraphBreaks, etc.

Post by jonjon »

Thank you Sergey but it looks like this fix is incomplete: if only part of the first line is selected (e.g. instead of selecting "test2" you only select "st2") then the line before that one is converted when it shouldn't.
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Example] DeleteBlankLines, RemoveParagraphBreaks, etc.

Post by Sergey Tkachenko »

I modified the code in my previous reply to fix it.
jonjon
Posts: 470
Joined: Sat Aug 27, 2005 4:19 pm

Re: [Example] DeleteBlankLines, RemoveParagraphBreaks, etc.

Post by jonjon »

Great. Thanks.
Post Reply