refactor: block start / end calculation
This commit is contained in:
parent
210eb8b6dc
commit
5d0c49a0bc
2
NEWS.md
2
NEWS.md
|
@ -2,6 +2,8 @@ Red Panda C++ Version 2.6
|
|||
|
||||
- enhancement: Highlighter for makefiles
|
||||
- fix: QSortFilterProxyModel not correctly cleared when exiting and project closed. (ASSERT fails in DEBUG mode.)
|
||||
- enhancement: Windows installers now use UNICODE encoding.
|
||||
- fix: can't correctly show code suggestions after "template <"
|
||||
|
||||
Red Panda C++ Version 2.5
|
||||
|
||||
|
|
|
@ -729,7 +729,6 @@ void Editor::keyPressEvent(QKeyEvent *event)
|
|||
return;
|
||||
} else if (mLastIdCharPressed==pSettings->codeCompletion().minCharRequired()){
|
||||
QString lastWord = getPreviousWordAtPositionForSuggestion(caretXY());
|
||||
|
||||
if (mParser && !lastWord.isEmpty()) {
|
||||
if (lastWord == "using") {
|
||||
commandProcessor(QSynedit::EditCommand::ecChar,ch,nullptr);
|
||||
|
@ -2350,7 +2349,7 @@ bool Editor::handleParentheseSkip()
|
|||
|
||||
if (document()->count()==0)
|
||||
return false;
|
||||
if (highlighter()) {
|
||||
if (highlighter() && highlighter()->supportBraceLevel()) {
|
||||
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1);
|
||||
if (lastLineState.parenthesisLevel==0) {
|
||||
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||
|
@ -2401,7 +2400,7 @@ bool Editor::handleBracketSkip()
|
|||
|
||||
if (document()->count()==0)
|
||||
return false;
|
||||
if (highlighter()) {
|
||||
if (highlighter() && highlighter()->supportBraceLevel()) {
|
||||
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1);
|
||||
if (lastLineState.bracketLevel==0) {
|
||||
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||
|
@ -2487,7 +2486,8 @@ bool Editor::handleBraceSkip()
|
|||
|
||||
if (document()->count()==0)
|
||||
return false;
|
||||
if (highlighter()) {
|
||||
|
||||
if (highlighter() && highlighter()->supportBraceLevel()) {
|
||||
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1);
|
||||
if (lastLineState.braceLevel==0) {
|
||||
bool oldInsertMode = insertMode();
|
||||
|
@ -3150,7 +3150,6 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
|
|||
pos,
|
||||
memberOperator,
|
||||
memberExpression);
|
||||
// qDebug()<<ownerExpression<<memberExpression;
|
||||
word = memberExpression.join("");
|
||||
mCompletionPopup->prepareSearch(
|
||||
preWord,
|
||||
|
@ -4421,7 +4420,10 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo
|
|||
bracketLevel++;
|
||||
} else if (s[wordEnd] == '<'
|
||||
|| s[wordEnd] == '[') {
|
||||
bracketLevel--;
|
||||
if (bracketLevel>0)
|
||||
bracketLevel--;
|
||||
else
|
||||
return "";
|
||||
} else if (bracketLevel==0) {
|
||||
//we can't differentiate multiple definition and function parameter define here , so we don't handle ','
|
||||
if (s[wordEnd] == ',') {
|
||||
|
@ -4473,7 +4475,7 @@ QString Editor::getPreviousWordAtPositionForCompleteFunctionDefinition(const QSy
|
|||
if (wordEnd >= s.length())
|
||||
wordEnd = s.length()-1;
|
||||
while (wordEnd > 0 && (isIdentChar(s[wordEnd]) || s[wordEnd] == ':')) {
|
||||
wordEnd--;
|
||||
wordEnd--;
|
||||
}
|
||||
int bracketLevel=0;
|
||||
while (wordEnd > 0) {
|
||||
|
@ -4482,7 +4484,10 @@ QString Editor::getPreviousWordAtPositionForCompleteFunctionDefinition(const QSy
|
|||
bracketLevel++;
|
||||
} else if (s[wordEnd] == '<'
|
||||
|| s[wordEnd] == '[') {
|
||||
bracketLevel--;
|
||||
if (bracketLevel>0)
|
||||
bracketLevel--;
|
||||
else
|
||||
break;
|
||||
} else if (bracketLevel==0) {
|
||||
if (s[wordEnd]=='*' || s[wordEnd]=='&' || s[wordEnd]==' ' || s[wordEnd]=='\t') {
|
||||
//do nothing
|
||||
|
|
|
@ -49,7 +49,7 @@ CodeFoldingOptions::CodeFoldingOptions():
|
|||
folderBarLinesColor(QColor("black")),
|
||||
indentGuidesColor("gray")
|
||||
{
|
||||
foldRegions.add(true,'{','}',SYNS_AttrSymbol);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ struct CodeFoldingOptions {
|
|||
QColor collapsedLineColor;
|
||||
QColor folderBarLinesColor;
|
||||
QColor indentGuidesColor;
|
||||
CodeFoldingDefines foldRegions;
|
||||
//CodeFoldingDefines foldRegions;
|
||||
CodeFoldingOptions();
|
||||
};
|
||||
|
||||
|
|
|
@ -3424,6 +3424,10 @@ int SynEdit::scanFrom(int Index, int canStopIndex)
|
|||
iRange = mHighlighter->getState();
|
||||
if (Result > canStopIndex){
|
||||
if (mDocument->ranges(Result).state == iRange.state
|
||||
&& mDocument->ranges(Result).blockLevel == iRange.blockLevel
|
||||
&& mDocument->ranges(Result).blockStarted == iRange.blockStarted
|
||||
&& mDocument->ranges(Result).blockEnded == iRange.blockEnded
|
||||
&& mDocument->ranges(Result).blockEndedLastLine == iRange.blockEndedLastLine
|
||||
&& mDocument->ranges(Result).braceLevel == iRange.braceLevel
|
||||
&& mDocument->ranges(Result).parenthesisLevel == iRange.parenthesisLevel
|
||||
&& mDocument->ranges(Result).bracketLevel == iRange.bracketLevel
|
||||
|
@ -3600,13 +3604,10 @@ void SynEdit::rescanForFoldRanges()
|
|||
}
|
||||
}
|
||||
|
||||
void SynEdit::scanForFoldRanges(PCodeFoldingRanges TopFoldRanges)
|
||||
void SynEdit::scanForFoldRanges(PCodeFoldingRanges topFoldRanges)
|
||||
{
|
||||
PCodeFoldingRanges parentFoldRanges = TopFoldRanges;
|
||||
// Recursively scan for folds (all types)
|
||||
for (int i= 0 ; i< mCodeFolding.foldRegions.count() ; i++ ) {
|
||||
findSubFoldRange(TopFoldRanges, i,parentFoldRanges,PCodeFoldingRange());
|
||||
}
|
||||
PCodeFoldingRanges parentFoldRanges = topFoldRanges;
|
||||
findSubFoldRange(topFoldRanges, parentFoldRanges,PCodeFoldingRange());
|
||||
}
|
||||
|
||||
//this func should only be used in findSubFoldRange
|
||||
|
@ -3639,108 +3640,53 @@ int SynEdit::lineHasChar(int Line, int startChar, QChar character, const QString
|
|||
return -1;
|
||||
}
|
||||
|
||||
void SynEdit::findSubFoldRange(PCodeFoldingRanges TopFoldRanges, int FoldIndex,PCodeFoldingRanges& parentFoldRanges, PCodeFoldingRange Parent)
|
||||
void SynEdit::findSubFoldRange(PCodeFoldingRanges topFoldRanges, PCodeFoldingRanges& parentFoldRanges, PCodeFoldingRange parent)
|
||||
{
|
||||
PCodeFoldingRange CollapsedFold;
|
||||
int Line = 0;
|
||||
QString CurLine;
|
||||
PCodeFoldingRange collapsedFold;
|
||||
int line = 0;
|
||||
QString curLine;
|
||||
if (!mHighlighter)
|
||||
return;
|
||||
bool useBraces = ( mCodeFolding.foldRegions.get(FoldIndex)->openSymbol == "{"
|
||||
&& mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol == "}");
|
||||
|
||||
while (Line < mDocument->count()) { // index is valid for LinesToScan and fLines
|
||||
while (line < mDocument->count()) { // index is valid for LinesToScan and fLines
|
||||
// If there is a collapsed fold over here, skip it
|
||||
CollapsedFold = collapsedFoldStartAtLine(Line + 1); // only collapsed folds remain
|
||||
if (CollapsedFold) {
|
||||
Line = CollapsedFold->toLine;
|
||||
continue;
|
||||
collapsedFold = collapsedFoldStartAtLine(line + 1); // only collapsed folds remain
|
||||
if (collapsedFold) {
|
||||
line = collapsedFold->toLine;
|
||||
continue;
|
||||
}
|
||||
|
||||
//we just use braceLevel
|
||||
if (useBraces) {
|
||||
// Find an opening character on this line
|
||||
CurLine = mDocument->getString(Line);
|
||||
if (mDocument->rightBraces(Line)>0) {
|
||||
for (int i=0; i<mDocument->rightBraces(Line);i++) {
|
||||
// Stop the recursion if we find a closing char, and return to our parent
|
||||
if (Parent) {
|
||||
Parent->toLine = Line + 1;
|
||||
Parent = Parent->parent.lock();
|
||||
if (!Parent) {
|
||||
parentFoldRanges = TopFoldRanges;
|
||||
} else {
|
||||
parentFoldRanges = Parent->subFoldRanges;
|
||||
}
|
||||
// Find an opening character on this line
|
||||
curLine = mDocument->getString(line);
|
||||
if (mDocument->blockEnded(line)>0) {
|
||||
for (int i=0; i<mDocument->blockEnded(line);i++) {
|
||||
// Stop the recursion if we find a closing char, and return to our parent
|
||||
if (parent) {
|
||||
parent->toLine = line + 1;
|
||||
parent = parent->parent.lock();
|
||||
if (!parent) {
|
||||
parentFoldRanges = topFoldRanges;
|
||||
} else {
|
||||
parentFoldRanges = parent->subFoldRanges;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mDocument->leftBraces(Line)>0) {
|
||||
for (int i=0; i<mDocument->leftBraces(Line);i++) {
|
||||
// Add it to the top list of folds
|
||||
Parent = parentFoldRanges->addByParts(
|
||||
Parent,
|
||||
TopFoldRanges,
|
||||
Line + 1,
|
||||
Line + 1);
|
||||
parentFoldRanges = Parent->subFoldRanges;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Find an opening character on this line
|
||||
CurLine = mDocument->getString(Line);
|
||||
|
||||
mHighlighter->setState(mDocument->ranges(Line));
|
||||
mHighlighter->setLine(CurLine,Line);
|
||||
|
||||
QString token;
|
||||
int pos;
|
||||
while (!mHighlighter->eol()) {
|
||||
token = mHighlighter->getToken();
|
||||
pos = mHighlighter->getTokenPos()+token.length();
|
||||
PHighlighterAttribute attr = mHighlighter->getTokenAttribute();
|
||||
// We've found a starting character and it have proper highlighting (ignore stuff inside comments...)
|
||||
if (token == mCodeFolding.foldRegions.get(FoldIndex)->openSymbol && attr->name()==mCodeFolding.foldRegions.get(FoldIndex)->highlight) {
|
||||
// And ignore lines with both opening and closing chars in them
|
||||
if (lineHasChar(Line,pos,mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol,
|
||||
mCodeFolding.foldRegions.get(FoldIndex)->highlight)<0) {
|
||||
// Add it to the top list of folds
|
||||
Parent = parentFoldRanges->addByParts(
|
||||
Parent,
|
||||
TopFoldRanges,
|
||||
Line + 1,
|
||||
Line + 1);
|
||||
parentFoldRanges = Parent->subFoldRanges;
|
||||
|
||||
// Skip until a newline
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (token == mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol && attr->name()==mCodeFolding.foldRegions.get(FoldIndex)->highlight) {
|
||||
// And ignore lines with both opening and closing chars in them
|
||||
if (lineHasChar(Line,pos,mCodeFolding.foldRegions.get(FoldIndex)->openSymbol,
|
||||
mCodeFolding.foldRegions.get(FoldIndex)->highlight)<0) {
|
||||
// Stop the recursion if we find a closing char, and return to our parent
|
||||
if (Parent) {
|
||||
Parent->toLine = Line + 1;
|
||||
Parent = Parent->parent.lock();
|
||||
if (!Parent) {
|
||||
parentFoldRanges = TopFoldRanges;
|
||||
} else {
|
||||
parentFoldRanges = Parent->subFoldRanges;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip until a newline
|
||||
break;
|
||||
}
|
||||
}
|
||||
mHighlighter->next();
|
||||
}
|
||||
}
|
||||
Line++;
|
||||
if (mDocument->blockStarted(line)>0) {
|
||||
for (int i=0; i<mDocument->blockStarted(line);i++) {
|
||||
// Add it to the top list of folds
|
||||
parent = parentFoldRanges->addByParts(
|
||||
parent,
|
||||
topFoldRanges,
|
||||
line + 1,
|
||||
line + 1);
|
||||
parentFoldRanges = parent->subFoldRanges;
|
||||
}
|
||||
}
|
||||
line++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
PCodeFoldingRange SynEdit::collapsedFoldStartAtLine(int Line)
|
||||
|
@ -5039,10 +4985,10 @@ void SynEdit::doGotoBlockStart(bool isSelection)
|
|||
//todo: handle block other than {}
|
||||
if (document()->braceLevels(mCaretY-1)==0) {
|
||||
doGotoEditorStart(isSelection);
|
||||
} else if (document()->leftBraces(mCaretY-1)==0){
|
||||
} else if (document()->blockStarted(mCaretY-1)==0){
|
||||
int line=mCaretY-1;
|
||||
while (line>=1) {
|
||||
if (document()->leftBraces(line-1)>document()->rightBraces(line-1)) {
|
||||
if (document()->blockStarted(line-1)>document()->blockEnded(line-1)) {
|
||||
moveCaretVert(line+1-mCaretY, isSelection);
|
||||
moveCaretToLineStart(isSelection);
|
||||
setTopLine(line-1);
|
||||
|
@ -5059,12 +5005,12 @@ void SynEdit::doGotoBlockEnd(bool isSelection)
|
|||
return;
|
||||
HighlighterState state = document()->ranges(mCaretY-1);
|
||||
//todo: handle block other than {}
|
||||
if (document()->braceLevels(mCaretY-1)==0) {
|
||||
if (document()->blockLevel(mCaretY-1)==0) {
|
||||
doGotoEditorEnd(isSelection);
|
||||
} else if (document()->rightBraces(mCaretY-1)==0){
|
||||
} else if (document()->blockEnded(mCaretY-1)==0){
|
||||
int line=mCaretY+1;
|
||||
while (line<=document()->count()) {
|
||||
if (document()->rightBraces(line-1)>document()->leftBraces(line-1)) {
|
||||
if (document()->blockEnded(line-1)>document()->blockStarted(line-1)) {
|
||||
moveCaretVert(line-1-mCaretY, isSelection);
|
||||
moveCaretToLineStart(isSelection);
|
||||
setTopLine(line-mLinesInWindow+1);
|
||||
|
|
|
@ -513,9 +513,9 @@ private:
|
|||
void foldOnListCleared();
|
||||
void rescanFolds(); // rescan for folds
|
||||
void rescanForFoldRanges();
|
||||
void scanForFoldRanges(PCodeFoldingRanges TopFoldRanges);
|
||||
void scanForFoldRanges(PCodeFoldingRanges topFoldRanges);
|
||||
int lineHasChar(int Line, int startChar, QChar character, const QString& highlighterAttrName);
|
||||
void findSubFoldRange(PCodeFoldingRanges TopFoldRanges,int FoldIndex,PCodeFoldingRanges& parentFoldRanges, PCodeFoldingRange Parent);
|
||||
void findSubFoldRange(PCodeFoldingRanges topFoldRanges,PCodeFoldingRanges& parentFoldRanges, PCodeFoldingRange Parent);
|
||||
PCodeFoldingRange collapsedFoldStartAtLine(int Line);
|
||||
void initializeCaret();
|
||||
PCodeFoldingRange foldStartAtLine(int Line) const;
|
||||
|
|
|
@ -55,59 +55,71 @@ static void ListIndexOutOfBounds(int index) {
|
|||
|
||||
|
||||
|
||||
int Document::parenthesisLevels(int Index)
|
||||
int Document::parenthesisLevels(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index>=0 && Index < mLines.size()) {
|
||||
return mLines[Index]->fRange.parenthesisLevel;
|
||||
if (index>=0 && index < mLines.size()) {
|
||||
return mLines[index]->fRange.parenthesisLevel;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Document::bracketLevels(int Index)
|
||||
int Document::bracketLevels(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index>=0 && Index < mLines.size()) {
|
||||
return mLines[Index]->fRange.bracketLevel;
|
||||
if (index>=0 && index < mLines.size()) {
|
||||
return mLines[index]->fRange.bracketLevel;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Document::braceLevels(int Index)
|
||||
int Document::braceLevels(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index>=0 && Index < mLines.size()) {
|
||||
return mLines[Index]->fRange.braceLevel;
|
||||
if (index>=0 && index < mLines.size()) {
|
||||
return mLines[index]->fRange.braceLevel;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Document::lineColumns(int Index)
|
||||
int Document::lineColumns(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index>=0 && Index < mLines.size()) {
|
||||
if (mLines[Index]->fColumns == -1) {
|
||||
return calculateLineColumns(Index);
|
||||
if (index>=0 && index < mLines.size()) {
|
||||
if (mLines[index]->fColumns == -1) {
|
||||
return calculateLineColumns(index);
|
||||
} else
|
||||
return mLines[Index]->fColumns;
|
||||
return mLines[index]->fColumns;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Document::leftBraces(int Index)
|
||||
int Document::blockLevel(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index>=0 && Index < mLines.size()) {
|
||||
return mLines[Index]->fRange.leftBraces;
|
||||
if (index>=0 && index < mLines.size()) {
|
||||
return mLines[index]->fRange.blockLevel;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Document::rightBraces(int Index)
|
||||
int Document::blockStarted(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index>=0 && Index < mLines.size()) {
|
||||
return mLines[Index]->fRange.rightBraces;
|
||||
if (index>=0 && index < mLines.size()) {
|
||||
return mLines[index]->fRange.blockStarted;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Document::blockEnded(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (index>=0 && index < mLines.size()) {
|
||||
int result = mLines[index]->fRange.blockEnded;
|
||||
// if (index+1 < mLines.size())
|
||||
// result += mLines[index+1]->fRange.blockEndedLastLine;
|
||||
return result;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
@ -146,13 +158,13 @@ QString Document::lineBreak() const
|
|||
return "\n";
|
||||
}
|
||||
|
||||
HighlighterState Document::ranges(int Index)
|
||||
HighlighterState Document::ranges(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index>=0 && Index < mLines.size()) {
|
||||
return mLines[Index]->fRange;
|
||||
if (index>=0 && index < mLines.size()) {
|
||||
return mLines[index]->fRange;
|
||||
} else {
|
||||
ListIndexOutOfBounds(Index);
|
||||
ListIndexOutOfBounds(index);
|
||||
}
|
||||
return HighlighterState();
|
||||
}
|
||||
|
@ -189,14 +201,14 @@ void Document::setAppendNewLineAtEOF(bool appendNewLineAtEOF)
|
|||
mAppendNewLineAtEOF = appendNewLineAtEOF;
|
||||
}
|
||||
|
||||
void Document::setRange(int Index, const HighlighterState& ARange)
|
||||
void Document::setRange(int Index, const HighlighterState& range)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index<0 || Index>=mLines.count()) {
|
||||
ListIndexOutOfBounds(Index);
|
||||
}
|
||||
beginUpdate();
|
||||
mLines[Index]->fRange = ARange;
|
||||
mLines[Index]->fRange = range;
|
||||
endUpdate();
|
||||
}
|
||||
|
||||
|
@ -285,10 +297,10 @@ int Document::add(const QString &s)
|
|||
return Result;
|
||||
}
|
||||
|
||||
void Document::addStrings(const QStringList &Strings)
|
||||
void Document::addStrings(const QStringList &strings)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Strings.count() > 0) {
|
||||
if (strings.count() > 0) {
|
||||
mIndexOfLongestLine = -1;
|
||||
beginUpdate();
|
||||
auto action = finally([this]{
|
||||
|
@ -296,10 +308,10 @@ void Document::addStrings(const QStringList &Strings)
|
|||
});
|
||||
int FirstAdded = mLines.count();
|
||||
|
||||
for (const QString& s:Strings) {
|
||||
for (const QString& s:strings) {
|
||||
addItem(s);
|
||||
}
|
||||
emit inserted(FirstAdded,Strings.count());
|
||||
emit inserted(FirstAdded,strings.count());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,80 +336,80 @@ void Document::clear()
|
|||
internalClear();
|
||||
}
|
||||
|
||||
void Document::deleteLines(int Index, int NumLines)
|
||||
void Document::deleteLines(int index, int numLines)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (NumLines<=0)
|
||||
if (numLines<=0)
|
||||
return;
|
||||
if ((Index < 0) || (Index >= mLines.count())) {
|
||||
ListIndexOutOfBounds(Index);
|
||||
if ((index < 0) || (index >= mLines.count())) {
|
||||
ListIndexOutOfBounds(index);
|
||||
}
|
||||
beginUpdate();
|
||||
auto action = finally([this]{
|
||||
endUpdate();
|
||||
});
|
||||
if (mIndexOfLongestLine>=Index) {
|
||||
if (mIndexOfLongestLine <Index+NumLines) {
|
||||
if (mIndexOfLongestLine>=index) {
|
||||
if (mIndexOfLongestLine <index+numLines) {
|
||||
mIndexOfLongestLine = -1;
|
||||
} else {
|
||||
mIndexOfLongestLine -= NumLines;
|
||||
mIndexOfLongestLine -= numLines;
|
||||
}
|
||||
}
|
||||
int LinesAfter = mLines.count() - (Index + NumLines);
|
||||
int LinesAfter = mLines.count() - (index + numLines);
|
||||
if (LinesAfter < 0) {
|
||||
NumLines = mLines.count() - Index;
|
||||
numLines = mLines.count() - index;
|
||||
}
|
||||
mLines.remove(Index,NumLines);
|
||||
emit deleted(Index,NumLines);
|
||||
mLines.remove(index,numLines);
|
||||
emit deleted(index,numLines);
|
||||
}
|
||||
|
||||
void Document::exchange(int Index1, int Index2)
|
||||
void Document::exchange(int index1, int index2)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if ((Index1 < 0) || (Index1 >= mLines.count())) {
|
||||
ListIndexOutOfBounds(Index1);
|
||||
if ((index1 < 0) || (index1 >= mLines.count())) {
|
||||
ListIndexOutOfBounds(index1);
|
||||
}
|
||||
if ((Index2 < 0) || (Index2 >= mLines.count())) {
|
||||
ListIndexOutOfBounds(Index2);
|
||||
if ((index2 < 0) || (index2 >= mLines.count())) {
|
||||
ListIndexOutOfBounds(index2);
|
||||
}
|
||||
beginUpdate();
|
||||
PDocumentLine temp = mLines[Index1];
|
||||
mLines[Index1]=mLines[Index2];
|
||||
mLines[Index2]=temp;
|
||||
PDocumentLine temp = mLines[index1];
|
||||
mLines[index1]=mLines[index2];
|
||||
mLines[index2]=temp;
|
||||
//mList.swapItemsAt(Index1,Index2);
|
||||
if (mIndexOfLongestLine == Index1) {
|
||||
mIndexOfLongestLine = Index2;
|
||||
} else if (mIndexOfLongestLine == Index2) {
|
||||
mIndexOfLongestLine = Index1;
|
||||
if (mIndexOfLongestLine == index1) {
|
||||
mIndexOfLongestLine = index2;
|
||||
} else if (mIndexOfLongestLine == index2) {
|
||||
mIndexOfLongestLine = index1;
|
||||
}
|
||||
endUpdate();
|
||||
}
|
||||
|
||||
void Document::insert(int Index, const QString &s)
|
||||
void Document::insert(int index, const QString &s)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if ((Index < 0) || (Index > mLines.count())) {
|
||||
ListIndexOutOfBounds(Index);
|
||||
if ((index < 0) || (index > mLines.count())) {
|
||||
ListIndexOutOfBounds(index);
|
||||
}
|
||||
beginUpdate();
|
||||
insertItem(Index, s);
|
||||
emit inserted(Index,1);
|
||||
insertItem(index, s);
|
||||
emit inserted(index,1);
|
||||
endUpdate();
|
||||
}
|
||||
|
||||
void Document::deleteAt(int Index)
|
||||
void Document::deleteAt(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if ((Index < 0) || (Index >= mLines.count())) {
|
||||
ListIndexOutOfBounds(Index);
|
||||
if ((index < 0) || (index >= mLines.count())) {
|
||||
ListIndexOutOfBounds(index);
|
||||
}
|
||||
beginUpdate();
|
||||
if (mIndexOfLongestLine == Index)
|
||||
if (mIndexOfLongestLine == index)
|
||||
mIndexOfLongestLine = -1;
|
||||
else if (mIndexOfLongestLine>Index)
|
||||
else if (mIndexOfLongestLine>index)
|
||||
mIndexOfLongestLine -= 1;
|
||||
mLines.removeAt(Index);
|
||||
emit deleted(Index,1);
|
||||
mLines.removeAt(index);
|
||||
emit deleted(index,1);
|
||||
endUpdate();
|
||||
}
|
||||
|
||||
|
@ -415,26 +427,26 @@ QString Document::getTextStr() const
|
|||
return result;
|
||||
}
|
||||
|
||||
void Document::putString(int Index, const QString &s, bool notify) {
|
||||
void Document::putString(int index, const QString &s, bool notify) {
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index == mLines.count()) {
|
||||
if (index == mLines.count()) {
|
||||
add(s);
|
||||
} else {
|
||||
if (Index<0 || Index>=mLines.count()) {
|
||||
ListIndexOutOfBounds(Index);
|
||||
if (index<0 || index>=mLines.count()) {
|
||||
ListIndexOutOfBounds(index);
|
||||
}
|
||||
beginUpdate();
|
||||
int oldColumns = mLines[Index]->fColumns;
|
||||
mLines[Index]->fString = s;
|
||||
calculateLineColumns(Index);
|
||||
if (mIndexOfLongestLine == Index && oldColumns>mLines[Index]->fColumns )
|
||||
int oldColumns = mLines[index]->fColumns;
|
||||
mLines[index]->fString = s;
|
||||
calculateLineColumns(index);
|
||||
if (mIndexOfLongestLine == index && oldColumns>mLines[index]->fColumns )
|
||||
mIndexOfLongestLine = -1;
|
||||
else if (mIndexOfLongestLine>=0
|
||||
&& mIndexOfLongestLine<mLines.count()
|
||||
&& mLines[Index]->fColumns > mLines[mIndexOfLongestLine]->fColumns)
|
||||
mIndexOfLongestLine = Index;
|
||||
&& mLines[index]->fColumns > mLines[mIndexOfLongestLine]->fColumns)
|
||||
mIndexOfLongestLine = index;
|
||||
if (notify)
|
||||
emit putted(Index,1);
|
||||
emit putted(index,1);
|
||||
endUpdate();
|
||||
}
|
||||
}
|
||||
|
@ -455,13 +467,13 @@ int Document::calculateLineColumns(int Index)
|
|||
return line->fColumns;
|
||||
}
|
||||
|
||||
void Document::insertLines(int Index, int NumLines)
|
||||
void Document::insertLines(int index, int numLines)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index<0 || Index>mLines.count()) {
|
||||
ListIndexOutOfBounds(Index);
|
||||
if (index<0 || index>mLines.count()) {
|
||||
ListIndexOutOfBounds(index);
|
||||
}
|
||||
if (NumLines<=0)
|
||||
if (numLines<=0)
|
||||
return;
|
||||
beginUpdate();
|
||||
auto action = finally([this]{
|
||||
|
@ -469,12 +481,12 @@ void Document::insertLines(int Index, int NumLines)
|
|||
});
|
||||
mIndexOfLongestLine = -1;
|
||||
PDocumentLine line;
|
||||
mLines.insert(Index,NumLines,line);
|
||||
for (int i=Index;i<Index+NumLines;i++) {
|
||||
mLines.insert(index,numLines,line);
|
||||
for (int i=index;i<index+numLines;i++) {
|
||||
line = std::make_shared<DocumentLine>();
|
||||
mLines[i]=line;
|
||||
}
|
||||
emit inserted(Index,NumLines);
|
||||
emit inserted(index,numLines);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -55,38 +55,39 @@ class Document : public QObject
|
|||
public:
|
||||
explicit Document(const QFont& font, const QFont& nonAsciiFont, QObject* parent=nullptr);
|
||||
|
||||
int parenthesisLevels(int Index);
|
||||
int bracketLevels(int Index);
|
||||
int braceLevels(int Index);
|
||||
int lineColumns(int Index);
|
||||
int leftBraces(int Index);
|
||||
int rightBraces(int Index);
|
||||
int parenthesisLevels(int index);
|
||||
int bracketLevels(int index);
|
||||
int braceLevels(int index);
|
||||
int lineColumns(int index);
|
||||
int blockLevel(int index);
|
||||
int blockStarted(int index);
|
||||
int blockEnded(int index);
|
||||
int lengthOfLongestLine();
|
||||
QString lineBreak() const;
|
||||
HighlighterState ranges(int Index);
|
||||
void setRange(int Index, const HighlighterState& ARange);
|
||||
QString getString(int Index);
|
||||
HighlighterState ranges(int index);
|
||||
void setRange(int index, const HighlighterState& range);
|
||||
QString getString(int index);
|
||||
int count();
|
||||
QString text();
|
||||
void setText(const QString& text);
|
||||
void setContents(const QStringList& text);
|
||||
QStringList contents();
|
||||
|
||||
void putString(int Index, const QString& s, bool notify=true);
|
||||
void putString(int index, const QString& s, bool notify=true);
|
||||
|
||||
void beginUpdate();
|
||||
void endUpdate();
|
||||
|
||||
int add(const QString& s);
|
||||
void addStrings(const QStringList& Strings);
|
||||
void addStrings(const QStringList& strings);
|
||||
|
||||
int getTextLength();
|
||||
void clear();
|
||||
void deleteAt(int Index);
|
||||
void deleteLines(int Index, int NumLines);
|
||||
void exchange(int Index1, int Index2);
|
||||
void insert(int Index, const QString& s);
|
||||
void insertLines(int Index, int NumLines);
|
||||
void deleteAt(int index);
|
||||
void deleteLines(int index, int numLines);
|
||||
void exchange(int index1, int index2);
|
||||
void insert(int index, const QString& s);
|
||||
void insertLines(int index, int numLines);
|
||||
|
||||
void loadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding);
|
||||
void saveToFile(QFile& file, const QByteArray& encoding,
|
||||
|
|
|
@ -265,11 +265,15 @@ int HighlighterState::getLastIndent()
|
|||
|
||||
HighlighterState::HighlighterState():
|
||||
state(0),
|
||||
blockLevel(0),
|
||||
blockStarted(0),
|
||||
blockEnded(0),
|
||||
blockEndedLastLine(0),
|
||||
braceLevel(0),
|
||||
bracketLevel(0),
|
||||
parenthesisLevel(0),
|
||||
leftBraces(0),
|
||||
rightBraces(0),
|
||||
// leftBraces(0),
|
||||
// rightBraces(0),
|
||||
firstIndentThisLine(0)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -36,11 +36,15 @@ enum SynIndentType {
|
|||
|
||||
struct HighlighterState {
|
||||
int state; // current syntax parsing state
|
||||
int blockLevel; // needed by block folding
|
||||
int blockStarted; // needed by block folding
|
||||
int blockEnded; // needed by block folding;
|
||||
int blockEndedLastLine; //needed by block folding;
|
||||
int braceLevel; // current braces embedding level (needed by rainbow color)
|
||||
int bracketLevel; // current brackets embedding level (needed by rainbow color)
|
||||
int parenthesisLevel; // current parenthesis embedding level (needed by rainbow color)
|
||||
int leftBraces; // unpairing left braces in the current line ( needed by block folding)
|
||||
int rightBraces; // unparing right braces in the current line (needed by block folding)
|
||||
// int leftBraces; // unpairing left braces in the current line ( needed by block folding)
|
||||
// int rightBraces; // unparing right braces in the current line (needed by block folding)
|
||||
QVector<int> indents; // indents stack (needed by auto indent)
|
||||
int firstIndentThisLine; /* index of first indent that appended to the indents
|
||||
* stack at this line ( need by auto indent) */
|
||||
|
|
|
@ -372,12 +372,15 @@ void CppHighlighter::braceCloseProc()
|
|||
}
|
||||
|
||||
mRange.braceLevel -= 1;
|
||||
if (mRange.braceLevel<0)
|
||||
mRange.blockLevel -= 1;
|
||||
if (mRange.braceLevel<0) {
|
||||
mRange.braceLevel = 0;
|
||||
if (mRange.leftBraces>0) {
|
||||
mRange.leftBraces--;
|
||||
mRange.blockLevel = 0;
|
||||
}
|
||||
if (mRange.blockStarted>0) {
|
||||
mRange.blockStarted--;
|
||||
} else {
|
||||
mRange.rightBraces++ ;
|
||||
mRange.blockEnded++ ;
|
||||
}
|
||||
popIndents(sitBrace);
|
||||
}
|
||||
|
@ -391,7 +394,8 @@ void CppHighlighter::braceOpenProc()
|
|||
mAsmStart = true;
|
||||
}
|
||||
mRange.braceLevel += 1;
|
||||
mRange.leftBraces++;
|
||||
mRange.blockLevel += 1;
|
||||
mRange.blockStarted++;
|
||||
if (mRange.getLastIndent() == sitStatement) {
|
||||
// if last indent is started by 'if' 'for' etc
|
||||
// just replace it
|
||||
|
@ -1576,8 +1580,9 @@ void CppHighlighter::setLine(const QString &newLine, int lineNumber)
|
|||
mLineSize = mLine.size();
|
||||
mLineNumber = lineNumber;
|
||||
mRun = 0;
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
mRange.blockStarted = 0;
|
||||
mRange.blockEnded = 0;
|
||||
mRange.blockEndedLastLine = 0;
|
||||
mRange.firstIndentThisLine = mRange.indents.length();
|
||||
mRange.matchingIndents.clear();
|
||||
next();
|
||||
|
@ -1592,8 +1597,9 @@ void CppHighlighter::setState(const HighlighterState& rangeState)
|
|||
{
|
||||
mRange = rangeState;
|
||||
// current line's left / right parenthesis count should be reset before parsing each line
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
mRange.blockStarted = 0;
|
||||
mRange.blockEnded = 0;
|
||||
mRange.blockEndedLastLine = 0;
|
||||
mRange.firstIndentThisLine = mRange.indents.length();
|
||||
mRange.matchingIndents.clear();
|
||||
}
|
||||
|
@ -1604,8 +1610,10 @@ void CppHighlighter::resetState()
|
|||
mRange.braceLevel = 0;
|
||||
mRange.bracketLevel = 0;
|
||||
mRange.parenthesisLevel = 0;
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
mRange.blockLevel = 0;
|
||||
mRange.blockStarted = 0;
|
||||
mRange.blockEnded = 0;
|
||||
mRange.blockEndedLastLine = 0;
|
||||
mRange.indents.clear();
|
||||
mRange.firstIndentThisLine = 0;
|
||||
mRange.matchingIndents.clear();
|
||||
|
|
|
@ -12,8 +12,6 @@ void CustomHighlighterV1::resetState()
|
|||
mRange.braceLevel = 0;
|
||||
mRange.bracketLevel = 0;
|
||||
mRange.parenthesisLevel = 0;
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
mRange.indents.clear();
|
||||
mRange.firstIndentThisLine = 0;
|
||||
mRange.matchingIndents.clear();
|
||||
|
|
|
@ -312,12 +312,15 @@ void GLSLHighlighter::braceCloseProc()
|
|||
}
|
||||
|
||||
mRange.braceLevel -= 1;
|
||||
if (mRange.braceLevel<0)
|
||||
mRange.blockLevel -= 1;
|
||||
if (mRange.braceLevel<0) {
|
||||
mRange.braceLevel = 0;
|
||||
if (mRange.leftBraces>0) {
|
||||
mRange.leftBraces--;
|
||||
mRange.blockLevel = 0;
|
||||
}
|
||||
if (mRange.blockStarted>0) {
|
||||
mRange.blockStarted--;
|
||||
} else {
|
||||
mRange.rightBraces++ ;
|
||||
mRange.blockEnded++ ;
|
||||
}
|
||||
popIndents(sitBrace);
|
||||
}
|
||||
|
@ -331,7 +334,8 @@ void GLSLHighlighter::braceOpenProc()
|
|||
mAsmStart = true;
|
||||
}
|
||||
mRange.braceLevel += 1;
|
||||
mRange.leftBraces++;
|
||||
mRange.blockLevel += 1;
|
||||
mRange.blockStarted += 1;
|
||||
if (mRange.getLastIndent() == sitStatement) {
|
||||
// if last indent is started by 'if' 'for' etc
|
||||
// just replace it
|
||||
|
@ -1411,8 +1415,10 @@ void GLSLHighlighter::setLine(const QString &newLine, int lineNumber)
|
|||
mLine = mLineString.data();
|
||||
mLineNumber = lineNumber;
|
||||
mRun = 0;
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
mRange.blockLevel = 0;
|
||||
mRange.blockStarted = 0;
|
||||
mRange.blockEnded = 0;
|
||||
mRange.blockEndedLastLine = 0;
|
||||
mRange.firstIndentThisLine = mRange.indents.length();
|
||||
mRange.matchingIndents.clear();
|
||||
next();
|
||||
|
@ -1427,8 +1433,10 @@ void GLSLHighlighter::setState(const HighlighterState& rangeState)
|
|||
{
|
||||
mRange = rangeState;
|
||||
// current line's left / right parenthesis count should be reset before parsing each line
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
mRange.blockLevel = 0;
|
||||
mRange.blockStarted = 0;
|
||||
mRange.blockEnded = 0;
|
||||
mRange.blockEndedLastLine = 0;
|
||||
mRange.firstIndentThisLine = mRange.indents.length();
|
||||
mRange.matchingIndents.clear();
|
||||
}
|
||||
|
@ -1439,8 +1447,10 @@ void GLSLHighlighter::resetState()
|
|||
mRange.braceLevel = 0;
|
||||
mRange.bracketLevel = 0;
|
||||
mRange.parenthesisLevel = 0;
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
mRange.blockLevel = 0;
|
||||
mRange.blockStarted = 0;
|
||||
mRange.blockEnded = 0;
|
||||
mRange.blockEndedLastLine = 0;
|
||||
mRange.indents.clear();
|
||||
mRange.firstIndentThisLine = 0;
|
||||
mRange.matchingIndents.clear();
|
||||
|
|
Loading…
Reference in New Issue