I attempted to factorise $x^2-x+1$, which seemed fairly straightforward:
$$ \begin{align} x^2-x+1 &= (x+1)^2-3x \\ &= (x+1-\sqrt{3x})(x+1+\sqrt{3x}) \\ &= (x-\sqrt{3x}+1)(x+\sqrt{3x}+1) \end{align}$$
Technically neither $(x-\sqrt{3x}+1)$ nor $(x+\sqrt{3x}+1)$ are linear functions, which is why I didn't get the "correct" answer:
$$(x-\frac{1}{2}-i\frac{\sqrt{3}}{2})(x-\frac{1}{2}+i\frac{\sqrt{3}}{2})$$
But I am curious as to why Desmos only considers the positive cases of $x$? If $(x-\sqrt{3x}+1)(x+\sqrt{3x}+1)$ does expand perfectly into $x^2-x+1$, why isn't it graphed the same way?
Desmos interprets it as a real function $\Bbb R\to\Bbb R$, and the square root - which is included in your formula - isn't defined for negative values (when $3x<0$ i.e. $x<0$).
For the quadratic: when you pull out, half the coefficient of $x$: $$x^2-\underline1\cdot x+1=(x-\underline{1/2})^2+\dots$$