Page 1 of 1

Deleting items with rvprStyleProtect

Posted: Mon Jul 20, 2020 7:32 pm
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.

Re: Deleting items with rvprStyleProtect

Posted: Tue Jul 28, 2020 7:44 pm
by Sergey Tkachenko
Ok, I'll add "easy delete" option in the next update.

Re: Deleting items with rvprStyleProtect

Posted: Thu Aug 20, 2020 5:09 am
by dave novo
Hi Sergey,

Just wondering how the "easy delete" option is coming?

Re: Deleting items with rvprStyleProtect

Posted: Fri Aug 21, 2020 4:44 pm
by Sergey Tkachenko
Do you need it urgently? I plan a major new feature in the next update, and it will take some time.

Re: Deleting items with rvprStyleProtect

Posted: Sat Aug 22, 2020 5:11 am
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.

Re: Deleting items with rvprStyleProtect

Posted: Mon Sep 28, 2020 7:06 pm
by dave novo
Hi Sergey,
Just wondering if there was any update on this.

Re: Deleting items with rvprStyleProtect

Posted: Thu Oct 01, 2020 6:56 pm
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.

Re: Deleting items with rvprStyleProtect

Posted: Sun Oct 11, 2020 8:15 pm
by dave novo
Hi Sergey,
Any update on this? We have finished all our changes and this is the last part that is remaining

Re: Deleting items with rvprStyleProtect

Posted: Fri Oct 16, 2020 9:39 am
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.

Re: Deleting items with rvprStyleProtect

Posted: Sun Oct 18, 2020 10:00 pm
by dave novo
Hi Sergey,
Thank you. We will apply the changes and let you know if we encounter any issues.