How to save cursor position in Writer?

Shift+F5 is supposed to take you to the last edit position (which normally involves cursor). It works in my Linux version 7.5.3.2. (Be sure F5 doesn’t require Fn key, like in my case.)
The shortcut corresponds to “Restore editing view” command (Tools-Customize-Keyboard) and you could try/add a different shortcut. I am using Shift-Delete.

This seems to be related to re-occurring issues. The unbroken default functionality seems to try to open a writer document at the position where the user now opening it last had placed the view cursor.

Even a single user, however, may want to choose one of a couple of positions where he(f/m) recently worked. To be able to do so, he would need to set bookmarks automatically given a name referring to the current user (more precisely: the user registered to the currently open user-profile) and the current date-time as well.

This may sound a bit complicated, but it can be done by simple user code which may be assigned to a keyboard shortcut or to a different trigger (toolbar area, button action).

I suppose (but didn’t test) the routine can be called by an onDocumentGoingToBeClosed event.
Surely it’s extremely simple to navigate using bookmarks, and also to remove those no longer being needed.

The code:

Sub createUserNamedDTstampedSinglePositionBookmark(Optional dummy)
cDoc       = ThisComponent
If NOT cDoc.supportsService("com.sun.star.text.TextDocument") Then Exit Sub
REM hard-coded names
Const dataNode      = "/org.openoffice.UserProfile/Data"
Const useAsID       = "initials"
REM format strings
Const longDTformat  = "YYYY-MM-DD_HH:MM:SS"
Const shortDTformat = "YYYYMMDDHHMMSS" REM preferred by my current camera, e.g. 
REM Assumed preferrences
Const dtDelim       = "_" REM inserted between user ID and dat.
Const bookmarkStart = False
cCtrl      = cDoc.CurrentController
cSel       = cCtrl.Selection
If cSel.Count>1 Then Exit Sub
REM Bookmark shall point to a single position. User should define it unambiguosly.
insPos     = IIf(bookmarkStart, cSel(0).Start, cSel(0).End)
newBm      = ThisComponent.createInstance("com.sun.star.text.Bookmark")
newBmN     = simplePropertyValueFromRegistryModificationsXcu(dataNode, useAsID)
newBmN     = newBmN & dtDelim & Format(Now(), longDTformat)
newBm.Name = newBmN 
cText      = insPos.Text
insCur     = cText.createTextCursorByRange(insPos)
cText.insertTextContent(insCur, newBm, False)
End Sub

REM Thanks to the documents by Andrew Pitonyak I could easily code this needed helper: 
'
Function simplePropertyValueFromRegistryModificationsXcu(pNodePath As String, pPropertyName As String) As Variant
simplePropertyValueFromRegistryModificationsXcu = ":err:"
On Local Error Goto fail
Dim structNode, providerSrv
Dim arguments(0) As New com.sun.star.beans.PropertyValue
Const providerSrvN = "com.sun.star.configuration.ConfigurationProvider"
Const structNodeN  = "com.sun.star.configuration.ConfigurationAccess"
providerSrv        = createUnoService(providerSrvN)
arguments(0).Name  = "nodepath"
arguments(0).Value = pNodePath
structNode         = providerSrv.createInstanceWithArguments(structNodeN, arguments())
simplePropertyValueFromRegistryModificationsXcu _
                   = structNode.getPropertyValue(pPropertyName)
fail:
End Function
2 Likes