- 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
|
||||
- fix: modify watch doesn't work
|
||||
- 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),
|
||||
mOldHighlightedWord(),
|
||||
mCurrentHighlightedWord(),
|
||||
mSaving(false)
|
||||
mSaving(false),
|
||||
mHoverModifiedLine(-1)
|
||||
{
|
||||
mCurrentLineModified = false;
|
||||
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
||||
|
@ -924,15 +925,30 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|
|||
if (token.isEmpty())
|
||||
return;
|
||||
|
||||
if (mParser && mParser->enabled() && highlighter() && (attr == highlighter()->identifierAttribute())
|
||||
&& !mParser->isIncludeLine(document()->getString(line-1)) ) {
|
||||
|
||||
if (mParser && mParser->enabled() && highlighter()) {
|
||||
QString lineText = document()->getString(line-1);
|
||||
if (mParser->isIncludeLine(lineText)) {
|
||||
if (cursor() == Qt::PointingHandCursor) {
|
||||
BufferCoord p;
|
||||
if (pointToCharLine(mapFromGlobal(QCursor::pos()),p)) {
|
||||
if (line==p.Line){
|
||||
int pos1=std::max(lineText.indexOf("<"),lineText.indexOf("\""));
|
||||
int pos2=std::max(lineText.lastIndexOf(">"),lineText.lastIndexOf("\""));
|
||||
pos1++;
|
||||
pos2++;
|
||||
if (pos1>0 && pos2>0 && pos1<aChar && aChar < pos2) {
|
||||
style.setFlag(SynFontStyle::fsUnderline);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (attr == highlighter()->identifierAttribute()) {
|
||||
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);
|
||||
// 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(),
|
||||
|
@ -963,6 +979,15 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|
|||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//selection
|
||||
|
@ -1012,6 +1037,11 @@ bool Editor::event(QEvent *event)
|
|||
&& !pMainWindow->completionPopup()->isVisible()
|
||||
&& !pMainWindow->functionTip()->isVisible()
|
||||
&& !pMainWindow->headerCompletionPopup()->isVisible()) {
|
||||
if(mHoverModifiedLine!=-1) {
|
||||
invalidateLine(mHoverModifiedLine);
|
||||
mHoverModifiedLine=-1;
|
||||
}
|
||||
|
||||
QHoverEvent *helpEvent = static_cast<QHoverEvent *>(event);
|
||||
BufferCoord p;
|
||||
TipType reason = getTipType(helpEvent->pos(),p);
|
||||
|
@ -1067,11 +1097,17 @@ bool Editor::event(QEvent *event)
|
|||
|
||||
s = s.trimmed();
|
||||
if ((s == mCurrentWord) && (mCurrentTipType == reason)) {
|
||||
if (helpEvent->modifiers() == Qt::ControlModifier) {
|
||||
if (qApp->queryKeyboardModifiers() == Qt::ControlModifier) {
|
||||
if (!hasFocus())
|
||||
activate();
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
} else {
|
||||
updateMouseCursor();
|
||||
}
|
||||
if (pointToLine(helpEvent->pos(),line)) {
|
||||
invalidateLine(line);
|
||||
mHoverModifiedLine=line;
|
||||
}
|
||||
event->ignore();
|
||||
return true; // do NOT remove hint when subject stays the same
|
||||
}
|
||||
|
@ -1119,11 +1155,17 @@ bool Editor::event(QEvent *event)
|
|||
if (!hint.isEmpty()) {
|
||||
// QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
|
||||
// if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) {
|
||||
if (helpEvent->modifiers() == Qt::ControlModifier) {
|
||||
if (qApp->queryKeyboardModifiers() == Qt::ControlModifier) {
|
||||
if (!hasFocus())
|
||||
activate();
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
} else if (cursor() == Qt::PointingHandCursor) {
|
||||
updateMouseCursor();
|
||||
}
|
||||
if (pointToLine(helpEvent->pos(),line)) {
|
||||
invalidateLine(line);
|
||||
mHoverModifiedLine=line;
|
||||
}
|
||||
if (pMainWindow->functionTip()->isVisible()) {
|
||||
pMainWindow->functionTip()->hide();
|
||||
}
|
||||
|
@ -1161,7 +1203,7 @@ void Editor::mouseReleaseEvent(QMouseEvent *event)
|
|||
}
|
||||
|
||||
// if ctrl+clicked
|
||||
if ((event->modifiers() == Qt::ControlModifier)
|
||||
if ((cursor() == Qt::PointingHandCursor) && (event->modifiers() == Qt::ControlModifier)
|
||||
&& (event->button() == Qt::LeftButton)) {
|
||||
|
||||
BufferCoord p;
|
||||
|
@ -3339,6 +3381,11 @@ Editor::TipType Editor::getTipType(QPoint point, BufferCoord& pos)
|
|||
|
||||
void Editor::cancelHint()
|
||||
{
|
||||
if(mHoverModifiedLine!=-1) {
|
||||
invalidateLine(mHoverModifiedLine);
|
||||
mHoverModifiedLine=-1;
|
||||
}
|
||||
|
||||
//MainForm.Debugger.OnEvalReady := nil;
|
||||
|
||||
// disable editor hint
|
||||
|
|
|
@ -332,6 +332,7 @@ private:
|
|||
BufferCoord mHighlightCharPos2;
|
||||
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mStatementColors;
|
||||
QTimer mFunctionTipTimer;
|
||||
int mHoverModifiedLine;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue