Issue 72394

Summary: "select all" does not work when "hidden text" at the end of document
Product: Writer Reporter: richlv <richlv>
Component: codeAssignee: michael.ruess
Status: CLOSED FIXED QA Contact: issues@sw <issues>
Severity: Trivial    
Priority: P3 CC: chengxiuzhi, frank.meies, issues, liujiaxiang, peter.junge
Version: OOo 2.1   
Target Milestone: ---   
Hardware: PC   
OS: All   
Issue Type: PATCH Latest Confirmation in: ---
Developer Difficulty: ---
Issue Depends on:    
Issue Blocks: 72764    
Attachments:
Description Flags
testcase
none
patch file
none
patch file
none
new patch file
none
patch file none

Description richlv 2006-12-08 13:16:35 UTC
this is a 680m3, build 9090, which advertises as 2.1.

see testcase. either 'select all' menu item or ctrl+a does not work.
Comment 1 richlv 2006-12-08 13:17:13 UTC
Created attachment 41248 [details]
testcase
Comment 2 michael.ruess 2006-12-08 13:40:36 UTC
MRU->FME: see attached document; there's hidden text at the end, thus Ctrl-A
won't work - it will just transfer the cursor to begin of document.
Comment 3 jian.li 2007-11-14 06:26:56 UTC
lijian->fme:
It seems that this issue is regarding cursor and SwPam. I am interested in 
this issue. What do you think about this ? Is this issue OK for me ?
I need your suggestion.
Comment 4 jian.li 2007-11-14 08:31:57 UTC
assign to lijian
Comment 5 jian.li 2007-11-20 08:44:18 UTC
lijian->fme:
I found this issue related to the options in tools.
Tools-Options-Writer-Formatting Aids, if we select "Hidden Text",
this issue will not exist.
So, we should get the value of checkbox "Hidden Text" to see if we have to 
move the cursor skipping hidden text, I think. Though I havn't found a way to 
get this value. 
What do think about my thought ?
Comment 6 frank.meies 2007-11-20 09:34:54 UTC
fme->lijian: Did you already find the code that skips the hidden paragraph? It's
located inside SwCrsr::IsSelOvr(). There's some code that checks if the point of
the current cursor is located inside a hidden frame (which in this case is
recognized by checking if the frame height = 0). If so, the point is moved to
the next paragraph. In our case there is no next paragraph, so the cursor
position is considered invalid. Maybe we should also try to move to the previous
paragraph...
Comment 7 jian.li 2007-11-21 09:01:34 UTC
Created attachment 49783 [details]
patch file
Comment 8 jian.li 2007-11-21 09:11:40 UTC
lijian->fme:
I wonder what pSavePos is used for and where its value 
gets from in SwCursor::IsSelOvr.
In my patch, I just changed the value of bGoNxt. Then 
all seems to work fine. I just take this as a test.
Actually, I think it should be like this :
if bGoNxt == 1 and pFrm is hidden, we could see if 
paragraph pFrm represents is the last paragraph. If so,
we need to move forward.
It's similar to bGoNxt == 0.
What's your opinion ?
Comment 9 frank.meies 2007-11-21 13:32:11 UTC
fme->lijian: Thank you for your patch. Please find my comments below.

[...] I wonder what pSavePos is used for and where its value gets from in
SwCursor::IsSelOvr. [...]

pSavePos contains the last known 'save' position the cursor was set to. Usually
it works like this: before trying to move the cursor, an SwCrsrSaveState object
is created with the current cursor. Since ths current cursor is assumed to be on
a valid position, the SwCrsrSaveState object stored the last known valid cursor
position. Then the cursor is moved to a new position. After this, some checks
are executed, if the cursor is now 'valid', e.g., in IsSelOvr(). If the cursor
is found to be on an invalid position and the cursor either should not be
corrected (!SELOVR_CHANGEPOS) or could not be corrected (like in our case), the
SwCrsrSaveState object can be used to 'undo' the cursor move that resulted in
this 'invalid' cursor position.

[...] In my patch, I just changed the value of bGoNxt. Then all seems to work
fine. I just take this as a test. Actually, I think it should be like this :

if bGoNxt == 1 and pFrm is hidden, we could see if paragraph pFrm represents is
the last paragraph. If so, we need to move forward. It's similar to bGoNxt == 0.
What's your opinion ? [...]

