Bug 295632

Summary: replacing a text selection spanning folded code messes up text
Product: [Applications] kate Reporter: Dominik Haumann <dhaumann>
Component: partAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: major CC: christoph, pascal.letourneau
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Dominik Haumann 2012-03-09 19:43:00 UTC
Insert the following text into the editor:
oooossssssss
{

}
ssssss----------

1. select C++ highlighing
2. fold the code
3. select text from o|s to s|- (the fold is still folded)
4. type x

Expected result: oooox----------
Actual result: oooo------x----

The folded node somehow leads to broken code. This bug exists also in KDE 4.6. Maybe this is related to crashes, so the severity is set to major.

kate/part/tests/foldedselection_test.cpp contains a unit test for this.
Comment 1 Dominik Haumann 2012-03-09 19:45:21 UTC
Git commit 9a058c00b71de765753ccbeaa583f55082630715 by Dominik Haumann.
Committed on 09/03/2012 at 20:43.
Pushed by dhaumann into branch 'master'.

unit test for broken text after replacing folded code

M  +11   -0    part/tests/CMakeLists.txt
A  +80   -0    part/tests/foldedselection_test.cpp     [License: LGPL (v2+)]
A  +36   -0    part/tests/foldedselection_test.h     [License: LGPL (v2+)]

http://commits.kde.org/kate/9a058c00b71de765753ccbeaa583f55082630715
Comment 2 Christoph Cullmann 2012-03-09 21:41:30 UTC
Git commit 4bcccf2906139ed523567f242464cf927e393716 by Christoph Cullmann.
Committed on 09/03/2012 at 22:41.
Pushed by cullmann into branch 'master'.

fix problem with folding and deletion of selection, fixes foldedselection_test

M  +1    -10   part/document/katedocument.cpp
M  +2    -0    part/view/kateviewinternal.cpp

http://commits.kde.org/kate/4bcccf2906139ed523567f242464cf927e393716
Comment 3 Dominik Haumann 2012-03-10 09:12:15 UTC
The following part (and more) was added by commit http://websvn.kde.org/?revision=1064050&view=revision to fix bug #200858

  m_preserveX = true;
  KTextEditor::Cursor newPos = toRealCursor(toVirtualCursor(m_cursor));
  KateTextLayout newLine = cache()->textLayout(newPos);
  newPos = renderer()->xToCursor(newLine, m_preservedX, !m_view->wrapCursor());
  updateCursor(newPos, true);

Pascal, Milian: Do you still remember what went wrong without this code in bug #200858 ?
Comment 4 Christoph Cullmann 2012-03-10 11:26:04 UTC
In any case: moving the cursor is a bad idea here, as then it will have a wrong position for next editing actions ;)
The problem is that m_cursor might still be wrong I think.
And after my testing, it just looked ok. But perhaps there is a corner case when the cursor is hidden in the region.
Comment 5 Dominik Haumann 2013-04-16 13:01:29 UTC
Git commit e68d2ccf57462a057306e777c2a7960a8338182e by Dominik Haumann.
Committed on 16/04/2013 at 14:59.
Pushed by dhaumann into branch 'master'.

bring back test for bug 295632

This test makes sure that,
- if you have selected text
- that spans a folded range,
- and the cursor is at the end of the text selection,
- and you type a char, e.g. 'x',
then the resulting text is correct, and changing region
visibility does not mess around with the text cursor.

M  +39   -0    tests/katefoldingtest.cpp
M  +1    -0    tests/katefoldingtest.h

http://commits.kde.org/kate/e68d2ccf57462a057306e777c2a7960a8338182e