Every time I open a new notebook I have to manually evaluate this code in that notebook. In order order to stop my cursor moving to a new cell.
How would I automate this? I would love this functionality to auto-load on startup.
I have tried putting it in a file.m file and adding a Get["/path/to/file.m"] line, to my FileNameJoin[{$UserBaseDirectory , "Kernel", "init.m"}]. Unfortunately this does not work. As it seems to need to be evaluated in the SelectedNotebook[] to work.
Here is the code by @Kuba
With[
{ nb := EvaluationNotebook[]
, c := EvaluationCell[]
}
, With[
{ cv := CurrentValue[nb, {"TaggingRules", "LastCursorPosition"}]
, pos := FrontEndExecute@FrontEnd`UndocumentedGetSelectionPacket[nb]
}
, With[
{ savePosition := (
cv = If[MemberQ[pos, "CharacterRange" -> _], Last["CharacterRange" /. pos], False]
)
}
, SetOptions[nb
, CellEventActions :> {
{"MenuCommand", "HandleShiftReturn"} :> savePosition
, {"MenuCommand", "EvaluateCells"} :> savePosition
, PassEventsDown -> True
}
, CellEpilog :> If[
IntegerQ[cv]
, SelectionMove[c, Before, CellContents]
; SelectionMove[nb, Next, Character, cv]
; cv = False
]
]
]
]
]
Default.nbtoDefaultModified.nb. I am confused. Where do I put your code? Do I paste it somewhere insideDefaultModified.nb? – Conor May 26 '19 at 14:11