The last value of a script is the return value, so with an existing script appending new variable declarations at the end seems counter-intuitive. But we can't directly use the cursor position, because if the cursor is inside a line then it will break the existing line. So I think what can happen is to insert the new variable as a new line above or below the current line the cursor is at. Whether above or below should be used needs some consideration (I think above is better).
Git commit ba6a0931c15fd49177095a76a7e0600dfd34b829 by L. E. Segovia. Committed on 28/06/2021 at 21:49. Pushed by lsegovia into branch 'master'. Insert new variables above the current line That will preserve the last line (the return value). M +3 -1 src/KSeExprUI/ExprEditor.cpp https://invent.kde.org/graphics/kseexpr/commit/ba6a0931c15fd49177095a76a7e0600dfd34b829
Seems like it is inserting the new variable line before the line above the current line, not just above the current line.
Git commit 5d323abb9a8e694deac7ae969f3058ad520ceed2 by L. E. Segovia. Committed on 30/06/2021 at 21:33. Pushed by lsegovia into branch 'master'. Insert new variables at the start of the current line M +0 -1 src/KSeExprUI/ExprEditor.cpp https://invent.kde.org/graphics/kseexpr/commit/5d323abb9a8e694deac7ae969f3058ad520ceed2