- enhancement: when ctrl+mouse cursor hovered an identifier or header name, use underline to highlight it
This commit is contained in:
parent
837dc9bb27
commit
5182e200fb
3
NEWS.md
3
NEWS.md
|
@ -1,3 +1,6 @@
|
||||||
|
Red Panda C++ Version 1.1.0
|
||||||
|
- enhancement: when ctrl+mouse cursor hovered an identifier or header name, use underline to highlight it
|
||||||
|
|
||||||
Red Panda C++ Version 1.0.10
|
Red Panda C++ Version 1.0.10
|
||||||
- fix: modify watch doesn't work
|
- fix: modify watch doesn't work
|
||||||
- fix: make behavior consistent in adding compiler bindirs to Path (thanks for brokencuph@github)
|
- fix: make behavior consistent in adding compiler bindirs to Path (thanks for brokencuph@github)
|
||||||
|
|
|
@ -93,7 +93,8 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
||||||
mCurrentTipType(TipType::None),
|
mCurrentTipType(TipType::None),
|
||||||
mOldHighlightedWord(),
|
mOldHighlightedWord(),
|
||||||
mCurrentHighlightedWord(),
|
mCurrentHighlightedWord(),
|
||||||
mSaving(false)
|
mSaving(false),
|
||||||
|
mHoverModifiedLine(-1)
|
||||||
{
|
{
|
||||||
mCurrentLineModified = false;
|
mCurrentLineModified = false;
|
||||||
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
||||||
|
@ -924,44 +925,68 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|
||||||
if (token.isEmpty())
|
if (token.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mParser && mParser->enabled() && highlighter() && (attr == highlighter()->identifierAttribute())
|
if (mParser && mParser->enabled() && highlighter()) {
|
||||||
&& !mParser->isIncludeLine(document()->getString(line-1)) ) {
|
QString lineText = document()->getString(line-1);
|
||||||
|
if (mParser->isIncludeLine(lineText)) {
|
||||||
BufferCoord p{aChar,line};
|
if (cursor() == Qt::PointingHandCursor) {
|
||||||
// BufferCoord pBeginPos,pEndPos;
|
BufferCoord p;
|
||||||
// QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
if (pointToCharLine(mapFromGlobal(QCursor::pos()),p)) {
|
||||||
// qDebug()<<s;
|
if (line==p.Line){
|
||||||
// PStatement statement = mParser->findStatementOf(mFilename,
|
int pos1=std::max(lineText.indexOf("<"),lineText.indexOf("\""));
|
||||||
// s , p.Line);
|
int pos2=std::max(lineText.lastIndexOf(">"),lineText.lastIndexOf("\""));
|
||||||
QStringList expression = getExpressionAtPosition(p);
|
pos1++;
|
||||||
PStatement statement = parser()->findStatementOf(
|
pos2++;
|
||||||
filename(),
|
if (pos1>0 && pos2>0 && pos1<aChar && aChar < pos2) {
|
||||||
expression,
|
style.setFlag(SynFontStyle::fsUnderline);
|
||||||
p.Line);
|
}
|
||||||
StatementKind kind = getKindOfStatement(statement);
|
}
|
||||||
if (kind == StatementKind::skUnknown) {
|
}
|
||||||
BufferCoord pBeginPos,pEndPos;
|
|
||||||
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
|
||||||
if ((pEndPos.Line>=1)
|
|
||||||
&& (pEndPos.Char>=0)
|
|
||||||
&& (pEndPos.Char+1 < document()->getString(pEndPos.Line-1).length())
|
|
||||||
&& (document()->getString(pEndPos.Line-1)[pEndPos.Char+1] == '(')) {
|
|
||||||
kind = StatementKind::skFunction;
|
|
||||||
} else {
|
|
||||||
kind = StatementKind::skVariable;
|
|
||||||
}
|
}
|
||||||
}
|
} else if (attr == highlighter()->identifierAttribute()) {
|
||||||
PColorSchemeItem item = mStatementColors->value(kind,PColorSchemeItem());
|
BufferCoord p{aChar,line};
|
||||||
|
// BufferCoord pBeginPos,pEndPos;
|
||||||
|
// QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
||||||
|
// qDebug()<<s;
|
||||||
|
// PStatement statement = mParser->findStatementOf(mFilename,
|
||||||
|
// s , p.Line);
|
||||||
|
QStringList expression = getExpressionAtPosition(p);
|
||||||
|
PStatement statement = parser()->findStatementOf(
|
||||||
|
filename(),
|
||||||
|
expression,
|
||||||
|
p.Line);
|
||||||
|
StatementKind kind = getKindOfStatement(statement);
|
||||||
|
if (kind == StatementKind::skUnknown) {
|
||||||
|
BufferCoord pBeginPos,pEndPos;
|
||||||
|
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
||||||
|
if ((pEndPos.Line>=1)
|
||||||
|
&& (pEndPos.Char>=0)
|
||||||
|
&& (pEndPos.Char+1 < document()->getString(pEndPos.Line-1).length())
|
||||||
|
&& (document()->getString(pEndPos.Line-1)[pEndPos.Char+1] == '(')) {
|
||||||
|
kind = StatementKind::skFunction;
|
||||||
|
} else {
|
||||||
|
kind = StatementKind::skVariable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PColorSchemeItem item = mStatementColors->value(kind,PColorSchemeItem());
|
||||||
|
|
||||||
if (item) {
|
if (item) {
|
||||||
foreground = item->foreground();
|
foreground = item->foreground();
|
||||||
//background = item->background();
|
//background = item->background();
|
||||||
style.setFlag(SynFontStyle::fsBold,item->bold());
|
style.setFlag(SynFontStyle::fsBold,item->bold());
|
||||||
style.setFlag(SynFontStyle::fsItalic,item->italic());
|
style.setFlag(SynFontStyle::fsItalic,item->italic());
|
||||||
style.setFlag(SynFontStyle::fsUnderline,item->underlined());
|
style.setFlag(SynFontStyle::fsUnderline,item->underlined());
|
||||||
style.setFlag(SynFontStyle::fsStrikeOut,item->strikeout());
|
style.setFlag(SynFontStyle::fsStrikeOut,item->strikeout());
|
||||||
} else {
|
} else {
|
||||||
foreground = highlighter()->identifierAttribute()->foreground();
|
foreground = highlighter()->identifierAttribute()->foreground();
|
||||||
|
}
|
||||||
|
if (cursor() == Qt::PointingHandCursor) {
|
||||||
|
BufferCoord p;
|
||||||
|
if (pointToCharLine(mapFromGlobal(QCursor::pos()),p)) {
|
||||||
|
if (line==p.Line && (aChar<=p.Char && p.Char<aChar+token.length())) {
|
||||||
|
style.setFlag(SynFontStyle::fsUnderline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1012,6 +1037,11 @@ bool Editor::event(QEvent *event)
|
||||||
&& !pMainWindow->completionPopup()->isVisible()
|
&& !pMainWindow->completionPopup()->isVisible()
|
||||||
&& !pMainWindow->functionTip()->isVisible()
|
&& !pMainWindow->functionTip()->isVisible()
|
||||||
&& !pMainWindow->headerCompletionPopup()->isVisible()) {
|
&& !pMainWindow->headerCompletionPopup()->isVisible()) {
|
||||||
|
if(mHoverModifiedLine!=-1) {
|
||||||
|
invalidateLine(mHoverModifiedLine);
|
||||||
|
mHoverModifiedLine=-1;
|
||||||
|
}
|
||||||
|
|
||||||
QHoverEvent *helpEvent = static_cast<QHoverEvent *>(event);
|
QHoverEvent *helpEvent = static_cast<QHoverEvent *>(event);
|
||||||
BufferCoord p;
|
BufferCoord p;
|
||||||
TipType reason = getTipType(helpEvent->pos(),p);
|
TipType reason = getTipType(helpEvent->pos(),p);
|
||||||
|
@ -1067,11 +1097,17 @@ bool Editor::event(QEvent *event)
|
||||||
|
|
||||||
s = s.trimmed();
|
s = s.trimmed();
|
||||||
if ((s == mCurrentWord) && (mCurrentTipType == reason)) {
|
if ((s == mCurrentWord) && (mCurrentTipType == reason)) {
|
||||||
if (helpEvent->modifiers() == Qt::ControlModifier) {
|
if (qApp->queryKeyboardModifiers() == Qt::ControlModifier) {
|
||||||
|
if (!hasFocus())
|
||||||
|
activate();
|
||||||
setCursor(Qt::PointingHandCursor);
|
setCursor(Qt::PointingHandCursor);
|
||||||
} else {
|
} else {
|
||||||
updateMouseCursor();
|
updateMouseCursor();
|
||||||
}
|
}
|
||||||
|
if (pointToLine(helpEvent->pos(),line)) {
|
||||||
|
invalidateLine(line);
|
||||||
|
mHoverModifiedLine=line;
|
||||||
|
}
|
||||||
event->ignore();
|
event->ignore();
|
||||||
return true; // do NOT remove hint when subject stays the same
|
return true; // do NOT remove hint when subject stays the same
|
||||||
}
|
}
|
||||||
|
@ -1119,11 +1155,17 @@ bool Editor::event(QEvent *event)
|
||||||
if (!hint.isEmpty()) {
|
if (!hint.isEmpty()) {
|
||||||
// QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
|
// QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
|
||||||
// if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) {
|
// if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) {
|
||||||
if (helpEvent->modifiers() == Qt::ControlModifier) {
|
if (qApp->queryKeyboardModifiers() == Qt::ControlModifier) {
|
||||||
|
if (!hasFocus())
|
||||||
|
activate();
|
||||||
setCursor(Qt::PointingHandCursor);
|
setCursor(Qt::PointingHandCursor);
|
||||||
} else if (cursor() == Qt::PointingHandCursor) {
|
} else if (cursor() == Qt::PointingHandCursor) {
|
||||||
updateMouseCursor();
|
updateMouseCursor();
|
||||||
}
|
}
|
||||||
|
if (pointToLine(helpEvent->pos(),line)) {
|
||||||
|
invalidateLine(line);
|
||||||
|
mHoverModifiedLine=line;
|
||||||
|
}
|
||||||
if (pMainWindow->functionTip()->isVisible()) {
|
if (pMainWindow->functionTip()->isVisible()) {
|
||||||
pMainWindow->functionTip()->hide();
|
pMainWindow->functionTip()->hide();
|
||||||
}
|
}
|
||||||
|
@ -1161,7 +1203,7 @@ void Editor::mouseReleaseEvent(QMouseEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ctrl+clicked
|
// if ctrl+clicked
|
||||||
if ((event->modifiers() == Qt::ControlModifier)
|
if ((cursor() == Qt::PointingHandCursor) && (event->modifiers() == Qt::ControlModifier)
|
||||||
&& (event->button() == Qt::LeftButton)) {
|
&& (event->button() == Qt::LeftButton)) {
|
||||||
|
|
||||||
BufferCoord p;
|
BufferCoord p;
|
||||||
|
@ -3339,6 +3381,11 @@ Editor::TipType Editor::getTipType(QPoint point, BufferCoord& pos)
|
||||||
|
|
||||||
void Editor::cancelHint()
|
void Editor::cancelHint()
|
||||||
{
|
{
|
||||||
|
if(mHoverModifiedLine!=-1) {
|
||||||
|
invalidateLine(mHoverModifiedLine);
|
||||||
|
mHoverModifiedLine=-1;
|
||||||
|
}
|
||||||
|
|
||||||
//MainForm.Debugger.OnEvalReady := nil;
|
//MainForm.Debugger.OnEvalReady := nil;
|
||||||
|
|
||||||
// disable editor hint
|
// disable editor hint
|
||||||
|
|
|
@ -332,6 +332,7 @@ private:
|
||||||
BufferCoord mHighlightCharPos2;
|
BufferCoord mHighlightCharPos2;
|
||||||
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors;
|
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors;
|
||||||
QTimer mFunctionTipTimer;
|
QTimer mFunctionTipTimer;
|
||||||
|
int mHoverModifiedLine;
|
||||||
|
|
||||||
// QWidget interface
|
// QWidget interface
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in New Issue