Yes, I fully agree with you. bGoNxt == true indicates, that the cursor has been
moved forward, i.e., the last 'save' position is < than the position after the
cursor move. In this case the code tries to search forward for a suitable cursor
position. If bGoNxt == false, the cursor has been moved backward, i.e., the last
'save' position > thant the current position. In this case the code searches
backward for a suitable cursor position. We should keep this logic, and maybe
should check, if after the while loop pFrm == 0. This means that for bGoNxt ==
true (resp. false), we reached the end (resp. start) of the text without finding
a suitable paragraph. In this case we should restart the search with bGoNxt =
!bGoNxt. Hope this helps.
Comment 10 jian.li 2007-11-22 03:15:19 UTC
Created attachment 49803 [details]
patch file
Comment 11 jian.li 2007-11-22 03:17:59 UTC
lijian->fme:
I have made a new patch according to your helpful explanations which are 
really very clear and detailed. Thank you very much.
Please review this patch.
Comment 12 jian.li 2007-11-22 09:20:46 UTC
Created attachment 49809 [details]
new patch file
Comment 13 jian.li 2007-11-22 09:22:16 UTC
lijian->fme:
Maybe this patch is OK .
Comment 14 frank.meies 2007-11-22 10:11:56 UTC
fme->lijian: Some more comments:

1. I just noticed that your while loop does not work if there are more than one
hidden paragraphs at the end. You should work with pFrm inside the new while
loop instead of pNd. 

2. Let's have a look at bGoNxt. A couple of lines below, bGoNxt is also used.
The meaning of bGoNxt in this context is that if the node postion of the cursor
has been corrected by going forward, the content member of the position is set
to the beginning of the new paragraph. If the cursor has been corrected by going
backward, the content member of the position is set to the end of the new
paragraph. So what should happen if we add our new code? Let's have a look at
this example:

Paragraph1
Paragraph2
hidden paragraph3
hidden paragraph4
Paragraph5

Let's assume that the cursor is moved from paragraph2 to paragraph3. In this
case bGoNxt=true. So we try to find a suitable paragraph after paragraph3 to set
the cursor to. The while loop sets pFrm to paragraph4 and finds that it is not
suitable. So the while loop advances to paragraph5 and breaks. The following
code sets the content member to the cursor to position 0 because the cursor
position was corrected to a position after the original position.

So here's an other example:

Paragraph1
Paragraph2
hidden paragraph3
hidden paragraph4

Let's assume that the cursor is moved from paragraph1 to paragraph3. In this
case bGoNxt=true. Since paragraph3 is hidden, we try to find a suitable
paragraph after paragraph3 to set the cursor to. The while loop sets pFrm to
paragraph4 and finds that it is not suitable. But paragraph4 is the last
paragraph, so the while loop breaks. Here we have to add our new code. We see
that pFrm == 0. We start over with pFrm = pNd->GetFrm(). Now we want to search
backward. We need have a while loop that does the same like the first while
loop, the only difference is that it has to search backward if the first loop
searched forward and vice versa. So our new code sets pFrm to paragraph3 and
searched backward. Because paragraph2 is fine, the new while loop breaks. What
do we have to do with the nContent member to the cursor? Since the cursor
position has been corrected by going backward, we have to set nContent to
pCnd->GetLen(). So we see that it is correct to set bGoNxt = !bGoNxt in case the
first while loop did not succeed.
Comment 15 jian.li 2007-11-26 03:55:08 UTC
Created attachment 49890 [details]
patch file
Comment 16 jian.li 2007-11-26 03:59:08 UTC
lijian->fme:
regarding 1: I have submitted a new patch. Please review it.

regarding 2: Thank you for your so clear explanations. I think 
I have understood this very clearly.  
Comment 17 frank.meies 2007-11-27 10:07:27 UTC
fme->lijian: Cool, that's it, works fine. I'll add your fix to cws sw8u10bf02. 

fme: Fixed by lijian in swcrsr.cxx rev. 1.54.94.1
Comment 18 frank.meies 2007-11-30 11:54:29 UTC
.
Comment 19 frank.meies 2007-12-04 09:54:08 UTC
Ready for QA.
Comment 20 michael.ruess 2007-12-11 11:14:33 UTC
Reopening.
Comment 21 michael.ruess 2007-12-11 11:31:11 UTC
MRU->FME: the implementation implies a new crash. The non-printing characters
must be deactivated. Insert dummy text, select all, format as "hidden", open
format.character dialog again -> crash
Comment 22 frank.meies 2007-12-11 13:08:18 UTC
fme->mru: You are right. We forgot to check this case. Now corrected.
Comment 23 frank.meies 2007-12-12 12:47:45 UTC
.
Comment 24 michael.ruess 2007-12-13 16:41:39 UTC
Verified in CWS sw8u10bf02.
Comment 25 michael.ruess 2008-03-20 14:39:49 UTC
Checked in OO 2.4 RC6 and DEV300m3.