work save
This commit is contained in:
parent
97b8fb1971
commit
c8704fdfbb
|
@ -1364,6 +1364,39 @@ void SynEdit::setWordBlock(BufferCoord Value)
|
||||||
setCaretAndSelection(v_WordEnd, v_WordStart, v_WordEnd);
|
setCaretAndSelection(v_WordEnd, v_WordStart, v_WordEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SynEdit::calcIndentSpaces(int line, const QString& lineText)
|
||||||
|
{
|
||||||
|
if (!mHighlighter)
|
||||||
|
return 0;
|
||||||
|
line = std::min(line, line = mLines->count()+1);
|
||||||
|
if (line<=1)
|
||||||
|
return 0;
|
||||||
|
int startLine = line-1;
|
||||||
|
int indentSpaces = 0;
|
||||||
|
QString s;
|
||||||
|
while (startLine>=1) {
|
||||||
|
s = mLines->getString(startLine-1);
|
||||||
|
if (!s.trimmed().isEmpty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
startLine -- ;
|
||||||
|
}
|
||||||
|
if (startLine>=1) {
|
||||||
|
SynRangeState range = mLines->ranges(startLine-1);
|
||||||
|
indentSpaces = leftSpaces(s);
|
||||||
|
int left = range.leftBraces+range.leftBrackets+range.leftParenthesis;
|
||||||
|
indentSpaces+=left*mTabWidth;
|
||||||
|
|
||||||
|
mHighlighter->setLine(lineText,line);
|
||||||
|
mHighlighter->setState(range);
|
||||||
|
mHighlighter->nextToEol();
|
||||||
|
range = mHighlighter->getRangeState();
|
||||||
|
int right = range.rightBraces+range.rightBrackets+range.leftParenthesis;
|
||||||
|
indentSpaces-=right*mTabWidth;
|
||||||
|
}
|
||||||
|
return std::max(0,indentSpaces);
|
||||||
|
}
|
||||||
|
|
||||||
void SynEdit::doSelectAll()
|
void SynEdit::doSelectAll()
|
||||||
{
|
{
|
||||||
BufferCoord LastPt;
|
BufferCoord LastPt;
|
||||||
|
@ -1894,7 +1927,8 @@ void SynEdit::insertLine(bool moveCaret)
|
||||||
if (Len > 0) {
|
if (Len > 0) {
|
||||||
if (Len >= mCaretX) {
|
if (Len >= mCaretX) {
|
||||||
if (mCaretX <= 1) {
|
if (mCaretX <= 1) {
|
||||||
mLines->insert(mCaretY - 1, "");
|
mLines->insert(mCaretY - 1,
|
||||||
|
GetLeftSpacing(calcIndentSpaces(mCaretY,""),true));
|
||||||
nLinesInserted++;
|
nLinesInserted++;
|
||||||
mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), Temp2,
|
mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), Temp2,
|
||||||
SynSelectionMode::smNormal);
|
SynSelectionMode::smNormal);
|
||||||
|
@ -1944,7 +1978,7 @@ void SynEdit::insertLine(bool moveCaret)
|
||||||
internalSetCaretXY(BufferCoord{indentSpacesForRightLineText.length()+1,mCaretY + 1});
|
internalSetCaretXY(BufferCoord{indentSpacesForRightLineText.length()+1,mCaretY + 1});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SpaceCount2 = 0;
|
SpaceCount2 = calcIndentSpaces(mCaretY,"");
|
||||||
int BackCounter = mCaretY;
|
int BackCounter = mCaretY;
|
||||||
if (mOptions.testFlag(eoAutoIndent)) {
|
if (mOptions.testFlag(eoAutoIndent)) {
|
||||||
do {
|
do {
|
||||||
|
@ -1953,7 +1987,7 @@ void SynEdit::insertLine(bool moveCaret)
|
||||||
SpaceCount2 = leftSpaces(Temp);
|
SpaceCount2 = leftSpaces(Temp);
|
||||||
} while ((BackCounter != 0) && (Temp == ""));
|
} while ((BackCounter != 0) && (Temp == ""));
|
||||||
}
|
}
|
||||||
mLines->insert(mCaretY, "");
|
mLines->insert(mCaretY, GetLeftSpacing(,true)));
|
||||||
nLinesInserted++;
|
nLinesInserted++;
|
||||||
BufferCoord Caret = caretXY();
|
BufferCoord Caret = caretXY();
|
||||||
if (moveCaret) {
|
if (moveCaret) {
|
||||||
|
@ -2839,8 +2873,7 @@ int SynEdit::scanFrom(int Index, int canStopIndex)
|
||||||
return Result;// avoid the final Decrement
|
return Result;// avoid the final Decrement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mLines->setRange(Result,iRange, mHighlighter->getLeftBraces(),
|
mLines->setRange(Result,iRange);
|
||||||
mHighlighter->getRightBraces());
|
|
||||||
Result ++ ;
|
Result ++ ;
|
||||||
} while (Result < mLines->count());
|
} while (Result < mLines->count());
|
||||||
Result--;
|
Result--;
|
||||||
|
@ -2856,9 +2889,7 @@ void SynEdit::scanRanges()
|
||||||
for (int i =0;i<mLines->count();i++) {
|
for (int i =0;i<mLines->count();i++) {
|
||||||
mHighlighter->setLine(mLines->getString(i), i);
|
mHighlighter->setLine(mLines->getString(i), i);
|
||||||
mHighlighter->nextToEol();
|
mHighlighter->nextToEol();
|
||||||
mLines->setRange(i, mHighlighter->getRangeState(),
|
mLines->setRange(i, mHighlighter->getRangeState());
|
||||||
mHighlighter->getLeftBraces(),
|
|
||||||
mHighlighter->getRightBraces());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mUseCodeFolding)
|
if (mUseCodeFolding)
|
||||||
|
|
|
@ -506,6 +506,8 @@ private:
|
||||||
void setSelWord();
|
void setSelWord();
|
||||||
void setWordBlock(BufferCoord Value);
|
void setWordBlock(BufferCoord Value);
|
||||||
|
|
||||||
|
int calcIndentSpaces(int line, const QString& lineText = "");
|
||||||
|
|
||||||
|
|
||||||
void processGutterClick(QMouseEvent* event);
|
void processGutterClick(QMouseEvent* event);
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ int SynEditStringList::leftBraces(int Index)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mMutex);
|
QMutexLocker locker(&mMutex);
|
||||||
if (Index>=0 && Index < mList.size()) {
|
if (Index>=0 && Index < mList.size()) {
|
||||||
return mList[Index]->fLeftBraces;
|
return mList[Index]->fRange.leftBraces;
|
||||||
} else
|
} else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ int SynEditStringList::rightBraces(int Index)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mMutex);
|
QMutexLocker locker(&mMutex);
|
||||||
if (Index>=0 && Index < mList.size()) {
|
if (Index>=0 && Index < mList.size()) {
|
||||||
return mList[Index]->fRightBraces;
|
return mList[Index]->fRange.rightBraces;
|
||||||
} else
|
} else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ void SynEditStringList::setAppendNewLineAtEOF(bool appendNewLineAtEOF)
|
||||||
mAppendNewLineAtEOF = appendNewLineAtEOF;
|
mAppendNewLineAtEOF = appendNewLineAtEOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEditStringList::setRange(int Index, const SynRangeState& ARange, int ALeftBraces, int ARightBraces)
|
void SynEditStringList::setRange(int Index, const SynRangeState& ARange)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mMutex);
|
QMutexLocker locker(&mMutex);
|
||||||
if (Index<0 || Index>=mList.count()) {
|
if (Index<0 || Index>=mList.count()) {
|
||||||
|
@ -179,8 +179,6 @@ void SynEditStringList::setRange(int Index, const SynRangeState& ARange, int ALe
|
||||||
}
|
}
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
mList[Index]->fRange = ARange;
|
mList[Index]->fRange = ARange;
|
||||||
mList[Index]->fLeftBraces = ALeftBraces;
|
|
||||||
mList[Index]->fRightBraces = ARightBraces;
|
|
||||||
endUpdate();
|
endUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ struct SynEditStringRec {
|
||||||
QString fString;
|
QString fString;
|
||||||
void * fObject;
|
void * fObject;
|
||||||
SynRangeState fRange;
|
SynRangeState fRange;
|
||||||
int fLeftBraces;
|
|
||||||
int fRightBraces;
|
|
||||||
int fColumns; //
|
int fColumns; //
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -60,7 +58,7 @@ public:
|
||||||
int lengthOfLongestLine();
|
int lengthOfLongestLine();
|
||||||
QString lineBreak() const;
|
QString lineBreak() const;
|
||||||
SynRangeState ranges(int Index);
|
SynRangeState ranges(int Index);
|
||||||
void setRange(int Index, const SynRangeState& ARange, int leftBraces, int rightBraces);
|
void setRange(int Index, const SynRangeState& ARange);
|
||||||
QString getString(int Index);
|
QString getString(int Index);
|
||||||
int count();
|
int count();
|
||||||
void* getObject(int Index);
|
void* getObject(int Index);
|
||||||
|
|
|
@ -64,16 +64,6 @@ void SynHighlighter::nextToEol()
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SynHighlighter::getLeftBraces()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SynHighlighter::getRightBraces()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SynHighlighter::isSpaceChar(const QChar &ch)
|
bool SynHighlighter::isSpaceChar(const QChar &ch)
|
||||||
{
|
{
|
||||||
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
|
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
|
||||||
|
|
|
@ -16,6 +16,12 @@ struct SynRangeState {
|
||||||
int braceLevel;
|
int braceLevel;
|
||||||
int bracketLevel;
|
int bracketLevel;
|
||||||
int parenthesisLevel;
|
int parenthesisLevel;
|
||||||
|
int leftBraces;
|
||||||
|
int rightBraces;
|
||||||
|
int leftBrackets;
|
||||||
|
int rightBrackets;
|
||||||
|
int leftParenthesis;
|
||||||
|
int rightParenthesis;
|
||||||
bool operator==(const SynRangeState& s2);
|
bool operator==(const SynRangeState& s2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -108,9 +114,6 @@ public:
|
||||||
virtual void setLine(const QString& newLine, int lineNumber) = 0;
|
virtual void setLine(const QString& newLine, int lineNumber) = 0;
|
||||||
virtual void resetState() = 0;
|
virtual void resetState() = 0;
|
||||||
|
|
||||||
virtual int getLeftBraces();
|
|
||||||
virtual int getRightBraces();
|
|
||||||
|
|
||||||
virtual QString languageName() = 0;
|
virtual QString languageName() = 0;
|
||||||
virtual SynHighlighterLanguage language() = 0;
|
virtual SynHighlighterLanguage language() = 0;
|
||||||
|
|
||||||
|
|
|
@ -153,14 +153,7 @@ SynEditCppHighlighter::SynEditCppHighlighter(): SynHighlighter()
|
||||||
mVariableAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrVariable);
|
mVariableAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrVariable);
|
||||||
addAttribute(mVariableAttribute);
|
addAttribute(mVariableAttribute);
|
||||||
|
|
||||||
mRange.state = RangeState::rsUnknown;
|
resetState();
|
||||||
mRange.spaceState = RangeState::rsUnknown;
|
|
||||||
mRange.braceLevel = 0;
|
|
||||||
mRange.bracketLevel = 0;
|
|
||||||
mRange.parenthesisLevel = 0;
|
|
||||||
mLeftBraces = 0;
|
|
||||||
mRightBraces = 0;
|
|
||||||
mAsmStart = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PSynHighlighterAttribute SynEditCppHighlighter::asmAttribute() const
|
PSynHighlighterAttribute SynEditCppHighlighter::asmAttribute() const
|
||||||
|
@ -368,10 +361,10 @@ void SynEditCppHighlighter::braceCloseProc()
|
||||||
}
|
}
|
||||||
|
|
||||||
mRange.braceLevel -= 1;
|
mRange.braceLevel -= 1;
|
||||||
if (mLeftBraces>0) {
|
if (mRange.leftBraces>0) {
|
||||||
mLeftBraces--;
|
mRange.leftBraces--;
|
||||||
} else {
|
} else {
|
||||||
mRightBraces++ ;
|
mRange.rightBraces++ ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +378,7 @@ void SynEditCppHighlighter::braceOpenProc()
|
||||||
mAsmStart = true;
|
mAsmStart = true;
|
||||||
}
|
}
|
||||||
mRange.braceLevel += 1;
|
mRange.braceLevel += 1;
|
||||||
mLeftBraces++;
|
mRange.leftBraces++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEditCppHighlighter::colonProc()
|
void SynEditCppHighlighter::colonProc()
|
||||||
|
@ -887,6 +880,11 @@ void SynEditCppHighlighter::roundCloseProc()
|
||||||
mTokenId = TokenKind::Symbol;
|
mTokenId = TokenKind::Symbol;
|
||||||
mExtTokenId = ExtTokenKind::RoundClose;
|
mExtTokenId = ExtTokenKind::RoundClose;
|
||||||
mRange.parenthesisLevel--;
|
mRange.parenthesisLevel--;
|
||||||
|
if (mRange.leftParenthesis>0) {
|
||||||
|
mRange.leftParenthesis--;
|
||||||
|
} else {
|
||||||
|
mRange.rightParenthesis++ ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEditCppHighlighter::roundOpenProc()
|
void SynEditCppHighlighter::roundOpenProc()
|
||||||
|
@ -895,6 +893,7 @@ void SynEditCppHighlighter::roundOpenProc()
|
||||||
mTokenId = TokenKind::Symbol;
|
mTokenId = TokenKind::Symbol;
|
||||||
mExtTokenId = ExtTokenKind::RoundOpen;
|
mExtTokenId = ExtTokenKind::RoundOpen;
|
||||||
mRange.parenthesisLevel++;
|
mRange.parenthesisLevel++;
|
||||||
|
mRange.leftParenthesis++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEditCppHighlighter::semiColonProc()
|
void SynEditCppHighlighter::semiColonProc()
|
||||||
|
@ -957,6 +956,11 @@ void SynEditCppHighlighter::squareCloseProc()
|
||||||
mTokenId = TokenKind::Symbol;
|
mTokenId = TokenKind::Symbol;
|
||||||
mExtTokenId = ExtTokenKind::SquareClose;
|
mExtTokenId = ExtTokenKind::SquareClose;
|
||||||
mRange.bracketLevel--;
|
mRange.bracketLevel--;
|
||||||
|
if (mRange.leftBrackets>0) {
|
||||||
|
mRange.leftBrackets--;
|
||||||
|
} else {
|
||||||
|
mRange.rightBrackets++ ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEditCppHighlighter::squareOpenProc()
|
void SynEditCppHighlighter::squareOpenProc()
|
||||||
|
@ -965,6 +969,7 @@ void SynEditCppHighlighter::squareOpenProc()
|
||||||
mTokenId = TokenKind::Symbol;
|
mTokenId = TokenKind::Symbol;
|
||||||
mExtTokenId = ExtTokenKind::SquareOpen;
|
mExtTokenId = ExtTokenKind::SquareOpen;
|
||||||
mRange.bracketLevel++;
|
mRange.bracketLevel++;
|
||||||
|
mRange.leftBrackets++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEditCppHighlighter::starProc()
|
void SynEditCppHighlighter::starProc()
|
||||||
|
@ -1480,8 +1485,6 @@ void SynEditCppHighlighter::setLine(const QString &newLine, int lineNumber)
|
||||||
mLine = mLineString.data();
|
mLine = mLineString.data();
|
||||||
mLineNumber = lineNumber;
|
mLineNumber = lineNumber;
|
||||||
mRun = 0;
|
mRun = 0;
|
||||||
mLeftBraces = 0;
|
|
||||||
mRightBraces = 0;
|
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1545,6 +1548,13 @@ SynHighlighterTokenType SynEditCppHighlighter::getTokenType()
|
||||||
void SynEditCppHighlighter::setState(const SynRangeState& rangeState)
|
void SynEditCppHighlighter::setState(const SynRangeState& rangeState)
|
||||||
{
|
{
|
||||||
mRange = rangeState;
|
mRange = rangeState;
|
||||||
|
// current line's left / right parenthesis count should be reset before parsing each line
|
||||||
|
mRange.leftBraces = 0;
|
||||||
|
mRange.leftBrackets = 0;
|
||||||
|
mRange.leftParenthesis = 0;
|
||||||
|
mRange.rightBraces = 0;
|
||||||
|
mRange.rightBrackets = 0;
|
||||||
|
mRange.rightParenthesis = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEditCppHighlighter::resetState()
|
void SynEditCppHighlighter::resetState()
|
||||||
|
@ -1554,6 +1564,13 @@ void SynEditCppHighlighter::resetState()
|
||||||
mRange.braceLevel = 0;
|
mRange.braceLevel = 0;
|
||||||
mRange.bracketLevel = 0;
|
mRange.bracketLevel = 0;
|
||||||
mRange.parenthesisLevel = 0;
|
mRange.parenthesisLevel = 0;
|
||||||
|
mRange.leftBraces = 0;
|
||||||
|
mRange.leftBrackets = 0;
|
||||||
|
mRange.leftParenthesis = 0;
|
||||||
|
mRange.rightBraces = 0;
|
||||||
|
mRange.rightBrackets = 0;
|
||||||
|
mRange.rightParenthesis = 0;
|
||||||
|
mAsmStart = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SynHighlighterClass SynEditCppHighlighter::getClass() const
|
SynHighlighterClass SynEditCppHighlighter::getClass() const
|
||||||
|
@ -1576,16 +1593,6 @@ SynHighlighterLanguage SynEditCppHighlighter::language()
|
||||||
return SynHighlighterLanguage::Cpp;
|
return SynHighlighterLanguage::Cpp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SynEditCppHighlighter::getLeftBraces()
|
|
||||||
{
|
|
||||||
return mLeftBraces;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SynEditCppHighlighter::getRightBraces()
|
|
||||||
{
|
|
||||||
return mRightBraces;
|
|
||||||
}
|
|
||||||
|
|
||||||
SynRangeState SynEditCppHighlighter::getRangeState() const
|
SynRangeState SynEditCppHighlighter::getRangeState() const
|
||||||
{
|
{
|
||||||
return mRange;
|
return mRange;
|
||||||
|
|
|
@ -180,9 +180,6 @@ public:
|
||||||
QString languageName() override;
|
QString languageName() override;
|
||||||
SynHighlighterLanguage language() override;
|
SynHighlighterLanguage language() override;
|
||||||
|
|
||||||
int getLeftBraces() override;
|
|
||||||
int getRightBraces() override;
|
|
||||||
|
|
||||||
// SynHighlighter interface
|
// SynHighlighter interface
|
||||||
public:
|
public:
|
||||||
SynRangeState getRangeState() const override;
|
SynRangeState getRangeState() const override;
|
||||||
|
|
Loading…
Reference in New Issue