Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-122701

Extend TextInput.cursorPosition documentation even more

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Quick: Other
    • None

    Description

      ... I see there has been attempt to improve the docs few years back QTBUG-97169.

      The only legal cursor positions is between graphemes, but TextInput.cursorPosition lets you use any value. For example, pos==1 is in middle of grapheme. It draws cursor at correct location, but does not reflect the "adjustment" in TextInput.cursorPosition property value. Example:

      import QtQuick
      
      Window {
          id: win
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          TextEdit {
              id: input
              color: "red"
              text: "செa"
              width: parent.width * 0.25;
              wrapMode: Text.WrapAnywhere
              height: 40
              anchors.centerIn: parent
              focus: true
              Component.onCompleted: input.cursorPosition = 0
              onCursorPositionChanged: console.log("cursor pos: " + input.cursorPosition)
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: input.cursorPosition++
          }
      }
      

      It appears that is easy to misuse this API.

      I think documentation should clarify that cursor values should be obtained from other APIs. At least that is my current understanding. Feel free to correct me by extending the documentation.

      What are the use cases that developer would want to set this value? To programmatically move the cursor around for some custom logic? That is plausible, but wouldn't we then need qml API equivalents for QTextLayout's functions that know where is the next/prev valid pos or QTextBoundaryFinder?

       int QTextLayout::nextCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
       int QTextLayout::previousCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
       int QTextLayout::leftCursorPosition(int oldPos) const;
       int QTextLayout::rightCursorPosition(int oldPos) const;
      

      And on the same topic, the documentation should clarify how should the position values be obtained for the following APIs. The regular qml developer does not know all the implications of string indices, grapheme clusters, ligatures and what not. And might not know that he/she/they is writing a code that won't work for complex Unicode script languages.

      string getText(int start, int end)
      insert(int position, string text)
      remove(int start, int end)
      select(int start, int end)
      

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              paeglis Gatis Paeglis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes