I reproduce this behavior with versions 5.2, 8.0.4, 12.3.1 and 13.0.1 on Win10 x64.
I would count this as a long-standing FrontEnd bug. An extended example:
CellPrint /@ {
Cell["\"First output from Cell#1\"\n\"Second output from Cell#1. Whoops! How did I get here ???\"", "Input", CellLabel -> "Cell#1"],
Cell["I'll disappear after evaluation of the previous cell!", "Text", CellLabel -> "Cell#2"],
Cell["3", "Input", CellLabel -> "Cell#3"]};
After evaluation of the first printed input cell with label "Cell#1"
, the "Text"
cell with label "Cell#2"
disappears. And the second output from "Cell#1"
is unexpectedly printed after "Cell#3"
!

As a workaround I can suggest using NotebookWrite
instead of CellPrint
:
NotebookWrite[EvaluationNotebook[], #] & /@ {Cell["1\n2", "Input"],
Cell["I won't disappear after evaluation of the previous cell!", "Text"],
Cell["3", "Input"]};

Further observations
It's also worth noting that the documentation for CellPrint
contradicts its observed behavior. In particulat, it states (in the very first section under the function name):
CellPrint[expr]
inserts expr
as a complete cell in the current notebook just below the cell being evaluated.
However, by default CellPrint[expr]
inserts expr
below the last cell generated by the cell being evaluated (and in this sense behaves exactly like Print
):
"Main output"
Print["First Print"]
CellPrint[Cell["First CellPrint", "Input"]]
Print["Second Print"]
CellPrint[TextCell["Second CellPrint", "Text"]]

Something similar to the documented behavior happens when we print cells with GeneratedCell -> False
option. But as one can see, in this case CellPrint[expr]
inserts expr
below the last cell with GeneratedCell -> True
generated by the cell being evaluated:
"Main output"
Print["First Print"]
CellPrint[TextCell["First CellPrint", "Input", GeneratedCell -> False]]
Print["Second Print"]
CellPrint[TextCell["Second CellPrint", "Text", GeneratedCell -> False]]

Hence we also have a Documentation bug.
To summarize the above observations:
CellPrint[expr]
inserts expr
below the cell being evaluated after the last cell with GeneratedCell -> True
above the next cell with GeneratedCell -> False
, even if the latter was generated during current evaluation.
Or shorter (official documentation style):
CellPrint[expr]
inserts expr
just above the next cell with GeneratedCell -> False
, or at the end of the evaluation notebook.
However, in order to fully understand the results of CellPrint
, one must take into account the general behavior of the FrontEnd when it receives the evaluation result (described in the "Explanation" section of the answer by Kuba). In the first place, one should pay attention to the fact that as the first step the FrontEnd deletes all subsequent cells which have CellAutoOverwrite -> True
but not Evaluatable -> True
.
In[]
tags, but you don't say explicitly. I get this output from your code: i.stack.imgur.com/n5TkX.png. I get this when the output is evaluated: i.stack.imgur.com/yI4Mw.png. I get no2
at all. I question whetherCell["1\n2", "Input"]
represents proper input, the cell expression does not containBoxData
. (I don't know the answer, but I ran into trouble with recently.) $\endgroup$1
, return,2
, I get a cell with a cell expression like this:Cell[BoxData[{"1", "\[IndentingNewLine]", "2"}], "Input", CellChangeTimes->{{3.865240719373975*^9, 3.8652407198856688`*^9}}]
, with the input split into a list of strings. $\endgroup$3
, otherwise the2
in output cell will be eaten. $\endgroup$