Bug 105136 - TextCursor gotoNextWord method fails when paragraph does not end in period
Summary: TextCursor gotoNextWord method fails when paragraph does not end in period
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
5.1.6.2 release
Hardware: All All
: medium minor
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: bibisected, bisected, regression
Depends on:
Blocks:
 
Reported: 2017-01-06 03:46 UTC by Jordi
Modified: 2023-11-01 11:18 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Test file containing macro. (10.99 KB, application/vnd.oasis.opendocument.text)
2017-01-21 02:47 UTC, Jordi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jordi 2017-01-06 03:46:56 UTC
Description:
While running 5.0.5.2, I wrote a macro to move the visible cursor to the next misspelled word. When I upgraded to 5.2.4.2 the macro was getting stuck. Upon further investigation it appears that the bug is there from as early as 5.1.6.2 release. I've checked and it there regardless of language used, I originally caught it with Greek question marks (;), or operating system used, I tried Linux, Windows 10, Windows 7.



Steps to Reproduce:
1. Type paragraph and end it with punctuation other than period
2. Run macro.
3. 

Actual Results:  
Macro appears stuck, will eventually give error possibly due to resources issue...?

Expected Results:
Expect the macro not to get stuck ?!?


Reproducible: Always

User Profile Reset: Yes

Additional Info:
Here is the macro I used...

Sub gotoNextSpellingError
	gotoSpellingError(true)
End Sub

Sub gotoPreviousSpellingError
	gotoSpellingError(false)
End Sub


'
' Find next misspelled word and move cursor to it
'
Sub gotoSpellingError(fwd As boolean)
	Dim oDocModel as Variant
	Dim oTextCursor as Variant
	
	Dim aProp(0) As New com.sun.star.beans.PropertyValue

	oDocModel = StarDesktop.CurrentFrame.Controller.getModel()
	If IsNull(oDocModel) Then
		MsgBox("No active document.")
		Exit Sub
	End If

	If Not HasUnoInterfaces (oDocModel, "com.sun.star.text.XTextDocument") Then
		MsgBox("This macro is for Text documents only.")
		Exit Sub
	End If

	'Start search from currect view cursor position...
	Dim oVC
    oVC = ThisComponent.currentController.getViewCursor()
    
	oTextCursor = oDocModel.Text.createTextCursor()
	oTextCursor.gotoRange(OVC,false)
	
	Dim vSpeller As Variant
	'vSpeller = createUnoService("com.sun.star.linguistic2.SpellChecker")
	vSpeller = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
	    oLinguSvcMgr = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
    If IsNull(oLinguSvcMgr) Then
    	Print "Failed to create LinguServiceManager object"
    	Exit Sub
	End If   
		
	vSpeller = oLinguSvcMgr.getSpellChecker()
	If isNull(vSpeller) Then
		Print "No SpellChecker object"
		Exit Sub
	End if
	
	'xray vSpeller
	'Repeated runs should walk through errors...
	If fwd then
		oTextCursor.gotoNextWord(false)
	Else
		oTextCursor.gotoPreviousWord(false)
	End if
	    
	Dim oTCWordStart,oTCString,oTCProp,bValidWord
	Do

'		If NOT oTextCursor.isStartOfWord() Then
			oTextCursor.gotoStartOfWord(false)
'		End If
		
		oTCWordStart = oTextCursor.getStart()
		
		oTextCursor.gotoEndOfWord(True)			
		oTCString = oTextCursor.getString()
		
		'DEBUG
		'oVC.collapseToEnd()
		'oVC.gotorange(oTextCursor,true)
		
		oTCProp = oTextCursor.getPropertyValue("CharLocale") '.Language

		If IsEmpty(oTCProp) Or IsNull(oTCProp) Then
			bValidWord = true
		else			
			Select Case oTCProp.Language
			Case "el", "en"
				bValidWord = vSpeller.com_sun_star_linguistic2_XSpellChecker_isValid(oTCString, oTCProp, aProp())
			Case Else
				bValidWord = true
			End Select
		End If
		
		If not bValidWord Then
			oVC.gotoRange(oTCWordStart,false)
			Exit Sub 	'Found invalid word
		End If

		If fwd then
			notDone = oTextCursor.gotoNextWord(false)
		Else
			oTextCursor.collapseToStart()		'collapse selection...
			notDone = oTextCursor.gotoPreviousWord(false)
		End if
	Loop while notDone
		
	Print "Done. No mispelled words found."
End Sub



User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Comment 1 Xisco Faulí 2017-01-12 11:09:54 UTC
Hello,

Thank you for reporting the bug. Please attach a sample document, as this makes it easier for us to verify the bug. 
I have set the bug's status to 'NEEDINFO'. Please change it back to 'UNCONFIRMED' once the requested document is provided.
(Please note that the attachment will be public, remove any sensitive information before attaching it. 
See https://wiki.documentfoundation.org/QA/FAQ#How_can_I_eliminate_confidential_data_from_a_sample_document.3F for help on how to do so.)
Comment 2 Jordi 2017-01-21 02:47:26 UTC
Created attachment 130591 [details]
Test file containing macro.
Comment 3 Buovjaga 2017-01-25 10:30:42 UTC
Ok, so you mean by running gotoNextSpellingError and clicking OK, it just continues finding 'line' all the time?

Win 7 Pro 64-bit Version: 5.4.0.0.alpha0+
Build ID: 1c27286b9d5331634c073cd3e327bd941e61bbb6
CPU Threads: 4; OS Version: Windows 6.1; UI Render: default; 
TinderBox: Win-x86@39, Branch:master, Time: 2017-01-23_03:24:17
Locale: fi-FI (fi_FI); Calc: group
Comment 4 Jordi 2017-02-11 00:24:50 UTC
Yes, it continues to show "line", the last word from the second paragraph and will not move beyond that.
Comment 5 raal 2017-04-08 22:02:13 UTC
This seems to have begun at the below commit.
Adding Cc: to Tomaž Vajngerl; Could you possibly take a look at this one? Thanks
 8e048850e03974bcdf2cf6943324a88c53a1fed3 is the first bad commit
commit 8e048850e03974bcdf2cf6943324a88c53a1fed3
Author: Norbert Thiebaud <nthiebaud@gmail.com>
Date:   Tue Aug 4 23:59:48 2015 -0700

    source 8eca4da70506e1e6c2e4b600262cced93aba8c96

author	Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>	2015-07-31 07:54:48 (GMT)
committer	Tomaž Vajngerl <quikee@gmail.com>	2015-08-04 06:28:15 (GMT)
commit 8eca4da70506e1e6c2e4b600262cced93aba8c96 (patch)
tree d8c4158af8263b94ee48b4fad5daf50c755e4938
parent a933e01a54f08132c2d8699f7c6851a8b493d5dc (diff)
tdf#89154 stop at paragraph end when using CTRL+Right (or Left)
Comment 6 QA Administrators 2018-04-09 02:31:24 UTC Comment hidden (obsolete)
Comment 7 QA Administrators 2020-04-09 03:35:57 UTC Comment hidden (spam)