diff options
Diffstat (limited to 'src/gui/text/qtextcursor.cpp')
-rw-r--r-- | src/gui/text/qtextcursor.cpp | 86 |
1 files changed, 36 insertions, 50 deletions
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp index a27ef81500..5730f55e6a 100644 --- a/src/gui/text/qtextcursor.cpp +++ b/src/gui/text/qtextcursor.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qtextcursor.h" #include "qtextcursor_p.h" @@ -612,7 +576,7 @@ bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor ++row; } cell = table->cellAt(row, column); - // note we also continue while we have not reached a cell thats not merged with one above us + // note we also continue while we have not reached a cell that's not merged with one above us } while (cell.isValid() && ((op == QTextCursor::NextRow && currentRow == cell.row()) || cell.row() < row)); @@ -625,7 +589,7 @@ bool QTextCursorPrivate::movePosition(QTextCursor::MoveOperation op, QTextCursor --row; } cell = table->cellAt(row, column); - // note we also continue while we have not reached a cell thats not merged with one above us + // note we also continue while we have not reached a cell that's not merged with one above us } while (cell.isValid() && ((op == QTextCursor::PreviousRow && currentRow == cell.row()) || cell.row() < row)); @@ -1459,28 +1423,28 @@ void QTextCursor::insertText(const QString &text, const QTextCharFormat &_format QTextBlockFormat blockFmt = blockFormat(); - int textStart = d->priv->text.length(); + int textStart = d->priv->text.size(); int blockStart = 0; d->priv->text += text; - int textEnd = d->priv->text.length(); + int textEnd = d->priv->text.size(); - for (int i = 0; i < text.length(); ++i) { + for (int i = 0; i < text.size(); ++i) { QChar ch = text.at(i); const int blockEnd = i; - if (ch == QLatin1Char('\r') - && (i + 1) < text.length() - && text.at(i + 1) == QLatin1Char('\n')) { + if (ch == u'\r' + && (i + 1) < text.size() + && text.at(i + 1) == u'\n') { ++i; ch = text.at(i); } - if (ch == QLatin1Char('\n') + if (ch == u'\n' || ch == QChar::ParagraphSeparator || ch == QTextBeginningOfFrame || ch == QTextEndOfFrame - || ch == QLatin1Char('\r')) { + || ch == u'\r') { if (!hasEditBlock) { hasEditBlock = true; @@ -1715,7 +1679,7 @@ static void getText(QString &text, QTextDocumentPrivate *priv, const QString &do const int offsetInFragment = qMax(0, pos - fragIt.position()); const int len = qMin(int(frag->size_array[0] - offsetInFragment), end - pos); - text += QString(docText.constData() + frag->stringPosition + offsetInFragment, len); + text += QStringView(docText.constData() + frag->stringPosition + offsetInFragment, len); pos += len; } } @@ -2291,6 +2255,28 @@ void QTextCursor::insertHtml(const QString &html) #endif // QT_NO_TEXTHTMLPARSER /*! + \since 6.4 + Inserts the \a markdown text at the current position(), + with the specified Markdown \a features. The default is GitHub dialect. +*/ + +#if QT_CONFIG(textmarkdownreader) + +void QTextCursor::insertMarkdown(const QString &markdown, QTextDocument::MarkdownFeatures features) +{ + if (!d || !d->priv) + return; + QTextDocumentFragment fragment = QTextDocumentFragment::fromMarkdown(markdown, features); + if (markdown.startsWith(QLatin1Char('\n'))) + insertBlock(fragment.d->doc->firstBlock().blockFormat()); + insertFragment(fragment); + if (!atEnd() && markdown.endsWith(QLatin1Char('\n'))) + insertText(QLatin1String("\n")); +} + +#endif // textmarkdownreader + +/*! \overload \since 4.2 @@ -2314,7 +2300,7 @@ void QTextCursor::insertImage(const QTextImageFormat &format, QTextFrameFormat:: d->priv->beginEditBlock(); d->remove(); const int idx = d->priv->formatCollection()->indexForFormat(fmt); - d->priv->insert(d->position, QString(QChar(QChar::ObjectReplacementCharacter)), idx); + d->priv->insert(d->position, QChar(QChar::ObjectReplacementCharacter), idx); d->priv->endEditBlock(); } |