# How can I make new outline cells be created above the current cell on return?

When you hit enter inside an item styled cell (e.g. Cell["", "Outline1"]), a new cell of the same type is created underneath the cell you are currently editing.

My question is: How can I alter this behavior so that when I type the return key the new cell is be created above it instead of below?

Motivation: A to-do list. I'd like keep adding items at the top of the notebook section.

• Admittedly not a full answer, but this may help: NotebookPut[ Notebook[Reverse[{Cell["number 1"], Cell["number 2"], Cell["number 3"]}]]]; – David G. Stork Jan 16 '15 at 17:09
• Let's say you are editing Cell which is "Outline1" style. Let's say you've typed "test" what is expected layout after hiting Enter? – Kuba Jan 16 '15 at 17:50
• Then a new cell would be created directly above that one and the cursor moves into it... – M.R. Jan 16 '15 at 22:37
• And if that cell had a dingbat with a counter it would be incremented on hitting Enter – M.R. Jan 16 '15 at 22:51
• This is the default behavior of all to-do list apps! – M.R. Jan 16 '15 at 22:52

To add a cell below is trivial because we have the built in option ReturnCreatesNewCell which can be set to True for a given cell style. To add a cell above when you hit Return you can use CellEventActions like this:

Cell[StyleData["ToDo", StyleDefinitions -> StyleData["Text"]],
CellDingbat->StyleBox["\[FilledSmallSquare]", Alignment -> Baseline,
RGBColor[0.8, 0.043, 0.008]],
CounterIncrements->"ToDo",
CellEventActions->{
"ReturnKeyDown":>(
SelectionMove[EvaluationNotebook[], Before, Cell];
NotebookWrite[EvaluationNotebook[], Cell["New Item", "ToDo"]];
SelectionMove[EvaluationNotebook[], Previous,Cell];
SelectionMove[EvaluationNotebook[],Before,CellContents])},

• Nice! This tweak helps: Cell[StyleData["ToDo", StyleDefinitions -> StyleData["Text"]], CellDingbat->StyleBox["\[FilledSmallSquare]", Alignment -> Baseline, RGBColor[0.8, 0.043, 0.008]], GeneratedCell->True, CellAutoOverwrite->True, CellEventActions->{"ReturnKeyDown" :> (SelectionMove[ EvaluationNotebook[], Before, Cell]; NotebookWrite[ EvaluationNotebook[], Cell["", "ToDo"]];SelectionMove[ EvaluationNotebook[], Previous, CellContents]; )}, CellChangeTimes->{3.630533038640272*^9}, CounterIncrements->"ToDo", MenuSortingValue->3, StyleMenuListing->True] – M.R. Jan 18 '15 at 1:28
• @M.R. agree. and also SelectionMove[EvaluationNotebook[],Before,CellContents] – Mike Honeychurch Jan 18 '15 at 1:40