forked from qt-creator/qt-creator
TextEditor: use cursor to comment selection
preparation for multi cursor support Change-Id: I57d318ee325e3667a6377a972a0eda66e43d0349 Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
@@ -74,13 +74,14 @@ static bool isComment(const QString &text, int index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &definition,
|
QTextCursor Utils::unCommentSelection(const QTextCursor &cursorIn,
|
||||||
bool preferSingleLine)
|
const CommentDefinition &definition,
|
||||||
|
bool preferSingleLine)
|
||||||
{
|
{
|
||||||
if (!definition.isValid())
|
if (!definition.isValid())
|
||||||
return;
|
return cursorIn;
|
||||||
|
|
||||||
QTextCursor cursor = edit->textCursor();
|
QTextCursor cursor = cursorIn;
|
||||||
QTextDocument *doc = cursor.document();
|
QTextDocument *doc = cursor.document();
|
||||||
cursor.beginEditBlock();
|
cursor.beginEditBlock();
|
||||||
|
|
||||||
@@ -227,9 +228,9 @@ void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &de
|
|||||||
|
|
||||||
cursor.endEditBlock();
|
cursor.endEditBlock();
|
||||||
|
|
||||||
|
cursor = cursorIn;
|
||||||
// adjust selection when commenting out
|
// adjust selection when commenting out
|
||||||
if (hasSelection && !doMultiLineStyleUncomment && !doSingleLineStyleUncomment) {
|
if (hasSelection && !doMultiLineStyleUncomment && !doSingleLineStyleUncomment) {
|
||||||
cursor = edit->textCursor();
|
|
||||||
if (!doMultiLineStyleComment)
|
if (!doMultiLineStyleComment)
|
||||||
start = startBlock.position(); // move the comment into the selection
|
start = startBlock.position(); // move the comment into the selection
|
||||||
int lastSelPos = anchorIsStart ? cursor.position() : cursor.anchor();
|
int lastSelPos = anchorIsStart ? cursor.position() : cursor.anchor();
|
||||||
@@ -240,6 +241,6 @@ void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &de
|
|||||||
cursor.setPosition(lastSelPos);
|
cursor.setPosition(lastSelPos);
|
||||||
cursor.setPosition(start, QTextCursor::KeepAnchor);
|
cursor.setPosition(start, QTextCursor::KeepAnchor);
|
||||||
}
|
}
|
||||||
edit->setTextCursor(cursor);
|
|
||||||
}
|
}
|
||||||
|
return cursor;
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include "utils_global.h"
|
#include "utils_global.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QTextCursor>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QPlainTextEdit;
|
class QPlainTextEdit;
|
||||||
@@ -57,8 +58,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT
|
QTCREATOR_UTILS_EXPORT
|
||||||
void unCommentSelection(QPlainTextEdit *edit,
|
QTextCursor unCommentSelection(const QTextCursor &cursor,
|
||||||
const CommentDefinition &definiton = CommentDefinition(),
|
const CommentDefinition &definiton = CommentDefinition(),
|
||||||
bool preferSingleLine = false);
|
bool preferSingleLine = false);
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -7336,8 +7336,11 @@ void TextEditorWidget::rewrapParagraph()
|
|||||||
|
|
||||||
void TextEditorWidget::unCommentSelection()
|
void TextEditorWidget::unCommentSelection()
|
||||||
{
|
{
|
||||||
Utils::unCommentSelection(this, d->m_commentDefinition,
|
const bool singleLine = d->m_document->typingSettings().m_preferSingleLineComments;
|
||||||
d->m_document->typingSettings().m_preferSingleLineComments);
|
const QTextCursor cursor = Utils::unCommentSelection(textCursor(),
|
||||||
|
d->m_commentDefinition,
|
||||||
|
singleLine);
|
||||||
|
setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorWidget::autoFormat()
|
void TextEditorWidget::autoFormat()
|
||||||
|
Reference in New Issue
Block a user