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?
[Solved] Cloning a text cursor?
[Solved] Cloning a text cursor?
Last edited by Hagar Delest on Tue Jan 08, 2019 12:31 am, edited 1 time in total.
Reason: tagged solved
Reason: tagged solved
LibreOffice 6.0.7.3 on Ubuntu 18.04.1
Re: Cloning a text cursor?
/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
Re: Cloning a text cursor?
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?
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
Re: Cloning a text cursor?
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
OpenOffice.org Macros Explained.odt V3
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Cloning a text cursor?
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)...
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
Re: Cloning a text cursor?
Hi,
you can clone a textcursor by creating a new one with the textrange the first defines
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
Re: Cloning a text cursor?
Looks exactly what I need!mikele wrote:Hi,
you can clone a textcursor by creating a new one with the textrange the first defines
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