#49 Insertion of text, removing selection

SVN
closed-fixed
QCodeEdit (16)
1
2009-07-20
2009-02-16
No

To replace a text by another, i must call removeSelectedText :

m_editControl->editor()->cursor().removeSelectedText();
m_editControl->editor()->cursor().insertText( "Test\nTest2\n Test3" );

Is it possible that insertText call removeSelectedText (has made when the user wrote text and a text is selected) ?

Thanks

Discussion

  • fullmetalcoder
    fullmetalcoder
    2009-02-16

    QEditor::write(const QString&) is your friend :D

    As a bonus it takes auto-indent and cursor mirrors into account.

     
  • fullmetalcoder
    fullmetalcoder
    2009-02-16

    • assigned_to: nobody --> fullmetalcoder
    • status: open --> open-invalid
     
    • priority: 5 --> 1
    • summary: Blank at the start of file --> Insertion of text, removing selection
     
  • Ok in this case.
    But in case where we made

    QDocumentCursor t( m_editControl->editor()->document() );
    t.movePosition(..., QDocumentCursor::MoveAnchor);
    t.movePosition(..., QDocumentCursor::KeepAnchor);
    t.insertText(...);
    t.movePosition(...);
    t.....

    the cursor should be remove the selected text.

    It's not important, but nearlier of QTextCursor (of Qt API)

     
  • fullmetalcoder
    fullmetalcoder
    2009-02-16

    I dunno why but I thought QTextCursor did not clear the selected text when insertText was called.

    I have corrected that. Thanks for reporting.

    cheers

    luc

     
  • fullmetalcoder
    fullmetalcoder
    2009-02-16

    • status: open-invalid --> open-fixed
     
  • fullmetalcoder
    fullmetalcoder
    2009-07-20

    • status: open-fixed --> closed-fixed