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

View File

@ -699,17 +699,17 @@ BufferCoord SynEdit::displayToBufferPos(const DisplayCoord &p) const
return Result;
}
NormalizedBufferCoord SynEdit::fromBufferCoord(const BufferCoord &p) const
ContentsCoord SynEdit::fromBufferCoord(const BufferCoord &p) const
{
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;
if (mLines->count()==0)
@ -728,7 +728,7 @@ QStringList SynEdit::getContents(const NormalizedBufferCoord &pStart, const Norm
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);
}
@ -6008,19 +6008,3 @@ void SynEdit::onScrollTimeout()
}
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
public:
explicit SynEdit(QWidget* parent=nullptr);
/**
* Returns how many rows are there in the editor
* @return
@ -165,10 +166,10 @@ public:
BufferCoord displayToBufferPos(const DisplayCoord& p) const;
//normalized buffer coord operations
NormalizedBufferCoord fromBufferCoord(const BufferCoord& p) const;
NormalizedBufferCoord createNormalizedBufferCoord(int aChar,int aLine) const;
QStringList getContents(const NormalizedBufferCoord& pStart,const NormalizedBufferCoord& pEnd);
QString getJoinedContents(const NormalizedBufferCoord& pStart,const NormalizedBufferCoord& pEnd, const QString& joinStr);
ContentsCoord fromBufferCoord(const BufferCoord& p) const;
ContentsCoord createNormalizedBufferCoord(int aChar,int aLine) const;
QStringList getContents(const ContentsCoord& pStart,const ContentsCoord& pEnd);
QString getJoinedContents(const ContentsCoord& pStart,const ContentsCoord& pEnd, const QString& joinStr);
int leftSpaces(const QString& line) 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')
*/
class NormalizedBufferCoord {
class ContentsCoord {
public:
NormalizedBufferCoord();
NormalizedBufferCoord(const NormalizedBufferCoord& coord);
ContentsCoord();
ContentsCoord(const ContentsCoord& coord);
int ch() const;
void setCh(int newChar);
@ -32,22 +32,22 @@ public:
bool atStart();
bool atEnd();
const SynEdit *edit() const;
const NormalizedBufferCoord& operator=(const NormalizedBufferCoord& coord);
const NormalizedBufferCoord& operator=(const NormalizedBufferCoord&& coord);
bool operator==(const NormalizedBufferCoord& coord) const;
bool operator<(const NormalizedBufferCoord& coord) const;
bool operator<=(const NormalizedBufferCoord& coord) const;
bool operator>(const NormalizedBufferCoord& coord) const;
bool operator>=(const NormalizedBufferCoord& coord) const;
size_t operator-(const NormalizedBufferCoord& coord) const;
const NormalizedBufferCoord& operator+=(int delta);
const NormalizedBufferCoord& operator-=(int delta);
NormalizedBufferCoord operator+(int delta) const;
NormalizedBufferCoord operator-(int delta) const;
const ContentsCoord& operator=(const ContentsCoord& coord);
const ContentsCoord& operator=(const ContentsCoord&& coord);
bool operator==(const ContentsCoord& coord) const;
bool operator<(const ContentsCoord& coord) const;
bool operator<=(const ContentsCoord& coord) const;
bool operator>(const ContentsCoord& coord) const;
bool operator>=(const ContentsCoord& coord) const;
size_t operator-(const ContentsCoord& coord) const;
const ContentsCoord& operator+=(int delta);
const ContentsCoord& operator-=(int delta);
ContentsCoord operator+(int delta) const;
ContentsCoord operator-(int delta) const;
BufferCoord toBufferCoord() const;
QChar operator*() const;
private:
NormalizedBufferCoord(const SynEdit* edit, int ch, int line);
ContentsCoord(const SynEdit* edit, int ch, int line);
void normalize();
private:
int mChar;

View File

@ -105,6 +105,18 @@ void FunctionTooltipWidget::updateTip()
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)
{
int i = 0;
@ -161,7 +173,7 @@ void FunctionTooltipWidget::closeEvent(QCloseEvent *)
void FunctionTooltipWidget::showEvent(QShowEvent *)
{
if (mInfos.length()>0) {
if (mInfoIndex<0 || mInfoIndex>= mInfos.count()) {
mInfoIndex = 0;
}
updateTip();

View File

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