[Solved] Cloning a text cursor?

Creating a macro - Writing a Script - Using the API

[Solved] Cloning a text cursor?

Postby eezacque » Mon Jan 07, 2019 7:40 pm

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
eezacque
 
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm

Re: Cloning a text cursor?

Postby RoryOF » Mon Jan 07, 2019 7:45 pm

/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.7 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 30179
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Cloning a text cursor?

Postby eezacque » Mon Jan 07, 2019 9:01 pm

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
eezacque
 
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm

Re: Cloning a text cursor?

Postby RoryOF » Mon Jan 07, 2019 9:08 pm

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.7 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 30179
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Cloning a text cursor?

Postby eezacque » Mon Jan 07, 2019 9:29 pm

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
eezacque
 
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm

Re: Cloning a text cursor?

Postby mikele » Mon Jan 07, 2019 9:32 pm

Hi,
you can clone a textcursor by creating a new one with the textrange the first defines
Code: Select all   Expand viewCollapse view
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 on LinuxMint/WinXP/Win7
mikele
 
Posts: 52
Joined: Wed Nov 21, 2018 11:11 am
Location: Germany

Re: Cloning a text cursor?

Postby eezacque » Mon Jan 07, 2019 9:42 pm

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
eezacque
 
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests