fix : header file completion stop work when input '.'

This commit is contained in:
royqh1979@gmail.com 2021-09-27 00:52:25 +08:00
parent 23c6f7f702
commit 22acab0950
7 changed files with 70 additions and 39 deletions

View File

@ -137,8 +137,6 @@ Editor::Editor(QWidget *parent, const QString& filename,
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QWidget::customContextMenuRequested,
pMainWindow, &MainWindow::onEditorContextMenu);
mOldHintCursor = Qt::IBeamCursor;
}
Editor::~Editor() {
@ -776,10 +774,9 @@ bool Editor::event(QEvent *event)
s = s.trimmed();
if ((s == mCurrentWord) && (mCurrentTipType == reason)) {
if (helpEvent->modifiers() == Qt::ControlModifier) {
mOldHintCursor = cursor();
setCursor(Qt::PointingHandCursor);
} else if (cursor() == Qt::PointingHandCursor) {
setCursor(mOldHintCursor);
} else {
updateMouseCursor();
}
event->ignore();
return true; // do NOT remove hint when subject stays the same
@ -826,17 +823,14 @@ bool Editor::event(QEvent *event)
// QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
// if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) {
if (helpEvent->modifiers() == Qt::ControlModifier) {
mOldHintCursor = cursor();
setCursor(Qt::PointingHandCursor);
} else if (cursor() == Qt::PointingHandCursor) {
setCursor(mOldHintCursor);
updateMouseCursor();
}
QToolTip::showText(mapToGlobal(helpEvent->pos()),hint);
event->ignore();
} else {
if (cursor() == Qt::PointingHandCursor) {
setCursor(mOldHintCursor);
}
updateMouseCursor();
event->ignore();
}
return true;
@ -2058,7 +2052,7 @@ bool Editor::onCompletionKeyPressed(QKeyEvent *event)
bool Editor::onHeaderCompletionKeyPressed(QKeyEvent *event)
{
bool processed = false;
if (!mCompletionPopup->isEnabled())
if (!mHeaderCompletionPopup->isEnabled())
return false;
QString phrase;
BufferCoord pBeginPos,pEndPos;
@ -2081,6 +2075,8 @@ bool Editor::onHeaderCompletionKeyPressed(QKeyEvent *event)
headerCompletionInsert();
mHeaderCompletionPopup->hide();
return true;
case Qt::Key_Shift:
return false;
default:
if (event->text().isEmpty()) {
//stop completion
@ -2090,7 +2086,9 @@ bool Editor::onHeaderCompletionKeyPressed(QKeyEvent *event)
}
}
QChar ch = event->text().front();
if (isIdentChar(ch)) {
if (isIdentChar(ch) || ch == '.'
|| ch =='_' || ch=='+') {
setSelText(ch);
phrase = getWordAtPosition(this,caretXY(),
pBeginPos,pEndPos,
@ -2145,8 +2143,7 @@ void Editor::cancelHint()
QToolTip::hideText();
mCurrentWord = "";
mCurrentTipType = TipType::None;
if (cursor() == Qt::PointingHandCursor)
setCursor(mOldHintCursor);
updateMouseCursor();
}
QString Editor::getFileHint(const QString &s)
@ -2569,11 +2566,13 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW
// Copy backward until begin of path
if (purpose == Editor::WordPurpose::wpHeaderCompletion) {
while ((wordBegin >= 0) && (wordBegin < len)) {
if (editor->isIdentChar(s[wordBegin]))
if (editor->isIdentChar(s[wordBegin])) {
wordBegin--;
else if (s[wordBegin] == '/'
|| s[wordBegin] == '\\'
|| s[wordBegin] == '.') {
} else if (s[wordBegin] == '.'
|| s[wordBegin] == '+') {
wordBegin--;
} else if (s[wordBegin] == '/'
|| s[wordBegin] == '\\') {
wordBegin--;
break;
} else

View File

@ -229,7 +229,6 @@ private:
TipType mCurrentTipType;
QString mOldSelectionWord;
QString mSelectionWord;
QCursor mOldHintCursor;
bool mSaving;

View File

@ -111,7 +111,7 @@ struct Statement {
QString type; // type "int"
QString command; // identifier/name of statement "foo"
QString args; // args "(int a,float b)"
QStringList argList;
QStringList argList; //not used yet
QString value; // Used for macro defines/typedef, "100" in "#defin COUNT 100"
StatementKind kind; // kind of statement class/variable/function/etc
QList<std::weak_ptr<Statement>> inheritanceList; // list of statements this one inherits from, can be nil
@ -134,6 +134,7 @@ struct Statement {
QSet<QString> usingList; // using namespaces
int usageCount; //Usage Count, used by TCodeCompletion
int freqTop; // Usage Count Rank, used by TCodeCompletion
bool caseMatch; // if match with case, used by TCodeCompletion
QString noNameArgs;// Args without name
};

View File

@ -5285,6 +5285,17 @@ void SynEdit::setRainbowAttrs(const PSynHighlighterAttribute &attr0, const PSynH
mRainbowAttr3 = attr3;
}
void SynEdit::updateMouseCursor(){
QPoint p = mapFromGlobal(cursor().pos());
if (p.y() >= clientHeight() || p.x()>= clientWidth()) {
setCursor(Qt::ArrowCursor);
} else if (p.x() > mGutterWidth) {
setCursor(Qt::IBeamCursor);
} else {
setCursor(Qt::ArrowCursor);
}
}
void SynEdit::paintEvent(QPaintEvent *event)
{
if (mPainterLock>0)
@ -5388,10 +5399,7 @@ bool SynEdit::event(QEvent *event)
synFontChanged();
break;
case QEvent::MouseMove: {
QPoint p = mapFromGlobal(cursor().pos());
if (p.y() >= clientHeight() || p.x()>= clientWidth()) {
setCursor(Qt::ArrowCursor);
}
updateMouseCursor();
break;
}
}
@ -5545,11 +5553,7 @@ void SynEdit::mouseMoveEvent(QMouseEvent *event)
internalSetCaretXY(displayToBufferPos(P));
setBlockEnd(caretXY());
} else if (buttons == Qt::NoButton) {
if (X > mGutterWidth) {
setCursor(Qt::IBeamCursor);
} else {
setCursor(Qt::ArrowCursor);
}
updateMouseCursor();
}
}

View File

@ -266,6 +266,8 @@ public:
const PSynHighlighterAttribute &attr1,
const PSynHighlighterAttribute &attr2,
const PSynHighlighterAttribute &attr3);
void updateMouseCursor();
// setter && getters
int topLine() const;
void setTopLine(int value);

View File

@ -373,13 +373,24 @@ void ClassBrowserModel::filterChildren(ClassBrowserNode *node, const StatementMa
addChild(node,statement);
}
}
if (pSettings->ui().classBrowserSortAlpha()) {
if (pSettings->ui().classBrowserSortAlpha()
&& pSettings->ui().classBrowserSortType()) {
std::sort(node->children.begin(),node->children.end(),
[](ClassBrowserNode* node1,ClassBrowserNode* node2) {
if (node1->statement->kind < node2->statement->kind) {
return true;
} else if (node1->statement->kind == node2->statement->kind) {
return node1->statement->command < node2->statement->command;
} else {
return false;
}
});
} else if (pSettings->ui().classBrowserSortAlpha()) {
std::sort(node->children.begin(),node->children.end(),
[](ClassBrowserNode* node1,ClassBrowserNode* node2) {
return node1->statement->command < node2->statement->command;
});
}
if (pSettings->ui().classBrowserSortType()) {
} else if (pSettings->ui().classBrowserSortType()) {
std::sort(node->children.begin(),node->children.end(),
[](ClassBrowserNode* node1,ClassBrowserNode* node2) {
return node1->statement->kind < node2->statement->kind;

View File

@ -186,6 +186,15 @@ void CodeCompletionPopup::addStatement(PStatement statement, const QString &file
mFullCompletionStatementList.append(statement);
}
static bool nameComparator(PStatement statement1,PStatement statement2) {
if (statement1->caseMatch && !statement2->caseMatch) {
return true;
} else if (!statement1->caseMatch && statement2->caseMatch) {
return false;
} else
return statement1->command < statement2->command;
}
static bool defaultComparator(PStatement statement1,PStatement statement2) {
// Show user template first
if (statement1->kind == StatementKind::skUserCodeIn) {
@ -203,7 +212,7 @@ static bool defaultComparator(PStatement statement1,PStatement statement2) {
&& (statement2->kind == StatementKind::skKeyword)) {
return false;
} else
return statement1->command < statement2->command;
return nameComparator(statement1,statement2);
}
static bool sortByScopeComparator(PStatement statement1,PStatement statement2){
@ -235,9 +244,8 @@ static bool sortByScopeComparator(PStatement statement1,PStatement statement2){
} else if (statement1->scope == StatementScope::ssGlobal
&& statement2->scope != StatementScope::ssGlobal ) {
return false;
// otherwise, sort by name
} else
return statement1->command < statement2->command;
return nameComparator(statement1,statement2);
}
static bool sortWithUsageComparator(PStatement statement1,PStatement statement2) {
@ -262,7 +270,7 @@ static bool sortWithUsageComparator(PStatement statement1,PStatement statement2)
&& (statement2->kind != StatementKind::skKeyword)) {
return false;
} else
return statement1->command < statement2->command;
return nameComparator(statement1,statement2);
}
static bool sortByScopeWithUsageComparator(PStatement statement1,PStatement statement2){
@ -299,9 +307,8 @@ static bool sortByScopeWithUsageComparator(PStatement statement1,PStatement stat
} else if (statement1->scope == StatementScope::ssGlobal
&& statement2->scope != StatementScope::ssGlobal ) {
return false;
// otherwise, sort by name
} else
return statement1->command < statement2->command;
return nameComparator(statement1,statement2);
}
void CodeCompletionPopup::filterList(const QString &member)
@ -331,8 +338,16 @@ void CodeCompletionPopup::filterList(const QString &member)
Qt::CaseSensitivity cs = (mIgnoreCase?
Qt::CaseInsensitive:
Qt::CaseSensitive);
if (statement->command.startsWith(member, cs))
if (statement->command.startsWith(member, cs)) {
if (mIgnoreCase) {
statement->caseMatch =
statement->command.startsWith(
member,Qt::CaseSensitive);
} else {
statement->caseMatch = true;
}
mCompletionStatementList.append(statement);
}
}
} else
mCompletionStatementList.append(mFullCompletionStatementList);