5

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"]]]]
Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
yode
  • 26,686
  • 4
  • 62
  • 167
  • @Kuba I'm sorry,I couldn't still understand why I can run normally in third case as you say. – yode Sep 23 '16 at 11:00
  • 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. – Kuba Sep 23 '16 at 11:04
  • 1
    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. – Kuba Sep 23 '16 at 11:08
  • So I'd say All behaves as expected and Previous gives you too much. – Kuba Sep 23 '16 at 11:09
  • @Kuba No need to sorry,you help me all the time.:) Notebook uploading just want to reduce the amount of work for answer.I have read your this comment many times.Thanks for your guess,but I think this is a unexpected behavior still currently. – yode Sep 23 '16 at 11:37
  • 1
    Yep, you can ask WRI Support. – Kuba Sep 23 '16 at 11:37
  • @yode Have you contacted the support? If yes, please share their reply. – Alexey Popkov Oct 07 '17 at 10:23
  • @AlexeyPopkov Although you tag a solved edit just now, but I can reproduce this bug still in v12... – yode Sep 29 '19 at 02:45
  • @yode I received a letter from the support that the problem is resolved, and indeed now SelectionMove returns $Failed when it cannot move the selection in the requested way. As of the case of inconsistent behavior described in the question (I wrote about it too), they say nothing about it. I corrected the bug header. – Alexey Popkov Sep 29 '19 at 07:57
  • @yode I think the bug is finally fixed in version 13.0.0. Please see the new answer. – Alexey Popkov Jan 03 '22 at 08:46
  • @AlexeyPopkov Thanks a lot... – yode Jan 03 '22 at 10:39

2 Answers2

4

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

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
1

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.

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368