Skip to content

Commit

Permalink
fix: does not support highlight do not reload.
Browse files Browse the repository at this point in the history
Change-Id: I78e6a21e6b22acbda07021ce89f4907268e3d0b4
  • Loading branch information
rekols committed Sep 11, 2018
1 parent 55b9611 commit e5bf394
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
49 changes: 27 additions & 22 deletions editor/src/texteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1922,40 +1922,40 @@ void TextEditor::setTheme(const KSyntaxHighlighting::Theme &theme, const QString
{
QVariantMap jsonMap = Utils::getThemeMapFromPath(path);
QVariantMap textStylesMap = jsonMap["text-styles"].toMap();
const QString &themeBackgroundColor = jsonMap["editor-colors"].toMap()["background-color"].toString();
const QString &themeCurrentLineColor = jsonMap["editor-colors"].toMap()["current-line"].toString();
const QString textColor = textStylesMap["Normal"].toMap()["text-color"].toString();
const QString selectColor = textStylesMap["RegionMarker"].toMap()["text-color"].toString();
const QString selectBgColor = textStylesMap["RegionMarker"].toMap()["background-color"].toString();

m_backgroundColor = QColor(jsonMap["editor-colors"].toMap()["background-color"].toString());
m_currentLineColor = QColor(themeCurrentLineColor);
m_currentLineNumberColor = QColor(jsonMap["editor-colors"].toMap()["current-line-number"].toString());
m_lineNumbersColor = QColor(jsonMap["editor-colors"].toMap()["line-numbers"].toString());
m_regionMarkerColor = QColor(theme.textColor(KSyntaxHighlighting::Theme::RegionMarker));
m_searchHighlightColor = QColor(jsonMap["editor-colors"].toMap()["search-highlight"].toString());
m_selectBgColor = QColor(textStylesMap["RegionMarker"].toMap()["background-color"].toString());
m_selectColor = QColor(textStylesMap["RegionMarker"].toMap()["text-color"].toString());
m_selectionColor = QColor(jsonMap["editor-colors"].toMap()["selection"].toString());

const QString &styleSheet = QString("QPlainTextEdit {"
"background-color: %1;"
"color: %2;"
"selection-color: %3;"
"selection-background-color: %4;"
"}").arg(themeBackgroundColor, textColor, selectColor, selectBgColor);

"}").arg(m_backgroundColor.name(), textColor,
m_selectColor.name(), m_selectBgColor.name());
setStyleSheet(styleSheet);

m_currentLineColor = QColor(themeCurrentLineColor);
m_backgroundColor = QColor(themeBackgroundColor);

m_lineNumbersColor = QColor(jsonMap["editor-colors"].toMap()["line-numbers"].toString());
m_currentLineNumberColor = QColor(jsonMap["editor-colors"].toMap()["current-line-number"].toString());
m_searchHighlightColor = QColor(jsonMap["editor-colors"].toMap()["search-highlight"].toString());
m_selectionColor = QColor(jsonMap["editor-colors"].toMap()["selection"].toString());
m_regionMarkerColor = QColor(theme.textColor(KSyntaxHighlighting::Theme::RegionMarker));

m_selectColor = selectColor;
m_selectBgColor = selectBgColor;

if (QColor(m_backgroundColor).lightness() < 128) {
if (m_backgroundColor.lightness() < 128) {
m_highlighter->setTheme(m_repository.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme));
} else {
m_highlighter->setTheme(m_repository.defaultTheme(KSyntaxHighlighting::Repository::LightTheme));
}

m_highlighter->rehighlight();
// does not support highlight do not reload
// when switching theme will be jammed or large files.
if (m_highlighted) {
m_highlighter->rehighlight();
}

lineNumberArea->update();

highlightCurrentLine();
Expand All @@ -1965,18 +1965,19 @@ void TextEditor::loadHighlighter()
{
const auto def = m_repository.definitionForFileName(QFileInfo(filepath).fileName());

if (def.filePath() != "") {
QString syntaxFile = QFileInfo(QString(":/syntax/%1").arg(QFileInfo(def.filePath()).fileName())).absoluteFilePath();
if (!def.filePath().isEmpty()) {
const QString &syntaxFile = QFileInfo(QString(":/syntax/%1").arg(QFileInfo(def.filePath()).fileName())).absoluteFilePath();

QFile file(syntaxFile);
if (!file.open(QFile::ReadOnly)) {
qDebug() << "Can't open file" << syntaxFile;
}
QXmlStreamReader reader(&file);

QXmlStreamReader reader(&file);
QString singleLineComment;
QString multiLineCommentStart;
QString multiLineCommentEnd;

while (!reader.atEnd()) {
const auto token = reader.readNext();
if (token != QXmlStreamReader::StartElement) {
Expand All @@ -2002,6 +2003,10 @@ void TextEditor::loadHighlighter()
m_highlighter->setDefinition(def);

file.close();

m_highlighted = true;
} else {
m_highlighted = false;
}
}

Expand Down
1 change: 1 addition & 0 deletions editor/src/texteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public slots:

QPoint m_mouseClickPos;

bool m_highlighted = false;
bool m_scrollbarLock = false;
int m_scrollbarMargin = 0;
};
Expand Down

0 comments on commit e5bf394

Please sign in to comment.