work save

This commit is contained in:
royqh1979@gmail.com 2021-09-25 08:40:18 +08:00
parent 7c325715fd
commit 342f497fba
6 changed files with 53 additions and 48 deletions

View File

@ -2247,7 +2247,8 @@ QString Editor::getHintForFunction(const PStatement &statement, const PStatement
void Editor::updateFunctionTip() void Editor::updateFunctionTip()
{ {
BufferCoord caretPos = caretXY(); BufferCoord caretPos = caretXY();
NormalizedBufferCoord curPos = fromBufferCoord(caretPos); ContentsCoord curPos = fromBufferCoord(caretPos);
ContentsCoord cursorPos = curPos;
int nBraces = 0; int nBraces = 0;
int nCommas = 0; int nCommas = 0;
int FMaxScanLength = 500; int FMaxScanLength = 500;
@ -2303,8 +2304,9 @@ void Editor::updateFunctionTip()
return; return;
} }
NormalizedBufferCoord FFunctionEnd = curPos; ContentsCoord FFunctionEnd = curPos;
int paramPos = 0;
// We've stopped at the ending ), start walking backwards )*here* with nBraces = -1 // We've stopped at the ending ), start walking backwards )*here* with nBraces = -1
for (int i=0;i<FMaxScanLength;i++) { for (int i=0;i<FMaxScanLength;i++) {
QChar ch = *curPos; QChar ch = *curPos;
@ -2328,20 +2330,25 @@ void Editor::updateFunctionTip()
if (nBraces == -1) // found it! if (nBraces == -1) // found it!
break;; break;;
} else if (ch == ',') { } else if (ch == ',') {
if (nBraces == 0) if (nBraces == 0) {
if (curPos <= cursorPos) {
paramPos = nCommas;
}
nCommas++; nCommas++;
} }
}
curPos -= 1; curPos -= 1;
if (curPos.atStart()) if (curPos.atStart())
break; break;
} }
paramPos = nCommas - paramPos;
// If we couldn't find the closing brace or reached the FMaxScanLength... // If we couldn't find the closing brace or reached the FMaxScanLength...
if (nBraces!=-1) { if (nBraces!=-1) {
return; return;
} }
NormalizedBufferCoord FFunctionStart = curPos; ContentsCoord FFunctionStart = curPos;
// Skip blanks // Skip blanks
while (!curPos.atStart()) { while (!curPos.atStart()) {
@ -2354,7 +2361,7 @@ void Editor::updateFunctionTip()
} }
} }
NormalizedBufferCoord prevPos = curPos-1; ContentsCoord prevPos = curPos-1;
if (prevPos.atStart()) if (prevPos.atStart())
return; return;
// Get the name of the function we're about to show // Get the name of the function we're about to show
@ -2400,7 +2407,7 @@ void Editor::updateFunctionTip()
pMainWindow->functionTip()->setFunctioFullName(s); pMainWindow->functionTip()->setFunctioFullName(s);
pMainWindow->functionTip()->guessFunction(nCommas); pMainWindow->functionTip()->guessFunction(nCommas);
pMainWindow->functionTip()->setParamIndex( pMainWindow->functionTip()->setParamIndex(
getFunctionParamIndex(FFunctionStart,caretPos,FFunctionEnd) paramPos
); );
pMainWindow->functionTip()->show(); pMainWindow->functionTip()->show();
//// // get the current token position in the text //// // get the current token position in the text

View File

@ -699,17 +699,17 @@ BufferCoord SynEdit::displayToBufferPos(const DisplayCoord &p) const
return Result; return Result;
} }
NormalizedBufferCoord SynEdit::fromBufferCoord(const BufferCoord &p) const ContentsCoord SynEdit::fromBufferCoord(const BufferCoord &p) const
{ {
return createNormalizedBufferCoord(p.Char,p.Line); return createNormalizedBufferCoord(p.Char,p.Line);
} }
NormalizedBufferCoord SynEdit::createNormalizedBufferCoord(int aChar, int aLine) const ContentsCoord SynEdit::createNormalizedBufferCoord(int aChar, int aLine) const
{ {
return NormalizedBufferCoord(this,aChar,aLine); return ContentsCoord(this,aChar,aLine);
} }
QStringList SynEdit::getContents(const NormalizedBufferCoord &pStart, const NormalizedBufferCoord &pEnd) QStringList SynEdit::getContents(const ContentsCoord &pStart, const ContentsCoord &pEnd)
{ {
QStringList result; QStringList result;
if (mLines->count()==0) if (mLines->count()==0)
@ -728,7 +728,7 @@ QStringList SynEdit::getContents(const NormalizedBufferCoord &pStart, const Norm
return result; return result;
} }
QString SynEdit::getJoinedContents(const NormalizedBufferCoord &pStart, const NormalizedBufferCoord &pEnd, const QString &joinStr) QString SynEdit::getJoinedContents(const ContentsCoord &pStart, const ContentsCoord &pEnd, const QString &joinStr)
{ {
return getContents(pStart,pEnd).join(joinStr); return getContents(pStart,pEnd).join(joinStr);
} }
@ -6008,19 +6008,3 @@ void SynEdit::onScrollTimeout()
} }
computeScroll(iMousePos.x(), iMousePos.y()); computeScroll(iMousePos.x(), iMousePos.y());
} }
SynEdit::Contents::Contents(const SynEdit *edit)
{
mEdit = edit;
}
QChar SynEdit::Contents::charAt(const NormalizedBufferCoord &coord) const
{
Q_ASSERT(coord.edit() == mEdit);
return *coord;
}
QChar SynEdit::Contents::operator[](const NormalizedBufferCoord &coord) const
{
return charAt(coord);
}

