Deleting items with rvprStyleProtect

General TRichView support forum. Please post your questions here
Post Reply
dave novo
Posts: 105
Joined: Wed Aug 31, 2005 2:13 am

Deleting items with rvprStyleProtect

Post by dave novo »

We are having an issue is that when a text item is partially selected and has a text style with rvprStyleProtect in its Protection but not rvprStyleDelete, it is annoying to actually delete it. You have to select the whole item first, and then delete/backspace/cut will work. If you only have part of the item selected, RVE will just call System.Beep and do nothing, because the item can't be modified. If the cursor is at the start of the item and you press the Delete key, or at the end of the item and you press Backspace, it will also fail unless the item is only one character long. This is technically correct given how rvprStyleProtect is defined, but not what we would like from a usability standpoint.

Instead, what I would prefer is to delete the whole item whenever there is an attempt to delete any part of it. This certainly doesn't need to be the default behavior for RVEs, but it's what I'm trying to make happen in this case.

We are trying to find a way to detect that the user is trying to delete the item, and before the delete is processed, we will expand the selection to include the entire item. But we cannot find a clean way to do this.

Any other alternative suggestions would be appreciated.
Last edited by dave novo on Tue Jul 28, 2020 7:52 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Deleting items with rvprStyleProtect

Post by Sergey Tkachenko »

Ok, I'll add "easy delete" option in the next update.
dave novo
Posts: 105
Joined: Wed Aug 31, 2005 2:13 am

Re: Deleting items with rvprStyleProtect

Post by dave novo »

Hi Sergey,

Just wondering how the "easy delete" option is coming?
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Deleting items with rvprStyleProtect

Post by Sergey Tkachenko »

Do you need it urgently? I plan a major new feature in the next update, and it will take some time.
dave novo
Posts: 105
Joined: Wed Aug 31, 2005 2:13 am

Re: Deleting items with rvprStyleProtect

Post by dave novo »

Is there some hack you can suggest in the meantime. Basically, all we need is some hook that when the delete is about to happen, we have a chance to expand the selection to encompass the entire item and then let the deletion proceed normally since all the text we want will be selected. We can modify the source with your suggestion until you come up with a more elegant solution.
dave novo
Posts: 105
Joined: Wed Aug 31, 2005 2:13 am

Re: Deleting items with rvprStyleProtect

Post by dave novo »

Hi Sergey,
Just wondering if there was any update on this.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Deleting items with rvprStyleProtect

Post by Sergey Tkachenko »

Sorry, I need to complete the current stage of DocX import before.
I'll be able to send changes to you in the next week.
dave novo
Posts: 105
Joined: Wed Aug 31, 2005 2:13 am

Re: Deleting items with rvprStyleProtect

Post by dave novo »

Hi Sergey,
Any update on this? We have finished all our changes and this is the last part that is remaining
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Deleting items with rvprStyleProtect

Post by Sergey Tkachenko »

I cannot upload the new version now, because it has incomplete changes.
But I can explain how to make the necessary changes.

1) RVEdit.pas, a new option in TRVEditorOption type:
rvoFastDeleteProtectedText

2) In RVERVData.pas, the condition of the first IF in Backspace_NotAtTheBeginning function is changed to:

Code: Select all

    if ((StyleNo < 0) and (Offset = 1)) or
      ((StyleNo >= 0) and IsProtected(DrawItem.ItemNo, rvprModifyProtect) and
       (rvoFastDeleteProtectedText in TCustomRichViewEdit(FRichView).EditorOptions)) or
      ((StyleNo >= 0) and
       (GetItemTextLength(DrawItem.ItemNo) <=
        DeleteCount(Items[DrawItem.ItemNo], DrawItem.Offs + Offset - 2, DrawItem.ItemNo)) and
       ((GetRVStyle.TextStyles[StyleNo].EmptyWidth <= 0) or IsWideEmptyTextItem(DrawItem.ItemNo))) then
This change allows deleting the protected text by a single press of Backspace or Delete key.

3) The same unit, add the method:

Code: Select all

procedure TRVEditRVData.AdjustSelectionBeforeDeletion(var StartNo, EndNo, StartOffs, EndOffs: Integer);
begin
  if not (rvoFastDeleteProtectedText in TCustomRichViewEdit(FRichView).EditorOptions) then
    exit;
  if IsProtected(StartNo, rvprModifyProtect) then
    StartOffs := GetOffsBeforeItem(StartNo);
  if IsProtected(EndNo, rvprModifyProtect) then
    EndOffs := GetOffsAfterItem(EndNo);
end;
4) Add the call of this method in the function function TRVEditRVData.CanDelete, just after the call of StoreSelBounds:

Code: Select all

  StoreSelBounds(StartNo, EndNo, StartOffs, EndOffs, True);
  AdjustSelectionBeforeDeletion(StartNo, EndNo, StartOffs, EndOffs);
5) Add the call of this method in the function function TRVEditRVData.DeleteSelection_, just after the SECOND call of StoreSelBounds (where the last parameter is True):

Code: Select all

    StoreSelBounds(StartNo, EndNo, StartOffs, EndOffs, True);
    AdjustSelectionBeforeDeletion(StartNo, EndNo, StartOffs, EndOffs);
The changes 3-5 allow deleting a protected text together with a selected fragment, even if it (protected text) is selected only partially.
dave novo
Posts: 105
Joined: Wed Aug 31, 2005 2:13 am

Re: Deleting items with rvprStyleProtect

Post by dave novo »

Hi Sergey,
Thank you. We will apply the changes and let you know if we encounter any issues.
Post Reply