- 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,9 +925,24 @@ 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)) {
|
||||||
|
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 p{aChar,line};
|
||||||
// BufferCoord pBeginPos,pEndPos;
|
// BufferCoord pBeginPos,pEndPos;
|
||||||
// QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
// QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
||||||
|
@ -963,6 +979,15 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|
||||||
} 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//selection
|
//selection
|
||||||
|
@ -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