Fix bug in graph drawing (would not exit out of graph mode in certain conditions), in partial expression input (would not discard input and its offset if pressing custom key or launching a script), and simplify code.