[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktexteditor/syntax-highlighting] src/syntax: create initial attributes, still without real attribut
From: Christoph Cullmann <null () kde ! org>
Date: 2018-07-31 19:11:42
Message-ID: E1fka3a-0008Iz-2n () code ! kde ! org
[Download RAW message or body]
Git commit a3f4d37a8dc66b2d2a502fbd5e5e11893aa1fc74 by Christoph Cullmann.
Committed on 31/07/2018 at 19:11.
Pushed by cullmann into branch 'syntax-highlighting'.
create initial attributes, still without real attribute values, just a list of \
something
M +34 -44 src/syntax/katehighlight.cpp
M +16 -0 src/syntax/katehighlight.h
https://commits.kde.org/ktexteditor/a3f4d37a8dc66b2d2a502fbd5e5e11893aa1fc74
diff --git a/src/syntax/katehighlight.cpp b/src/syntax/katehighlight.cpp
index 85bc3dce..62ee3e87 100644
--- a/src/syntax/katehighlight.cpp
+++ b/src/syntax/katehighlight.cpp
@@ -99,6 +99,19 @@ KateHighlighting::KateHighlighting(const \
KSyntaxHighlighting::Definition &def)
* tell the AbstractHighlighter the definition it shall use
*/
setDefinition(def);
+
+ /**
+ * create the format => attributes mapping
+ */
+ if (def.isValid()) {
+ for (const auto & def : definition().includedDefinitions()) {
+ for (const auto & format : def.formats()) {
+ if (m_formatsIdToIndex.insert(std::make_pair(format.id(), \
m_formats.size())).second) { + m_formats.push_back(format);
+ }
+ }
+ }
+ }
}
KateHighlighting::~KateHighlighting()
@@ -2180,33 +2193,8 @@ int KateHighlighting::addToContextList(const QString &ident, \
int ctx0)
void KateHighlighting::clearAttributeArrays()
{
- QMutableHashIterator< QString, QList<KTextEditor::Attribute::Ptr> > it = \
m_attributeArrays;
- while (it.hasNext()) {
- it.next();
-
- // k, schema correct, let create the data
- KateAttributeList defaultStyleList;
-
- KateHlManager::self()->getDefaults(it.key(), defaultStyleList);
-
- QList<KTextEditor::Attribute::Ptr> itemDataList;
- getKateExtendedAttributeList(it.key(), itemDataList);
-
- uint nAttribs = itemDataList.count();
- QList<KTextEditor::Attribute::Ptr> &array = it.value();
- array.clear();
-
- for (uint z = 0; z < nAttribs; z++) {
- KTextEditor::Attribute::Ptr itemData = itemDataList.at(z);
- KTextEditor::Attribute::Ptr newAttribute(new \
KTextEditor::Attribute(*defaultStyleList.at(itemData->defaultStyle())));
-
- if (itemData && itemData->hasAnyProperty()) {
- *newAttribute += *itemData;
- }
-
- array.append(newAttribute);
- }
- }
+ // just clear the hashed attributes, we create them lazy again
+ m_attributeArrays.clear();
}
QList<KTextEditor::Attribute::Ptr> KateHighlighting::attributes(const QString \
&schema) @@ -2216,29 +2204,31 @@ QList<KTextEditor::Attribute::Ptr> \
KateHighlighting::attributes(const QString &s return m_attributeArrays[schema];
}
- // k, schema correct, let create the data
+ /**
+ * create list of all known things
+ */
QList<KTextEditor::Attribute::Ptr> array;
- KateAttributeList defaultStyleList;
-
- KateHlManager::self()->getDefaults(schema, defaultStyleList);
-
- QList<KTextEditor::Attribute::Ptr> itemDataList;
- getKateExtendedAttributeList(schema, itemDataList);
+ if (m_formats.empty()) {
+ KTextEditor::Attribute::Ptr newAttribute(new \
KTextEditor::Attribute(QLatin1String("Normal"), KTextEditor::dsNormal)); + \
array.append(newAttribute); + } else {
+ for (const auto &format : m_formats) {
+ /**
+ * convert from KSyntaxHighlighting => KTextEditor type
+ * special handle non-1:1 things
+ */
+ KTextEditor::DefaultStyle defaultStyle = \
static_cast<KTextEditor::DefaultStyle>(format.textStyle()); + if \
(format.textStyle() == KSyntaxHighlighting::Theme::Error) + \
defaultStyle = KTextEditor::dsError; + else if (format.textStyle() == \
KSyntaxHighlighting::Theme::Others) + defaultStyle = \
KTextEditor::dsOthers;
- uint nAttribs = itemDataList.count();
- for (uint z = 0; z < nAttribs; z++) {
- KTextEditor::Attribute::Ptr itemData = itemDataList.at(z);
- KTextEditor::Attribute::Ptr newAttribute(new \
KTextEditor::Attribute(*defaultStyleList.at(itemData->defaultStyle()))); + \
KTextEditor::Attribute::Ptr newAttribute(new KTextEditor::Attribute(format.name(), \
defaultStyle));
- if (itemData && itemData->hasAnyProperty()) {
- *newAttribute += *itemData;
+ array.append(newAttribute);
}
-
- array.append(newAttribute);
}
-
m_attributeArrays.insert(schema, array);
-
return array;
}
diff --git a/src/syntax/katehighlight.h b/src/syntax/katehighlight.h
index bb89c099..085761b1 100644
--- a/src/syntax/katehighlight.h
+++ b/src/syntax/katehighlight.h
@@ -23,7 +23,9 @@
#define __KATE_HIGHLIGHT_H__
#include <KSyntaxHighlighting/AbstractHighlighter>
+#include <KSyntaxHighlighting/Definition>
#include <KSyntaxHighlighting/FoldingRegion>
+#include <KSyntaxHighlighting/Format>
#include "katetextline.h"
#include "kateextendedattribute.h"
@@ -43,6 +45,8 @@
#include <QDate>
#include <QLinkedList>
+#include <unordered_map>
+
class KConfig;
class KateHlContext;
@@ -491,6 +495,7 @@ private:
*/
QMap<int, QString> m_hlIndex;
QMap<int, QString> m_ctxIndex;
+
public:
inline bool foldingIndentationSensitive()
{
@@ -500,6 +505,17 @@ public:
{
return folding;
}
+
+ /**
+ * all formats for the highlighting definition of this highlighting
+ * includes included formats
+ */
+ QVector<KSyntaxHighlighting::Format> m_formats;
+
+ /**
+ * mapping of format id => index into m_formats
+ */
+ std::unordered_map<quint16, int> m_formatsIdToIndex;
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic