5
$\begingroup$

Bug introduced in 11.2 or earlier, partially fixed in 12.0 and finally fixed in 13.0 [CASE:3968507]


(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"]]]]
$\endgroup$
11
  • $\begingroup$ @Kuba I'm sorry,I couldn't still understand why I can run normally in third case as you say. $\endgroup$
    – yode
    Commented Sep 23, 2016 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
    Commented Sep 23, 2016 at 11:04
  • 1
    $\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
    Commented Sep 23, 2016 at 11:08
  • $\begingroup$ So I'd say All behaves as expected and Previous gives you too much. $\endgroup$
    – Kuba
    Commented Sep 23, 2016 at 11:09
  • 1
    $\begingroup$ Yep, you can ask WRI Support. $\endgroup$
    – Kuba
    Commented Sep 23, 2016 at 11:37

2 Answers 2

1
$\begingroup$

I notice that some changes in the behavior of SelectionMove occurred on the transition from version 12.3.1 to 13.0.0.

  1. Changed the behavior of SelectionMove[EvaluationCell[], Previous, CellGroup]. Now it selects the previous CellGroup, even if between the previous CellGroup and the EvaluationCell[] present several cells which aren't a member of a CellGroup. Here is a screenshot of a version 13.0.0 Notebook right after applying the menu item Evaluation ► Evaluate Notebook:

    screenshot

    And here is what happens in version 12.3.1:

    SCREENSHOT2

    The new behavior is more consistent. So the inconsistency described in the question is finally fixed in version 13.0.0.

  2. In the same way changed the behavior of SelectionMove[PreviousCell[], Previous, CellGroup]. Now it selects the CellGroup before the PreviousCell[] even if PreviousCell[] is a member of a CellGroup itself. Here is a screenshot of a version 13.0.0 Notebook right after applying the menu item Evaluation ► Evaluate Notebook:

    screenshot3

    And here is what happens in version 12.3.1:

    screenshot4

So this aspect of the behavior of SelectionMove is finally fixed in version 13.0.0.

$\endgroup$
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$
1
  • $\begingroup$ Reported to the support as [CASE:3968507]. $\endgroup$ Commented Nov 5, 2017 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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