[Solved] Cloning a text cursor?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
eezacque
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm

[Solved] Cloning a text cursor?

Post by eezacque »

In my macro, I am navigating my Writer document using a text cursor to find a certain location.
As I need this location later on, I would like to keep this text cursor for future reference, so I would like to make an independent clone/duplicate.
Is there any way to achieve this?
Last edited by Hagar Delest on Tue Jan 08, 2019 12:31 am, edited 1 time in total.
Reason: tagged solved
LibreOffice 6.0.7.3 on Ubuntu 18.04.1
User avatar
RoryOF
Moderator
Posts: 34610
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Cloning a text cursor?

Post by RoryOF »

/Insert /Bookmark, or /Insert /Comment, then use the Navigator to move back to the marked location. You can use code to insert and to move to either of these markers if using a macro.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
eezacque
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm

Re: Cloning a text cursor?

Post by eezacque »

Not sure whether bookmarks is the way to go, as I do not want to move my view cursor.
Is there any way to place a bookmark and create a text cursor at this position, both in the same macro?
LibreOffice 6.0.7.3 on Ubuntu 18.04.1
User avatar
RoryOF
Moderator
Posts: 34610
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Cloning a text cursor?

Post by RoryOF »

I think this is possible, but you will have to read up on it; the best source book is
OpenOffice.org Macros Explained.odt V3
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
eezacque
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm

Re: Cloning a text cursor?

Post by eezacque »

Looks like it is possible indeed, but it looks like a hopelessly convoluted solution.

Let me explain my situation. In a Writer document I create a text cursor from my view cursor, and use this cursor to find a paragraph of certain style.
At this moment I have a variable textCursor which points exactly at the location from where I will collect text in memory, with the intention to manipulate this text in memory, and replace the text in my document with the manipulated text. I can successfully collect text and reformat it, but this process moves my textCursor through the document. All I need is to create an independent copy of textCursor which does not change with textCursor, so I can easily replace the original text. All I really need is something like orgCursor=copy(textCursor)...
LibreOffice 6.0.7.3 on Ubuntu 18.04.1
mikele
Posts: 72
Joined: Wed Nov 21, 2018 11:11 am
Location: Germany

Re: Cloning a text cursor?

Post by mikele »

Hi,
you can clone a textcursor by creating a new one with the textrange the first defines

Code: Select all

Sub Main
	odoc=thiscomponent
	otc1=odoc.text.createtextcursor
	otc1.gotostart(false)
	otc1.gotonextword(false)
	otc2=odoc.text.createTextCursorByRange(otc1)
	otc2.gotoend(false)
	odoc.text.insertstring(otc,"!!!first!!!",false)
	odoc.text.insertstring(otc2,"!!!second!!!",true)
End Sub
LibreOffice 5.4, 7.0, 7.2 on LinuxMint/Win10
eezacque
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm

Re: Cloning a text cursor?

Post by eezacque »

mikele wrote:Hi,
you can clone a textcursor by creating a new one with the textrange the first defines
Looks exactly what I need!
I will give it a try...

Edit: it works!

Thanks a lot for helping me out...
LibreOffice 6.0.7.3 on Ubuntu 18.04.1
Post Reply