mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-18 14:42:27 +00:00
Make name highlighting more consistent and only for variable names
This commit is contained in:
parent
95f60d2bb3
commit
829560719e
@ -52,7 +52,6 @@ CSVWorld::ScriptEdit::ScriptEdit(
|
|||||||
mMonoFont(QFont("Monospace")),
|
mMonoFont(QFont("Monospace")),
|
||||||
mTabCharCount(4),
|
mTabCharCount(4),
|
||||||
mMarkOccurrences(true),
|
mMarkOccurrences(true),
|
||||||
mMarkOccurrencesRunning(false),
|
|
||||||
mDocument(document),
|
mDocument(document),
|
||||||
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive)
|
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive)
|
||||||
{
|
{
|
||||||
@ -90,7 +89,7 @@ CSVWorld::ScriptEdit::ScriptEdit(
|
|||||||
<<CSMWorld::UniversalId::Type_Script
|
<<CSMWorld::UniversalId::Type_Script
|
||||||
<<CSMWorld::UniversalId::Type_Region;
|
<<CSMWorld::UniversalId::Type_Region;
|
||||||
|
|
||||||
connect(this, SIGNAL(selectionChanged()), this, SLOT(markOccurrences()));
|
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(markOccurrences()));
|
||||||
|
|
||||||
mCommentAction = new QAction (tr ("Comment Selection"), this);
|
mCommentAction = new QAction (tr ("Comment Selection"), this);
|
||||||
connect(mCommentAction, SIGNAL (triggered()), this, SLOT (commentSelection()));
|
connect(mCommentAction, SIGNAL (triggered()), this, SLOT (commentSelection()));
|
||||||
@ -309,24 +308,20 @@ void CSVWorld::ScriptEdit::updateLineNumberArea(const QRect &rect, int dy)
|
|||||||
|
|
||||||
void CSVWorld::ScriptEdit::markOccurrences()
|
void CSVWorld::ScriptEdit::markOccurrences()
|
||||||
{
|
{
|
||||||
// prevent infinite recursion with cursor.select(),
|
|
||||||
// which ends up calling this function again
|
|
||||||
// could be fixed with blockSignals, but mDocument is const
|
|
||||||
if (mMarkOccurrencesRunning)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (mMarkOccurrences)
|
if (mMarkOccurrences)
|
||||||
{
|
{
|
||||||
mMarkOccurrencesRunning = true;
|
|
||||||
|
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
cursor.select(QTextCursor::WordUnderCursor);
|
|
||||||
QString word = cursor.selectedText();
|
|
||||||
|
|
||||||
|
// prevent infinite recursion with cursor.select(),
|
||||||
|
// which ends up calling this function again
|
||||||
|
// could be fixed with blockSignals, but mDocument is const
|
||||||
|
disconnect(this, SIGNAL(cursorPositionChanged()), this, 0);
|
||||||
|
cursor.select(QTextCursor::WordUnderCursor);
|
||||||
|
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(markOccurrences()));
|
||||||
|
|
||||||
|
QString word = cursor.selectedText();
|
||||||
mHighlighter->setMarkedWord(word.toStdString());
|
mHighlighter->setMarkedWord(word.toStdString());
|
||||||
mHighlighter->rehighlight();
|
mHighlighter->rehighlight();
|
||||||
|
|
||||||
mMarkOccurrencesRunning = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ namespace CSVWorld
|
|||||||
QFont mMonoFont;
|
QFont mMonoFont;
|
||||||
int mTabCharCount;
|
int mTabCharCount;
|
||||||
bool mMarkOccurrences;
|
bool mMarkOccurrences;
|
||||||
bool mMarkOccurrencesRunning;
|
|
||||||
QAction *mCommentAction;
|
QAction *mCommentAction;
|
||||||
QAction *mUncommentAction;
|
QAction *mUncommentAction;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ void CSVWorld::ScriptHighlighter::highlight (const Compiler::TokenLoc& loc, Type
|
|||||||
index -= length;
|
index -= length;
|
||||||
|
|
||||||
QTextCharFormat scheme = mScheme[type];
|
QTextCharFormat scheme = mScheme[type];
|
||||||
if (mMarkOccurrences && loc.mLiteral == mMarkedWord)
|
if (mMarkOccurrences && type == Type_Name && loc.mLiteral == mMarkedWord)
|
||||||
scheme.merge(mScheme[Type_Highlight]);
|
scheme.merge(mScheme[Type_Highlight]);
|
||||||
|
|
||||||
setFormat (index, length, scheme);
|
setFormat (index, length, scheme);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user