diff --git a/src/schema/kateschema.cpp b/src/schema/kateschema.cpp --- a/src/schema/kateschema.cpp +++ b/src/schema/kateschema.cpp @@ -137,6 +137,9 @@ KTextEditor::ViewPrivate *view = m_view; if (view) { + // it allows the KateHighlighting class to know the chosen scheme + KateRendererConfig::global()->setSchema(mode); + view->renderer()->config()->setSchema(mode); } } diff --git a/src/syntax/katehighlight.cpp b/src/syntax/katehighlight.cpp --- a/src/syntax/katehighlight.cpp +++ b/src/syntax/katehighlight.cpp @@ -68,6 +68,22 @@ return static_cast(textStyle); } +/** + * convert the theme/schema name from KTextEditor => KSyntaxHighlighting. + * NOTE: some themes of KTextEditor don't exist in KSyntaxHighlighting + */ +inline QString convertThemeName(const QString &themeName) +{ + if (themeName == QLatin1String("Normal")) { + return QLatin1String("Default"); + } else if (themeName == QLatin1String("Solarized (light)")) { + return QLatin1String("Solarized Light"); + } else if (themeName == QLatin1String("Solarized (dark)")) { + return QLatin1String("Solarized Dark"); + } + return themeName; +} + } //END @@ -507,45 +523,61 @@ QVector KateHighlighting::attributesForDefinition() { - /** + /** + * get the KSyntaxHighlighting theme from the chosen schema + */ + KSyntaxHighlighting::Theme currentTheme = KateHlManager::self()->repository().theme(convertThemeName(KateRendererConfig::global()->schema())); + + /** * create list of all known things */ QVector array; for (const auto &format : m_formats) { /** - * FIXME: atm we just set some theme here for later color generation + * atm we just set the current chosen theme here for later color generation. + * NOTE: if the theme isn't valid for KSyntaxHighlighting, the default light theme will be used. + * For example, the "KDE" and "Vim (dark)" themes don't exist in KSyntaxHighlighting. */ - setTheme(KateHlManager::self()->repository().defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); + if (currentTheme.isValid()) { + setTheme(currentTheme); + } else { + setTheme(KateHlManager::self()->repository().defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); + } /** * create a KTextEditor attribute matching the given format */ KTextEditor::Attribute::Ptr newAttribute(new KTextEditor::Attribute(nameForAttrib(array.size()), textStyleToDefaultStyle(format.textStyle()))); - if (format.hasTextColor(theme())) { - newAttribute->setForeground(format.textColor(theme())); - newAttribute->setSelectedForeground(format.selectedTextColor(theme())); - } + /** + * don't apply attribute styles for themes that don't exist in KSyntaxHighlighting, but exist in KTextEditor + */ + if (currentTheme.isValid()) { + if (format.hasTextColor(theme())) { + newAttribute->setForeground(format.textColor(theme())); + newAttribute->setSelectedForeground(format.selectedTextColor(theme())); + } - if (format.hasBackgroundColor(theme())) { - newAttribute->setBackground(format.backgroundColor(theme())); - newAttribute->setSelectedBackground(format.selectedBackgroundColor(theme())); - } + if (format.hasBackgroundColor(theme())) { + newAttribute->setBackground(format.backgroundColor(theme())); + newAttribute->setSelectedBackground(format.selectedBackgroundColor(theme())); + } - if (format.isBold(theme())) { - newAttribute->setFontBold(true); - } + if (format.isBold(theme())) { + newAttribute->setFontBold(true); + } - if (format.isItalic(theme())) { - newAttribute->setFontItalic(true); - } + if (format.isItalic(theme())) { + newAttribute->setFontItalic(true); + } - if (format.isUnderline(theme())) { - newAttribute->setFontUnderline(true); - } + if (format.isUnderline(theme())) { + newAttribute->setFontUnderline(true); + } - if (format.isStrikeThrough(theme())) { - newAttribute->setFontStrikeOut(true); + if (format.isStrikeThrough(theme())) { + newAttribute->setFontStrikeOut(true); + } } newAttribute->setSkipSpellChecking(format.spellCheck());