Bug introduced in 11.2 or earlier and partially fixed in 12.0 [CASE:3968507]
Now SelectionMove
returns $Failed
when it cannot move selection in the requested way, but inconsistent behavior described in the question is still here.
(Cross-posted at Wolfram Community.)
I think this is a bug. If someone can help to confirm it, I'll report it to Wolfram. I can selet previous cell group:
SelectionMove[PreviousCell[], All, CellGroup]
But I fail to do this like follows
Maybe you will say that it is a Cell
not a CellGroup
, but why I can do this:
Can anyone give a reasonable explanation? You can get the .nb
test file by run
NotebookPut[Uncompress[First[Values[Databin["fVOforSX"]]["nb"]]]]
Answer
This indeed looks like a bug. Citing the Documentation page for SelectionMove
:
SelectionMove
returns$Failed
if it cannot move the selection in the way you request.
In your example SelectionMove
obviously fails but returns Null
instead of $Failed
what directly contradicts the Docs.
One workaround is to check whether the selection is empty (SelectionMove
failed) and if so to attempt to select Cell
instead of CellGroup
:
SelectionMove[PreviousCell[], All, CellGroup];
If[SelectedCells[] === {},
SelectionMove[PreviousCell[], All, Cell]];
Another way is to rely upon the working functionality:
SelectionMove[PreviousCell[], Before, CellGroup]
SelectionMove[EvaluationNotebook[], Next, CellGroup]
(instead of EvaluationNotebook[]
one can use ParentNotebook@PreviousCell[]
).
Comments
Post a Comment