[kdevelop/frameworks] languages/cpp: Port KTE::Document::{endEditing -> finishEditing}

Dominik Haumann dhaumann at kde.org
Tue Mar 25 12:52:21 UTC 2014


On Tuesday, March 25, 2014 09:20:30 Kevin Funk wrote:
> Git commit 5ffe6fadd785b1f96d4c85c705c26093eea1c0fd by Kevin Funk.
> Committed on 25/03/2014 at 08:42.
> Pushed by kfunk into branch 'frameworks'.
> 
> Port KTE::Document::{endEditing -> finishEditing}
> 
> M  +2    -1    languages/cpp/codecompletion/item.cpp
> M  +5    -5    languages/cpp/tests/test_cppcodecompletion.cpp
> 
> http://commits.kde.org/kdevelop/5ffe6fadd785b1f96d4c85c705c26093eea1c0fd
> 
> diff --git a/languages/cpp/codecompletion/item.cpp
> b/languages/cpp/codecompletion/item.cpp index 1cdf6ef..883f18f 100644
> --- a/languages/cpp/codecompletion/item.cpp
> +++ b/languages/cpp/codecompletion/item.cpp
> @@ -41,6 +41,7 @@
>  #include <language/codecompletion/codecompletionhelper.h>
>  #include "context.h"
>  #include <ktexteditor/codecompletioninterface.h>
> +#include <ktexteditor/document.h>
>  #include <ktexteditor/movingrange.h>
>  #include <ktexteditor/movinginterface.h>
>  #include <memory>
> @@ -339,7 +340,7 @@ void
> NormalDeclarationCompletionItem::execute(KTextEditor::View* view, const KTe
> if(!removeRange.isEmpty() && removeRange.end() > end && removeRange.end().line() == end.line() && removeRange.end().column() <= document->lineLength(removeRange.end().line())) {
>        // We stop the editing sequence, which was initiated by kate, so the user can manually undo the removal
> -      bool wasEditing = document->endEditing();
> +      bool wasEditing = document->finishEditing();
>        if(wasEditing)
>          document->startEditing();

That code looks suspicious:

0335   if(removeInSecondStep)
0336   {
0337     KTextEditor::Range removeRange = removeInSecondStep->toRange();
0338     if(!removeRange.isEmpty() && removeRange.end() > end && removeRange.end().line() == end.line() && removeRange.end().column() <= document->lineLength(removeRange.end().line()))
0339     {
0340       // We stop the editing sequence, which was initiated by kate, so the user can manually undo the removal
0341       bool wasEditing = document->finishEditing();
0342       if(wasEditing)
0343         document->startEditing();
0344       else
0345         kWarning() << "Was not editing";
0346       document->removeText(removeRange);
0347     }
0348   }
0349 }

Can you guarantee that finishEditing() is only called after startEditing() was called?

If not, you potentially hit the following assert:

bool KTextEditor::DocumentPrivate::editEnd()
{
    if (editSessionNumber == 0) {
        Q_ASSERT(0);
        return false;
    }

Greetings,
Dominik


More information about the KDevelop-devel mailing list