I've got a list of cells I want to select, but I'd like to do this without the selection cursor moving over each. Is there a way I can do this?
Asked
Active
Viewed 142 times
1 Answers
2
We can do this in a similar way to this. But the trick is simply to start with a FrontEnd`NotebookSuspendScreenUpdates on the notebook in question.
Here's a way to do this:
Options[selectCells] =
Options[NotebookFind];
selectCells[cells : {__CellObject}, ops : OptionsPattern[]] :=
With[{c = GroupBy[cells, ParentNotebook], tag = CreateUUID[]},
KeyValueMap[
CheckAbort[
FrontEndExecute@
FrontEnd`NotebookSuspendScreenUpdates[#];
With[{nb = #},
Map[
Function[
SelectionMove[#, All, Cell, AutoScroll -> False];
FrontEndExecute@
FrontEnd`SelectionAddCellTags[nb, {tag}];
],
#2
]
];
NotebookFind[#, tag, All, CellTags, ops];
FrontEndExecute@
FrontEnd`SelectionRemoveCellTags[NotebookSelection[#], tag];
FrontEndExecute@
FrontEnd`NotebookResumeScreenUpdates[#];,
FrontEndExecute@
FrontEnd`NotebookResumeScreenUpdates[#];
] &,
c
];
c
];
selectCells[cell_CellObject, ops : OptionsPattern[]] :=
selectCells[{cell}, ops]
This we can use this on a list of cells and they will be selected, but without each being visibly selected in turn.
Note that we wrap it in a CheckAbort with a FrontEnd`NotebookResumeScreenUpdates so that if things go pear-shaped we don't lose our screen updating.
This can be made yet more useful, in fact, by including a function to map after the cell has been selected. In doing so one gets a function mapped over cell selections, but without it being visible what's happening.
b3m2a1
- 46,870
- 3
- 92
- 239
selectCells@Cells[][[;; 2]]leaves the selection on those two cells. By the wayselectCells@First@Cells[]throws recursion error. – Kuba Aug 23 '17 at 20:39"SelectNextLine") and b) it's about hiding the selection process, which is very useful -- panning through each selection looks really clumsy. I wouldn't mind if it's closed as a duplicate, but I think at the very least having it here is useful for those who don't think to search for "select to the end". – b3m2a1 Aug 23 '17 at 20:53