Set bookmark at last cursor position

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
dgermann
Posts: 26
Joined: Wed May 05, 2010 3:54 am

Set bookmark at last cursor position

Post by dgermann »

Friends--

Hagar Delest pointed me to this thread from the ubuntu forum. Thank you, Hagar!

Being new to macros, I don't know what to do with the macro file I downloaded from the first post in this thread, nor what to do with Hagar's edited one: would like it just to work by default in all my documents.

Thanks!

:- Doug.

Split from Automatically setting bookmarks with strictly formatted names (Hagar, Moderator).
:- Doug.
LO 7.3.6.2, Ubuntu 22.04
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Setting bookmark for last cursor position

Post by Hagar Delest »

Start here (includes another link for macro installation): [Tutorial] Binding a macro: Shortcut key, menu or toolbar.

I've split your post since the the original topic is not for questions.

Please add [Solved] at the beginning of the title in your first post (top of the topic) with the 🖉 button if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
dgermann
Posts: 26
Joined: Wed May 05, 2010 3:54 am

Re: Setting bookmark for last cursor position

Post by dgermann »

Hagar--

Thank you for splitting this thread off.

I have followed the instructions and pulled your code into a macro, and got it working in a couple of test files. I have another one that is 713 pages long, and it does not seem to work there. Is there a size limit for your code? Does it matter which of the 5 choices your macro gives? I have been using gotolasttypist one.

I will play with it a bit more, too.

Thanks, Hagar!
:- Doug.
LO 7.3.6.2, Ubuntu 22.04
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Setting bookmark for last cursor position

Post by Hagar Delest »

Indeed, there is a longstanding issue with both AOO/LO, it is the time needed to repaginate a long document.
Either you wait few seconds or you relaunch the macro. Personally, it's triggered by a toolbar button. Thus, in such case I click several times until either the position is retrieved (from what I remember of the last position), or until it doesn't move again.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Setting bookmark for last cursor position

Post by RoryOF »

Although my computers reliably move me to the last cursor position in a Saved file, this is not always what I require - as the Saved cursor position may reflect an incidental correction. I often insert a Comment at the last major editing position, and use the Navigator to go to that location.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
dgermann
Posts: 26
Joined: Wed May 05, 2010 3:54 am

Re: Setting bookmark for last cursor position

Post by dgermann »

RoryOF--

I have used bookmarks in much the same way: I have a bookmark set to the next paragraph, which is seldom if ever edited.

Hagar--

The macro you had stopped working for me, even in shorter documents. So I tried the one in the first post (by Lupp), and that is not working for me reliably. Do I run the macro after I open the document? That seems wrong, and anyway it does not work for me.

Thanks to each of you!
:- Doug.
LO 7.3.6.2, Ubuntu 22.04
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Setting bookmark for last cursor position

Post by Hagar Delest »

You have to call SaveLastEditPosition when you close the file (or when you need to place the bookmark). And then you call GotoCurrenttypistLastPositionBookmark when you need to go to that last recorded position.

It is very easy to see if it works or not: in the Navigator, display the bookmarks and you'll see the bookmark "- Last Edit Position - " (with my version) that should be at the top, with your initials if filled in in the Tools > Options > LO/AOO > User data.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Setting bookmark for last cursor position

Post by John_Ha »

