1
$\begingroup$

My Questing is very simple. If I have a CellObject e.g. CellObject[Text], I can move the selection to this Cell by just clicking inside of this CellObject.

How can I programmatically move the selection to this CellObject? In other words, how can i trigger this internal "MoveSelectionToCellObject" - token from Code?

I make an example:

nb = CreateDocument[{TextCell["1", "Text"], TextCell["2", "Text"]}]
firstCell = Cells[nb]〚1〛
(* move Selection in nb to firstCell *)

I know there is a function SelectionMove but it seams to move the Selection only relative to some units like cells, but i want to be able to select a specific cell by a CellObject.

$\endgroup$
2
$\begingroup$

SelectionMove works on CellObjects just like on NotebookObjects:

SelectionMove[Cells[nb][[1]], All, Cell]
$\endgroup$
2
  • $\begingroup$ Nice! From the documentation of SelectionMove it was really not clear to me, that one could do that. All examples where exclusivly with NotebookObject and the usage text: "moves the current selection in an open notebook in the front end in the direction dir by the specified unit. " did not made it clear for me, that the object could also be a Cell. Well I just started with this kind of notebookmanipulation, but i think just one example in the documentation about a CellObject would be nice. By the way, thank you for correcting my english :) $\endgroup$
    – sacratus
    Mar 27 '15 at 19:57
  • $\begingroup$ @sacratus notebook programming is fun, good luck. meanwhile, please take a tour $\endgroup$
    – Kuba
    Mar 27 '15 at 19:59

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.