Move Line Up in C# TextBox like in VS
I am working on a Notepad clone and I want to create the move line up/down feature that is so common in editors. I believe in VS it is Alt+Up/Alt+Down. I was wondering how can I do this, or if someone has done it before, if you don't mind sharing your code. I might probably have to remove the current line's content and then insert it at a higher line index but what if there is already a non-empty line above? Would appreciate help on this.
2 Replies
split by new line, move the lines, join back
What do you think code-wise? I tested and it works. One annoying thing is that the caret visibly, even if ever so quickly, changes position.
I took care of that with BeginChange() and EndChange()