If you put something in Tools > Options > OpenOffice > General > Surname/Forename, Initials ..., to identify yourself so that AOO knows it is you editing it (it's a privacy thing), Writer opens the document at the position the cursor was when the document was last saved. If the fields are empty, or a different user opens it, Writer opens at the start of the document.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Setting bookmark for last cursor position

Post by Hagar Delest »

That feature is broken in LibreOffice. That's the point of this thread.
AOO used to work quite well for that.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Setting bookmark for last cursor position

Post by John_Ha »

Hagar Delest wrote: Thu Nov 17, 2022 7:09 pm That feature is broken in LibreOffice.
It must be broken LO under Ububtu/Linux as it works for me in both AOO and LO under W10. A quick test shows that it works with something in only the LO Surname field but, surprisingly, not with something in only the Initials field (IIRC the Initials field is used to identify the editor in Record changes).
Attachments
Clipboard02.gif
Clipboard02.gif (8.51 KiB) Viewed 2390 times
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Setting bookmark for last cursor position

Post by RoryOF »

I've just tested several time using LibreOffice 7.2 on Xubuntu 22.04. LibreOffice remembered my last editing position every time, but the file has to have been edited and Saved.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
dgermann
Posts: 26
Joined: Wed May 05, 2010 3:54 am

Re: Setting bookmark for last cursor position

Post by dgermann »

Hagar--

Well now, I had not thought to look in the navigator--I seldom use it. I will have to check that upon opening files.

John_Ha--

Well now, I had previously tried with one letter only in the first name position, and then tested with something in all the positions. I will try only in the last name position.

Nope. Opened to page 1 of my 714 page document, instead of page 648.

I am running lo 7.3.6.2 under ubuntu 22.04.

RoryOF--

Thanks! I may have to get and try lo 7.2.

Hagar, John_Ha, RoryOF--thank you each!
:- Doug.
LO 7.3.6.2, Ubuntu 22.04
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Setting bookmark for last cursor position

Post by John_Ha »

Test with a 2 page document and I think it will work.

A complex 648 pages document (eg with images, tables and/or footnotes) probably takes ages (30+ minutes) to lay out and the cursor probably cannot be positioned until layout has finished. Test by leaving it until the Task Manager says LO cpu had fallen to very low. See 11A. Why is my page count so high? Why does my page count keep changing? Why do white gaps appear in my document? in [Tutorial] Some useful hints on using images for a discussion of the problem.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Setting bookmark for last cursor position

Post by Hagar Delest »

The feature is broken in LO in both Windows 10 and xubuntu 22.10. But it is linked to the LO version. It used to work until 7.0 then broken in 7.1, then not broken in 7.2 and then broken again. Currently broken for sure with LO 7.4.
dgermann wrote: Thu Nov 17, 2022 10:14 pm Well now, I had not thought to look in the navigator--I seldom use it. I will have to check that upon opening files.
It is only a workaround. Creating a toolbar button and assigning it the proper macro should do it. Except that you may have to wait few seconds in case you have a complex document, giving LO some time to repaginate. Beware that the macro should be GotoCurrenttypistLastPositionBookmark, not the first one of course.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Setting bookmark for last cursor position

Post by John_Ha »

I have just tested LO under W10 with 1,612 pages and 1.2 million words (four copies of Vanity Fair) and it opens at the last cursor position wherever it is in the document. It takes about 3 or 4 seconds as it is a simple document - just text - so it lays out quite quickly.

It strongly suggests to me that dgerman's document does not open at the cursor position for one of two reasons. It either takes so long to lay out that LO abandons waiting and opens at the beginning; or if he waits long enough, it will jump to the cursor position.

The first is probably correct as it allows the user to continue working while the documents is still being laid out.

What version of LO are you using? That being said, I doubt it is an LO version or OS specific bug because the cursor position is written into the settings.xml file and that should be pretty stable code.
Last edited by John_Ha on Thu Nov 17, 2022 11:13 pm, edited 1 time in total.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Setting bookmark for last cursor position

Post by Hagar Delest »

What LO version?
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Setting bookmark for last cursor position

Post by RoryOF »

My document was text only book text and layout, of 91,000 words, 335 A5 pages. I had entered First and Last Name and Initials in /Tools /Options etc.

I also use Comments/Annotations with a first word of significance such as "Revise", or "Rewrite"to navigate about the document, using the Navigator; these take longer to become established when the document is opened.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Setting bookmark for last cursor position

Post by Hagar Delest »

I can't use the Navigator because I have zillions of tables that clutter it. Thus, the Navigator is locked to the headings so that I can quickly navigate based on the headings. There is still the sidebar if I need another non-filtered instance of the Navigator but still cumbersome. Having to click a button is much easier for me. But I need only one position recorded, the last one.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Setting bookmark for last cursor position

Post by John_Ha »

I don't have my laptop with the LO version on it with me. I had added the LO version to the post but it seemed to get dropped off somehow. Possibly 7.1.8.1??? I'll confirm tomorrow.

A clunky workaround is to use an icon to add something like qwerty at the cursor position.
Search for it where the search could be an event triggered by opening the document which might even delete the qwerty ...

A master document with numerous sub-documents may also be worth looking at.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Setting bookmark for last cursor position

Post by John_Ha »

John_Ha wrote: Fri Nov 18, 2022 1:32 am I'll confirm tomorrow.
I tested my home PC. LO 7.0.6.2 under W10 opens six copies of Vanity Fair (2,500 A4 pages, 1.8 million words, all text, no images, tables, footnotes, fancy formatting etc) in about eight seconds at the cursor position even when the cursor is close to the last page.

Another workaround. Define a heading called Cursor with text cursor. Use an icon on the toolbar to insert it, or insert it as an event when the document is closed. Search for it (as an event?) when you open the file.

To speed the layout of a large, complex file add redundant page breaks about every 50 pages throughout. These catch the spills during layout and prevent them propagating throughout the rest of the file.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Setting bookmark for last cursor position

Post by John_Ha »

I downloaded the latest so called "Stable" version 7.3.7.2 and it does not locate to the cursor position even in a small document. Furthermore, whereas 7.0.6.2 opened six copies of Vanity Fair at the cursor location in about eight seconds, 7.3.7.2 gives me a spinning wheel for about 90 seconds during which I am locked out and then the cursor is at the beginning.

I hate *##'!%#* LibreOffice. Every new release is worse than the previous version and has more bugs in it. Lots of new features, yes. But what use are new features when basic things don't work? The developers should spend more time testing and less time adding new features.

I'll raise yet another bug report ...
.
 Edit: Even that is difficult. There is no link to raise bugs on the https://www.libreoffice.org and searching with bug report finds nothing.

Digging around I found Feedback where I was going to leave a comment and it has "Create a bug report". You will note it has the word bug and the word report in it yet the search did not find it. Who writes this stuff? 
.
 Edit: See Bug 152097 - Writer document does not open at last cursor position 
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Setting bookmark for last cursor position

Post by John_Ha »

Even more interesting - it is quite random!.

I have updated the bug report with
I attach fred.odt which I am using for testing.

The behaviour is quite random and the document opens with the cursor at different positions on each opening. Some of the locations of the cursor are repeated on different openings but none are where the cursor was located when the document was saved.

I reset the profile and added back the User Data. The random behaviour continued.
Attachments
fred.odt
(57.42 KiB) Downloaded 53 times
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Setting bookmark for last cursor position

Post by John_Ha »

LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Setting bookmark for last cursor position

Post by Hagar Delest »

Hi John,

In fact, all those posts just to confirm what Doug and I have reported from the beginning...

At least I learned something: a kind of master bug report has been opened -> Bug 141586 - Restoring last document position is unreliable.

The timeline is quite interesting:
- Hot discussion in the ask.libreoffice channel and then in the bug report Bug 140147 - position of cursor not saved
- After that discussion, bug opened for the very same issue (what's the point?), without even informing the "initial" bug report: Bug 141586 - Restoring last document position is unreliable.
:roll:
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Setting bookmark for last cursor position

Post by JeJe »

Here's a simple alternative, save and restore the scroll position:

https://forum.openoffice.org/en/forum/v ... p?t=108901
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Set bookmark at last cursor position

Post by Lupp »

This topic was split off from a "code-snippet-topic" I had started. Now I'm somehow unhappy about the way the discussion took, and want to state that I was well aware of the use-case to get bookmarked "the last cursor position" for probably more than one user in the same document, but mainly wanted to provide the basis for time-stamped bookmarks depending on "this or that" in a flexible way.

Concerning the "last position per profile owner" I should have emphasied the suggestion to include and customize as event handler the following piece of code:

Code: Select all

Function onGoingToBeClosed(Optional pEvent) As Boolean
createUserNamedDTstampedSinglePositionBookmark()
onGoingToBeClosed = True
End Function
Also: Two lines of the code published in the demo to the snippet might be changed
Line 27 to

Code: Select all

insPos     = IIf(bookmarkStart, cSel(0).Start, cSel(0)) REM  .End() removed
Line 34 to

Code: Select all

cText.insertTextContent(insCur, newBm, True) REM Now True instead of False 
This alows the bookmark to link to a range instead of a single position.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Hagar Delest
Moderator
Posts: 32657
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Set bookmark at last cursor position

Post by Hagar Delest »

Topic split, the one for the last cursor position is now: Set and retrieve last cursor position (with a bookmark).
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Post Reply