View File

@ -138,6 +138,7 @@ class SynEdit : public QAbstractScrollArea
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SynEdit(QWidget* parent=nullptr);
/** /**
* Returns how many rows are there in the editor * Returns how many rows are there in the editor
* @return * @return
@ -165,10 +166,10 @@ public:
BufferCoord displayToBufferPos(const DisplayCoord& p) const; BufferCoord displayToBufferPos(const DisplayCoord& p) const;
//normalized buffer coord operations //normalized buffer coord operations
NormalizedBufferCoord fromBufferCoord(const BufferCoord& p) const; ContentsCoord fromBufferCoord(const BufferCoord& p) const;
NormalizedBufferCoord createNormalizedBufferCoord(int aChar,int aLine) const; ContentsCoord createNormalizedBufferCoord(int aChar,int aLine) const;
QStringList getContents(const NormalizedBufferCoord& pStart,const NormalizedBufferCoord& pEnd); QStringList getContents(const ContentsCoord& pStart,const ContentsCoord& pEnd);
QString getJoinedContents(const NormalizedBufferCoord& pStart,const NormalizedBufferCoord& pEnd, const QString& joinStr); QString getJoinedContents(const ContentsCoord& pStart,const ContentsCoord& pEnd, const QString& joinStr);
int leftSpaces(const QString& line) const; int leftSpaces(const QString& line) const;
QString GetLeftSpacing(int charCount,bool wantTabs) const; QString GetLeftSpacing(int charCount,bool wantTabs) const;

View File

@ -20,10 +20,10 @@ class SynEdit;
* (length of the line+1, line) means at the line break of the line ('\n') * (length of the line+1, line) means at the line break of the line ('\n')
*/ */
class NormalizedBufferCoord { class ContentsCoord {
public: public:
NormalizedBufferCoord(); ContentsCoord();
NormalizedBufferCoord(const NormalizedBufferCoord& coord); ContentsCoord(const ContentsCoord& coord);
int ch() const; int ch() const;
void setCh(int newChar); void setCh(int newChar);
@ -32,22 +32,22 @@ public:
bool atStart(); bool atStart();
bool atEnd(); bool atEnd();
const SynEdit *edit() const; const SynEdit *edit() const;
const NormalizedBufferCoord& operator=(const NormalizedBufferCoord& coord); const ContentsCoord& operator=(const ContentsCoord& coord);
const NormalizedBufferCoord& operator=(const NormalizedBufferCoord&& coord); const ContentsCoord& operator=(const ContentsCoord&& coord);
bool operator==(const NormalizedBufferCoord& coord) const; bool operator==(const ContentsCoord& coord) const;
bool operator<(const NormalizedBufferCoord& coord) const; bool operator<(const ContentsCoord& coord) const;
bool operator<=(const NormalizedBufferCoord& coord) const; bool operator<=(const ContentsCoord& coord) const;
bool operator>(const NormalizedBufferCoord& coord) const; bool operator>(const ContentsCoord& coord) const;
bool operator>=(const NormalizedBufferCoord& coord) const; bool operator>=(const ContentsCoord& coord) const;
size_t operator-(const NormalizedBufferCoord& coord) const; size_t operator-(const ContentsCoord& coord) const;
const NormalizedBufferCoord& operator+=(int delta); const ContentsCoord& operator+=(int delta);
const NormalizedBufferCoord& operator-=(int delta); const ContentsCoord& operator-=(int delta);
NormalizedBufferCoord operator+(int delta) const; ContentsCoord operator+(int delta) const;
NormalizedBufferCoord operator-(int delta) const; ContentsCoord operator-(int delta) const;
BufferCoord toBufferCoord() const; BufferCoord toBufferCoord() const;
QChar operator*() const; QChar operator*() const;
private: private:
NormalizedBufferCoord(const SynEdit* edit, int ch, int line); ContentsCoord(const SynEdit* edit, int ch, int line);
void normalize(); void normalize();
private: private:
int mChar; int mChar;

View File

@ -105,6 +105,18 @@ void FunctionTooltipWidget::updateTip()
mInfoLabel->setText(text); mInfoLabel->setText(text);
} }
void FunctionTooltipWidget::guesstFunction(int commas)
{
for (int i=0;i<mInfos.size();i++) {
if (mInfos[i]->params.count()>commas) {
mInfoIndex = i;
return;
}
}
mInfoIndex = 0;
return;
}
QStringList FunctionTooltipWidget::splitArgs(QString argStr) QStringList FunctionTooltipWidget::splitArgs(QString argStr)
{ {
int i = 0; int i = 0;
@ -161,7 +173,7 @@ void FunctionTooltipWidget::closeEvent(QCloseEvent *)
void FunctionTooltipWidget::showEvent(QShowEvent *) void FunctionTooltipWidget::showEvent(QShowEvent *)
{ {
if (mInfos.length()>0) { if (mInfoIndex<0 || mInfoIndex>= mInfos.count()) {
mInfoIndex = 0; mInfoIndex = 0;
} }
updateTip(); updateTip();

View File

@ -29,6 +29,7 @@ public:
void nextTip(); void nextTip();
void previousTip(); void previousTip();
void updateTip(); void updateTip();
void guesstFunction(int commas);
int paramIndex() const; int paramIndex() const;
void setParamIndex(int newParamIndex); void setParamIndex(int newParamIndex);