forked from qt-creator/qt-creator
Editor: fix folding for Markdown
Fixes: QTCREATORBUG-25882 Change-Id: I46048a191f4dd9bb2f7c3029f8555066bb8451ab Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -26,29 +26,32 @@
|
|||||||
#include "highlighter.h"
|
#include "highlighter.h"
|
||||||
|
|
||||||
#include "highlightersettings.h"
|
#include "highlightersettings.h"
|
||||||
#include "textdocumentlayout.h"
|
|
||||||
#include "tabsettings.h"
|
#include "tabsettings.h"
|
||||||
#include "texteditorsettings.h"
|
#include "textdocumentlayout.h"
|
||||||
#include "texteditor.h"
|
#include "texteditor.h"
|
||||||
|
#include "texteditorsettings.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/documentmodel.h>
|
#include <coreplugin/editormanager/documentmodel.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <utils/mimetypes/mimedatabase.h>
|
#include <utils/mimetypes/mimedatabase.h>
|
||||||
#include <utils/stylehelper.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/stylehelper.h>
|
||||||
|
|
||||||
#include <DefinitionDownloader>
|
#include <DefinitionDownloader>
|
||||||
#include <Format>
|
|
||||||
#include <FoldingRegion>
|
#include <FoldingRegion>
|
||||||
|
#include <Format>
|
||||||
#include <Repository>
|
#include <Repository>
|
||||||
#include <SyntaxHighlighter>
|
#include <SyntaxHighlighter>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QLoggingCategory>
|
||||||
#include <QMetaEnum>
|
#include <QMetaEnum>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
|
static Q_LOGGING_CATEGORY(highlighterLog, "qtc.editor.highlighter", QtWarningMsg)
|
||||||
|
|
||||||
static const char kDefinitionForMimeType[] = "definitionForMimeType";
|
static const char kDefinitionForMimeType[] = "definitionForMimeType";
|
||||||
static const char kDefinitionForExtension[] = "definitionForExtension";
|
static const char kDefinitionForExtension[] = "definitionForExtension";
|
||||||
static const char kDefinitionForFilePath[] = "definitionForFilePath";
|
static const char kDefinitionForFilePath[] = "definitionForFilePath";
|
||||||
@@ -370,14 +373,22 @@ void Highlighter::applyFolding(int offset,
|
|||||||
const bool fromStart = TabSettings::firstNonSpace(text) == offset;
|
const bool fromStart = TabSettings::firstNonSpace(text) == offset;
|
||||||
const bool toEnd = (offset + length) == (text.length() - TabSettings::trailingWhitespaces(text));
|
const bool toEnd = (offset + length) == (text.length() - TabSettings::trailingWhitespaces(text));
|
||||||
if (region.type() == KSyntaxHighlighting::FoldingRegion::Begin) {
|
if (region.type() == KSyntaxHighlighting::FoldingRegion::Begin) {
|
||||||
TextDocumentLayout::changeBraceDepth(block, 1);
|
const int newBraceDepth = TextDocumentLayout::braceDepth(block) + 1;
|
||||||
// if there is only a folding begin in the line move the current block into the fold
|
TextDocumentLayout::setBraceDepth(block, newBraceDepth);
|
||||||
if (fromStart && toEnd) {
|
qCDebug(highlighterLog) << "Found folding start from '" << offset << "' to '" << length
|
||||||
|
<< "' resulting in the bracedepth '" << newBraceDepth << "' in :";
|
||||||
|
qCDebug(highlighterLog) << text;
|
||||||
|
// if there is only a folding begin marker in the line move the current block into the fold
|
||||||
|
if (fromStart && toEnd && length <= 1) {
|
||||||
data->setFoldingIndent(TextDocumentLayout::braceDepth(block));
|
data->setFoldingIndent(TextDocumentLayout::braceDepth(block));
|
||||||
data->setFoldingStartIncluded(true);
|
data->setFoldingStartIncluded(true);
|
||||||
}
|
}
|
||||||
} else if (region.type() == KSyntaxHighlighting::FoldingRegion::End) {
|
} else if (region.type() == KSyntaxHighlighting::FoldingRegion::End) {
|
||||||
TextDocumentLayout::changeBraceDepth(block, -1);
|
const int newBraceDepth = qMax(0, TextDocumentLayout::braceDepth(block) - 1);
|
||||||
|
qCDebug(highlighterLog) << "Found folding end from '" << offset << "' to '" << length
|
||||||
|
<< "' resulting in the bracedepth '" << newBraceDepth << "' in :";
|
||||||
|
qCDebug(highlighterLog) << text;
|
||||||
|
TextDocumentLayout::setBraceDepth(block, newBraceDepth);
|
||||||
// if the folding end is at the end of the line move the current block into the fold
|
// if the folding end is at the end of the line move the current block into the fold
|
||||||
if (toEnd)
|
if (toEnd)
|
||||||
data->setFoldingEndIncluded(true);
|
data->setFoldingEndIncluded(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user