GetSelectionBounds and CurItemNo
GetSelectionBounds and CurItemNo
I am using
RichViewEdit.GetSelectionBounds(PsiNo, PsiOffs, PeiNo, PeiOffs, True);
RichViewEdit.CurItemNo
However I am needing help understanding why PsiNo is not equal to CurItemNo.
This happens when the selection bound is around a single item. Is it because the selection technically starts before the 1st character of an item?
I can use CurItemNo but I would rather not do double work if I can just get it from GetSelectionBounds.
RichViewEdit.GetSelectionBounds(PsiNo, PsiOffs, PeiNo, PeiOffs, True);
RichViewEdit.CurItemNo
However I am needing help understanding why PsiNo is not equal to CurItemNo.
This happens when the selection bound is around a single item. Is it because the selection technically starts before the 1st character of an item?
I can use CurItemNo but I would rather not do double work if I can just get it from GetSelectionBounds.
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: GetSelectionBounds and CurItemNo
The caret is always at the end of selection, so CurItemNo is either PsiNo or PeiNo.
If you call GetSelectionBounds(... False), it is always equal to PeiNo.
However, it is possible that in case of no selection GetSelectionBounds returns -1 in item indexes.
If you call GetSelectionBounds(... False), it is always equal to PeiNo.
However, it is possible that in case of no selection GetSelectionBounds returns -1 in item indexes.
Re: GetSelectionBounds and CurItemNo
If I use GetSelectionBounds(... True) should PsiNo be the CurItemNo?
Re: GetSelectionBounds and CurItemNo
What I am doing is combining Regex Search with Item Format settings. Is the regex a bold item etc.
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: GetSelectionBounds and CurItemNo
No, it should not.If I use GetSelectionBounds(... True) should PsiNo be the CurItemNo?
The caret is always at the end of the selected fragment. "The end" depends on the order how this selection was made. If it was made from top to bottom (PsiNo <= PeiNo), the end is closer to the bottom of the document. If it was made from bottom to top (PsiNo >= PeiNo), the end is closer to the top of the document.
GetSelectionBounds(... False) returns the selection bounds as they are, so CurItemNo = PeiNo.
GetSelectionBounds(... True) provides that PsiNo <= PeiNo, so CurItemNo is either PeiNo (if the selection was made from top to bottom) or PsiNo (if the selection was made from bottom to top).
Re: GetSelectionBounds and CurItemNo
Thank you for taking time to explain that! That really helps.
Re: GetSelectionBounds and CurItemNo
I think I am seeing part of what is going on
Imagine a word like this
word Nextword
Which is 5 bold characters because the space is included (1 item in RichView)
The "Nextword" is italics (1 item in RichView)
When I run RichViewEdit.GetSelectionBounds(PsiNo,PsiOffs, PeiNo, PeiOffs, False)
If I've selected the entire first Item using: TCustomRVFormattedData(RVData1).SetSelectionBounds(ItemNo1, Offs1, ItemNo2, Offs2)
Visually in RichViewEdit I see just "word " is selected.
I expect
PsiNo = 1
PeiNo = 1
PsiOffs = 1
PeiOffs = 5 (it is 6, I don't know why but doesn't affect me for now)
2nd Item selection what I expect
PsiNo = 2 (but it is 1??? this is really messing me up, how can I account for this. (It is not always this way.))
PsiOffs = 1 (but it is 10 probably due to item1)
PseiNo = 2
PseiOffs = 8 (it is 9, I don't know why but doesn't affect me for now)
Imagine a word like this
word Nextword
Which is 5 bold characters because the space is included (1 item in RichView)
The "Nextword" is italics (1 item in RichView)
When I run RichViewEdit.GetSelectionBounds(PsiNo,PsiOffs, PeiNo, PeiOffs, False)
If I've selected the entire first Item using: TCustomRVFormattedData(RVData1).SetSelectionBounds(ItemNo1, Offs1, ItemNo2, Offs2)
Visually in RichViewEdit I see just "word " is selected.
I expect
PsiNo = 1
PeiNo = 1
PsiOffs = 1
PeiOffs = 5 (it is 6, I don't know why but doesn't affect me for now)
2nd Item selection what I expect
PsiNo = 2 (but it is 1??? this is really messing me up, how can I account for this. (It is not always this way.))
PsiOffs = 1 (but it is 10 probably due to item1)
PseiNo = 2
PseiOffs = 8 (it is 9, I don't know why but doesn't affect me for now)
Re: GetSelectionBounds and CurItemNo
I think I must be doing something wrong here:
StartIndex := M.Index-1;
EndIndex := StartIndex + M.Length;
if LinearToRichView(MainForm.RichViewEdit, MainForm.RichViewEdit.RVData, StartIndex, RVData1, ItemNo1, Offs1) and
LinearToRichView(MainForm.RichViewEdit, MainForm.RichViewEdit.RVData, EndIndex, RVData2, ItemNo2, Offs2) and
(RVData1 = RVData2) then
begin
RVData1 := RVData1.Edit;
TCustomRVFormattedData(RVData1).SetSelectionBounds(ItemNo1, Offs1, ItemNo2, Offs2);
StartIndex := M.Index-1;
EndIndex := StartIndex + M.Length;
if LinearToRichView(MainForm.RichViewEdit, MainForm.RichViewEdit.RVData, StartIndex, RVData1, ItemNo1, Offs1) and
LinearToRichView(MainForm.RichViewEdit, MainForm.RichViewEdit.RVData, EndIndex, RVData2, ItemNo2, Offs2) and
(RVData1 = RVData2) then
begin
RVData1 := RVData1.Edit;
TCustomRVFormattedData(RVData1).SetSelectionBounds(ItemNo1, Offs1, ItemNo2, Offs2);
Re: GetSelectionBounds and CurItemNo
I think I see what is going on just not sure how to fix.
I need the selection to go to the closet item and not just use offs.
I need the selection to go to the closet item and not just use offs.
Re: GetSelectionBounds and CurItemNo
I found a fix, this brings the selection up to the present item if they are identically linearly.
A similar function may be nice to add to the LinearToRichView. It adjusts the Item and the Offs to the Items.
A similar function may be nice to add to the LinearToRichView. It adjusts the Item and the Offs to the Items.
Code: Select all
RichViewEdit.GetSelectionBounds(PsiNo, PsiOffs, PeiNo, PeiOffs, False);
//Selection was made PsiNo------>PeiNo in SelectNext, Replace, ReplaceAll
//Test two linear positions
if PsiOffs <> 1 then
begin
RichViewToLinear(RichViewEdit, RichViewEdit.RVData, RVData1, PsiNo, PsiOffs, PosA);
RichViewToLinear(RichViewEdit, RichViewEdit.RVData, RVData2, PsiNo+1, 1, PosB);
if PosA = PosB then
begin
PsiNo := PsiNo+1;
PsiOffs := 1;
end;
end;
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: GetSelectionBounds and CurItemNo
Sorry, I do not understand what your code does.
Re: GetSelectionBounds and CurItemNo
Ah basically the idea is to check if caret positions are identical if so move to the updated item.
However, I wonder if I am misunderstanding something.
Why is APos and BPos identical? I don't think it should be.
RichViewToLinear(GRichViewEdit, GRichViewEdit.RVData, RVData1, 1, 9, PosA);
RichViewToLinear(GRichViewEdit, GRichViewEdit.RVData, RVData2, 2, 1, PosB);
Is it because I have not supplied data to RVData1, RVData2: TCustomRVData; ??
However, I wonder if I am misunderstanding something.
Why is APos and BPos identical? I don't think it should be.
RichViewToLinear(GRichViewEdit, GRichViewEdit.RVData, RVData1, 1, 9, PosA);
RichViewToLinear(GRichViewEdit, GRichViewEdit.RVData, RVData2, 2, 1, PosB);
Is it because I have not supplied data to RVData1, RVData2: TCustomRVData; ??
Re: GetSelectionBounds and CurItemNo
My Fault I am sorry
I didn't do it right
RichViewToLinear(GRichViewEdit, GRichViewEdit.RVData, GRichViewEdit.RVData, PsiNo, PsiOffs, PosA);
RichViewToLinear(GRichViewEdit, GRichViewEdit.RVData, GRichViewEdit.RVData, PsiNo+1, 1, PosB);
I didn't do it right
RichViewToLinear(GRichViewEdit, GRichViewEdit.RVData, GRichViewEdit.RVData, PsiNo, PsiOffs, PosA);
RichViewToLinear(GRichViewEdit, GRichViewEdit.RVData, GRichViewEdit.RVData, PsiNo+1, 1, PosB);
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: GetSelectionBounds and CurItemNo
Problems:
1) The item with index PsiNo+1 does not necessary exist (check GRichViewEdit.ItemCount)
2) 1 is the position before the item only if this is a text item. For non-text item, the position before item is 0. Universal way: comparison with GRichViewEdit.GetOffsetBeforeItem(PsiNo_1)
But as I understand, you simply want to know if the position (PsiNo, PsiOffs) is at the end of the item.
You can check it simpler and much faster: if PsiOffs = GRichViewEdit.GetOffAferItem(PsiNo).
However, I am still not sure what you need. Your comparison of linear position works only if the item PsiNo and PsiOffs are at the same paragraph. Otherwise, they will be different by the size of line break (by default, by 2).
And my comparison (PsiOffs = GRichViewEdit.GetOffAferItem(PsiNo)) works when the next item is at the same paragraph, in the new paragraph, or even if PsiNo is the last item.
I am not sure what you need.
1) The item with index PsiNo+1 does not necessary exist (check GRichViewEdit.ItemCount)
2) 1 is the position before the item only if this is a text item. For non-text item, the position before item is 0. Universal way: comparison with GRichViewEdit.GetOffsetBeforeItem(PsiNo_1)
But as I understand, you simply want to know if the position (PsiNo, PsiOffs) is at the end of the item.
You can check it simpler and much faster: if PsiOffs = GRichViewEdit.GetOffAferItem(PsiNo).
However, I am still not sure what you need. Your comparison of linear position works only if the item PsiNo and PsiOffs are at the same paragraph. Otherwise, they will be different by the size of line break (by default, by 2).
And my comparison (PsiOffs = GRichViewEdit.GetOffAferItem(PsiNo)) works when the next item is at the same paragraph, in the new paragraph, or even if PsiNo is the last item.
I am not sure what you need.