Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-23131

Beautifier: FormatAtCursor formats at wrong position

    XMLWordPrintable

Details

    • All
    • efa9d258a267f42234bfc30293f2b8eae702166e (qt-creator/qt-creator/master)

    Description

      I have bound the action ClangFormat > FormatAtCursor to a keyboard shortcut which I often use to format code while editing.

      The problem is when the text beforce the cursor contains umlauts the wrong text is formatted.

      example.cpp
      int main()
      {
      	int a1 ;
      	int a2 ;
      	int a3 ;
      	int a4 ;
      	// ääääääääääääääääääää
      	int a5 ;
      	int a6 ;
      	int a7 ;
      	int a8 ;
      	int a9 ;
      }
      

      When I position the cursor before a8, the lines containing a6 and a7 are formatted.

      The problem is, that ClangFormat::formatAtCursor() forwards the wrong offset to clang-format.
      The offset is the character position, but clang-format expect the position in bytes.

       

      Perhaps not directly related, but If I add the character '���' at the beginning of the document it even deletes text, which doesn't happen when I invoke clang-format from the command-line:

      // ���
      int main()
      {
      	int a1 ;
      	it a2 ;
      	it a3 ;
      	it a4 ;
      	/ ääääääääääääääääääää
      	int a5 ;
      	it a6 ;
      	it a7 ;
      	it a8 ;
      	int a9 ;
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            con Eike Ziller
            mkrems Marcel Krems
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes