Hello,

I have some text in QPlainTextEdit, where every line starts with 10 spaces:

Qt Code:
  1. // example:
  2.  
  3. line1
  4. line2
  5. line3
  6. line4
To copy to clipboard, switch view to plain text mode 

Then, I select few lines and in a loop I want to remove first two spaces from all the selected lines:

Qt Code:
  1. // finding the startBlock and endBlock (+1)
  2.  
  3. cursor.beginEditBlock();
  4. for (QTextBlock block = startBlock; block != endBlock; block = block.next()) {
  5. cursor.setPosition(block.position());
  6. cursor.setPosition(block.position() + 2, QTextCursor::KeepAnchor);
  7. cursor.removeSelectedText();
  8. }
  9. cursor.endEditBlock();
To copy to clipboard, switch view to plain text mode 

The problem is that the code above “damages” the last selected line – as if it removed some kind of end-of-line marker – when I want to jump to the end of last line the cursor moves to the line below it, between first and second character. Even the selection does not show up properly after the edit – all the lines but the last one have selection indicator expanded to the right window edge and the last line has the indicator only as wide as the line.

Qt Code:
  1. // after removing the first two characters:
  2.  
  3. line1 < 1. selected lines, run the code
  4. line2 <
  5. line3 < < 2. here I jump to end of line
  6. | line4
  7.  
  8. ^ 3. cursor appears here
To copy to clipboard, switch view to plain text mode 

When I remove `beginEditBlock()` and `endEditBlock()` everything works fine.

Please, does anyone know why is this happening?