KTextEditor
katetextfolding.cpp
16TextFolding::FoldingRange::FoldingRange(TextBuffer &buffer, KTextEditor::Range range, FoldingRangeFlags _flags)
172 FoldingRange::Vector &parentVector = range->parent ? range->parent->nestedRanges : m_foldingRanges;
224 std::upper_bound(m_foldedFoldingRanges.begin(), m_foldedFoldingRanges.end(), line, compareRangeByStartWithLine);
375void TextFolding::foldingRangesStartingOnLine(QList<QPair<qint64, FoldingRangeFlags>> &results, const TextFolding::FoldingRange::Vector &ranges, int line) const
383 FoldingRange::Vector::const_iterator lowerBound = std::lower_bound(ranges.begin(), ranges.end(), line, compareRangeByLineWithStart);
386 FoldingRange::Vector::const_iterator upperBound = std::upper_bound(ranges.begin(), ranges.end(), line, compareRangeByStartWithLine);
388 // we may need to go one to the left, if not already at the begin, as we might overlap with the one in front of us!
405QList<QPair<qint64, TextFolding::FoldingRangeFlags>> TextFolding::foldingRangesForParentRange(qint64 parentRangeId) const
440void TextFolding::editEnd(int startLine, int endLine, std::function<bool(int)> isLineFoldingStart)
443 auto foldIt = std::upper_bound(m_foldedFoldingRanges.begin(), m_foldedFoldingRanges.end(), startLine, compareRangeByStartWithLine);
483 dump += QStringLiteral("[%1:%2 %3%4 ").arg(range->start->line()).arg(range->start->column()).arg(persistent, folded);
498bool TextFolding::insertNewFoldingRange(FoldingRange *parent, FoldingRange::Vector &existingRanges, FoldingRange *newRange)
501 // that means, we can search for lower bound of start of range and upper bound of end of range to find all "overlapping" ranges.
504 FoldingRange::Vector::iterator lowerBound = std::lower_bound(existingRanges.begin(), existingRanges.end(), newRange, compareRangeByStart);
507 FoldingRange::Vector::iterator upperBound = std::upper_bound(existingRanges.begin(), existingRanges.end(), newRange, compareRangeByEnd);
509 // we may need to go one to the left, if not already at the begin, as we might overlap with the one in front of us!
510 if ((lowerBound != existingRanges.begin()) && ((*(lowerBound - 1))->end->toCursor() > newRange->start->toCursor())) {
518 if ((lowerBound == existingRanges.end()) || (newRange->start->toCursor() >= (*lowerBound)->end->toCursor())
530 if ((newRange->start->toCursor() >= (*lowerBound)->start->toCursor()) && (newRange->end->toCursor() <= (*lowerBound)->end->toCursor())) {
534 // else: we might contain at least this fold, or many more, if this if block is not taken at all
555 if (!((newRange->start->toCursor() <= (*it)->start->toCursor()) && (newRange->end->toCursor() >= (*it)->end->toCursor()))) {
572 // remove the contained ones here, insert new range with new nested ranges we already constructed
627 // we now want to add this range to the m_foldedFoldingRanges vector, just removing any ranges that is included in it!
633 if ((newRange->start->toCursor() <= range->start->toCursor()) && (newRange->end->toCursor() >= range->end->toCursor())) {
683 // we now want to remove this range from the m_foldedFoldingRanges vector and include our nested folded ranges!
707void TextFolding::appendFoldedRanges(TextFolding::FoldingRange::Vector &newFoldedFoldingRanges, const TextFolding::FoldingRange::Vector &ranges) const
734void TextFolding::exportFoldingRanges(const TextFolding::FoldingRange::Vector &ranges, QJsonArray &folds)
756 const auto checksum = QByteArray::fromHex(folds.object().value(QStringLiteral("checksum")).toString().toLocal8Bit());
768 const KTextEditor::Cursor start(rangeMap[QStringLiteral("startLine")].toInt(), rangeMap[QStringLiteral("startColumn")].toInt());
769 const KTextEditor::Cursor end(rangeMap[QStringLiteral("endLine")].toInt(), rangeMap[QStringLiteral("endColumn")].toInt());
const Cursor toCursor() const
Convert this clever cursor into a dumb one.
Definition movingcursor.h:266
bool isValid() const
Returns whether the current position of this cursor is a valid position, i.e.
Definition movingcursor.h:159
An object representing a section of text, from one Cursor to another.
Definition include/ktexteditor/range.h:49
constexpr bool isEmpty() const noexcept
Returns true if this range contains no characters, ie.
Definition include/ktexteditor/range.h:301
static constexpr Range invalid() noexcept
Returns an invalid range.
Definition include/ktexteditor/range.h:121
KTextEditor::DocumentPrivate * document() const
Gets the document to which this buffer is bound.
Definition katetextbuffer.h:483
const QByteArray & digest() const
Checksum of the document on disk, set either through file loading in openFile() or in KTextEditor::Do...
Definition katetextbuffer.cpp:775
QList< QPair< qint64, FoldingRangeFlags > > foldingRangesForParentRange(qint64 parentRangeId=-1) const
Query child folding ranges for given range id.
Definition katetextfolding.cpp:405
bool unfoldRange(qint64 id, bool remove=false)
Unfold the given range.
Definition katetextfolding.cpp:148
QJsonDocument exportFoldingRanges() const
Return the current known folding ranges a QJsonDocument to store in configs.
Definition katetextfolding.cpp:722
bool isLineVisible(int line, qint64 *foldedRangeId=nullptr) const
Query if a given line is visible.
Definition katetextfolding.cpp:215
QString debugDump() const
Dump folding state as string, for unit testing and debugging.
Definition katetextfolding.cpp:428
void foldingRangesChanged()
If the folding state of existing ranges changes or ranges are added/removed, this signal is emitted.
void importFoldingRanges(const QJsonDocument &folds)
Import the folding ranges given as a QJsonDocument like read from configs.
Definition katetextfolding.cpp:752
void debugPrint(const QString &title) const
Print state to stdout for testing.
Definition katetextfolding.cpp:434
QList< QPair< qint64, FoldingRangeFlags > > foldingRangesStartingOnLine(int line) const
Queries which folding ranges start at the given line and returns the id + flags for all of them.
Definition katetextfolding.cpp:363
qint64 newFoldingRange(KTextEditor::Range range, FoldingRangeFlags flags=FoldingRangeFlags())
Create a new folding range.
Definition katetextfolding.cpp:76
int lineToVisibleLine(int line) const
Convert a text buffer line to a visible line number.
Definition katetextfolding.cpp:281
KTextEditor::Range foldingRange(qint64 id) const
Returns the folding range associated with id.
Definition katetextfolding.cpp:119
int visibleLineToLine(int visibleLine) const
Convert a visible line number to a line number in the text buffer.
Definition katetextfolding.cpp:322
void ensureLineIsVisible(int line)
Ensure that a given line will be visible.
Definition katetextfolding.cpp:241
Q_SCRIPTABLE Q_NOREPLY void start()
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Definition katetextblock.h:18
QByteArray fromHex(const QByteArray &hexEncoded)
QByteArray toHex(char separator) const const
void clear()
iterator insert(const Key &key, const T &value)
bool isEmpty() const const
bool remove(const Key &key)
T value(const Key &key) const const
void append(const QJsonValue &value)
QJsonObject object() const const
void setObject(const QJsonObject &object)
iterator end()
iterator insert(QLatin1StringView key, const QJsonValue &value)
QJsonValue value(QLatin1StringView key) const const
QJsonArray toArray() const const
void append(QList< T > &&value)
iterator begin()
void clear()
iterator end()
iterator erase(const_iterator begin, const_iterator end)
bool isEmpty() const const
void push_back(parameter_type value)
bool removeOne(const AT &t)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QString arg(Args &&... args) const const
QString fromLocal8Bit(QByteArrayView str)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:07:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:07:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.