I'd like to suggest a slightly different approach. Instead of removing the current line and inserting the shortened line (which struggles at the end of the text), you can set the cursor selection to the trailing whitespaces at the end of the line and remove it if the selection isn't empty. This wouldn't touch lines that don't need changes and processes faster for texts with many lines. The move operations of the cursor allow to decide if you move the anchor (selection-start).
Remark for GitHub: This branch merges to master but it should merge to develop
I'd like to suggest a slightly different approach. Instead of removing the current line and inserting the shortened line (which struggles at the end of the text), you can set the cursor selection to the trailing whitespaces at the end of the line and remove it if the selection isn't empty. This wouldn't touch lines that don't need changes and processes faster for texts with many lines. The move operations of the cursor allow to decide if you move the anchor (selection-start).
Remark for GitHub: This branch merges to
master
but it should merge todevelop