4
$\begingroup$

Bug introduced in 11.2 or earlier and fixed in 12.0 [CASE:3968507]


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"]]]]
$\endgroup$
  • $\begingroup$ @Kuba I'm sorry,I couldn't still understand why I can run normally in third case as you say. $\endgroup$ – yode Sep 23 '16 at 11:00
  • $\begingroup$ Ah, I'm sorry, I missed the point. This is the problem when one has to rewrite the code himself. Sorry again, it indeed looks like an inconsistency. ps. Don't attach notebooks, they are not safe in general so people are not going to download it very often. $\endgroup$ – Kuba Sep 23 '16 at 11:04
  • $\begingroup$ Here is my guess: All CellGroup is trying to reach CellGroup from the bottom, it fails so there is no selection. Previous CellGroup is trying to find it from the "top", so it narrows down selection up to a single cell, it fails but the cell is already selected. Just a guess. $\endgroup$ – Kuba Sep 23 '16 at 11:08
  • $\begingroup$ So I'd say All behaves as expected and Previous gives you too much. $\endgroup$ – Kuba Sep 23 '16 at 11:09
  • 1
    $\begingroup$ Yep, you can ask WRI Support. $\endgroup$ – Kuba Sep 23 '16 at 11:37
4
$\begingroup$

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[]).

$\endgroup$
  • $\begingroup$ Reported to the support as [CASE:3968507]. $\endgroup$ – Alexey Popkov Nov 5 '17 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.