- enhancement: prevent group undo when caret position changed

- fix: undo link break may lose leading spaces
  refactor undo
This commit is contained in:
Roy Qu 2022-07-04 10:01:40 +08:00
parent a86544d6ae
commit 2d7c2145e3
14 changed files with 996 additions and 1298 deletions

View File

@ -9,6 +9,8 @@ Red Panda C++ Version 1.1.4
- refactor of undo system
- fix: calculation of the code block ranges when inserting/deleting
- fix: undo chains
- enhancement: prevent group undo when caret position changed
- fix: undo link break may lose leading spaces
Red Panda C++ Version 1.1.3

View File

@ -45,7 +45,7 @@ bool CppRefacter::findOccurence(Editor *editor, const BufferCoord &pos)
PStatement statement = editor->parser()->findStatementOf(
editor->filename(),
expression,
pos.Line);
pos.line);
// definition of the symbol not found
if (!statement)
return false;
@ -117,7 +117,7 @@ void CppRefacter::renameSymbol(Editor *editor, const BufferCoord &pos, const QSt
QStringList expression;
QChar s=editor->charAt(pos);
if (!editor->isIdentChar(s)) {
expression = editor->getExpressionAtPosition(BufferCoord{pos.Char-1,pos.Line});
expression = editor->getExpressionAtPosition(BufferCoord{pos.ch-1,pos.line});
} else {
expression = editor->getExpressionAtPosition(pos);
}
@ -125,7 +125,7 @@ void CppRefacter::renameSymbol(Editor *editor, const BufferCoord &pos, const QSt
PStatement oldStatement = editor->parser()->findStatementOf(
editor->filename(),
expression,
pos.Line);
pos.line);
// definition of the symbol not found
if (!oldStatement)
return;
@ -144,7 +144,7 @@ void CppRefacter::renameSymbol(Editor *editor, const BufferCoord &pos, const QSt
PStatement newStatement = editor->parser()->findStatementOf(
editor->filename(),
newExpression,
pos.Line);
pos.line);
if (newStatement && fullParentName(newStatement) == oldScope) {
QMessageBox::critical(editor,
tr("Rename Symbol Error"),
@ -231,19 +231,19 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
if (token == statement->command) {
//same name symbol , test if the same statement;
BufferCoord p;
p.Line = posY+1;
p.Char = start+1;
p.line = posY+1;
p.ch = start+1;
QStringList expression = editor.getExpressionAtPosition(p);
PStatement tokenStatement = parser->findStatementOf(
filename,
expression, p.Line);
expression, p.line);
if (tokenStatement
&& (tokenStatement->line == statement->line)
&& (tokenStatement->fileName == statement->fileName)) {
PSearchResultTreeItem item = std::make_shared<SearchResultTreeItem>();
item->filename = filename;
item->line = p.Line;
item->line = p.line;
item->start = start;
item->len = token.length();
item->parent = parentItem.get();
@ -291,13 +291,13 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
if (token == statement->command) {
//same name symbol , test if the same statement;
BufferCoord p;
p.Line = posY+1;
p.Char = start;
p.line = posY+1;
p.ch = start;
QStringList expression = editor.getExpressionAtPosition(p);
PStatement tokenStatement = parser->findStatementOf(
filename,
expression, p.Line);
expression, p.line);
if (tokenStatement
&& (tokenStatement->line == statement->line)
&& (tokenStatement->fileName == statement->fileName)) {

View File

@ -595,7 +595,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
if (s=="*/") {
BufferCoord p = caretXY();
setBlockBegin(p);
p.Char = lineText().length()+1;
p.ch = lineText().length()+1;
setBlockEnd(p);
setSelText("");
}
@ -652,10 +652,10 @@ void Editor::keyPressEvent(QKeyEvent *event)
s=lineBreak()+"* ";
insertString(s,false);
BufferCoord p = caretXY();
p.Line++;
p.Char = document()->getString(p.Line-1).length()+1;
p.line++;
p.ch = document()->getString(p.line-1).length()+1;
if (right>0) {
p.Char -=right+1;
p.ch -=right+1;
}
setCaretXY(p);
}
@ -718,7 +718,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
if (t.isEmpty())
return;
if (activeSelectionMode()==SynSelectionMode::smColumn)
if (activeSelectionMode()==SynSelectionMode::Column)
return;
QChar ch = t[0];
@ -932,7 +932,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
if (cursor() == Qt::PointingHandCursor) {
BufferCoord p;
if (pointToCharLine(mapFromGlobal(QCursor::pos()),p)) {
if (line==p.Line){
if (line==p.line){
int pos1=std::max(lineText.indexOf("<"),lineText.indexOf("\""));
int pos2=std::max(lineText.lastIndexOf(">"),lineText.lastIndexOf("\""));
pos1++;
@ -954,15 +954,15 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
PStatement statement = parser()->findStatementOf(
filename(),
expression,
p.Line);
p.line);
StatementKind kind = getKindOfStatement(statement);
if (kind == StatementKind::skUnknown) {
BufferCoord pBeginPos,pEndPos;
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
if ((pEndPos.Line>=1)
&& (pEndPos.Char>=0)
&& (pEndPos.Char+1 < document()->getString(pEndPos.Line-1).length())
&& (document()->getString(pEndPos.Line-1)[pEndPos.Char+1] == '(')) {
if ((pEndPos.line>=1)
&& (pEndPos.ch>=0)
&& (pEndPos.ch+1 < document()->getString(pEndPos.line-1).length())
&& (document()->getString(pEndPos.line-1)[pEndPos.ch+1] == '(')) {
kind = StatementKind::skFunction;
} else {
kind = StatementKind::skVariable;
@ -983,7 +983,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
if (cursor() == Qt::PointingHandCursor) {
BufferCoord p;
if (pointToCharLine(mapFromGlobal(QCursor::pos()),p)) {
if (line==p.Line && (aChar<=p.Char && p.Char<aChar+token.length())) {
if (line==p.line && (aChar<=p.ch && p.ch<aChar+token.length())) {
style.setFlag(SynFontStyle::fsUnderline);
}
}
@ -1005,15 +1005,15 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
} else if (!selAvail() && attr->name() == SYNS_AttrSymbol
&& pSettings->editor().highlightMathingBraces()) {
// qDebug()<<line<<":"<<aChar<<" - "<<mHighlightCharPos1.Line<<":"<<mHighlightCharPos1.Char<<" - "<<mHighlightCharPos2.Line<<":"<<mHighlightCharPos2.Char;
if ( (line == mHighlightCharPos1.Line)
&& (aChar == mHighlightCharPos1.Char)) {
if ( (line == mHighlightCharPos1.line)
&& (aChar == mHighlightCharPos1.ch)) {
if (mCurrentHighlighWordForeground.isValid())
foreground = mCurrentHighlighWordForeground;
if (mCurrentHighlighWordBackground.isValid())
background = mCurrentHighlighWordBackground;
}
if ((line == mHighlightCharPos2.Line)
&& (aChar == mHighlightCharPos2.Char)) {
if ((line == mHighlightCharPos2.line)
&& (aChar == mHighlightCharPos2.ch)) {
if (mCurrentHighlighWordForeground.isValid())
foreground = mCurrentHighlighWordForeground;
if (mCurrentHighlighWordBackground.isValid())
@ -1067,7 +1067,7 @@ bool Editor::event(QEvent *event)
switch (reason) {
case TipType::Preprocessor:
// When hovering above a preprocessor line, determine if we want to show an include or a identifier hint
s = document()->getString(p.Line - 1);
s = document()->getString(p.line - 1);
isIncludeLine = mParser->isIncludeLine(s);
if (!isIncludeLine)
s = wordAtRowCol(p);
@ -1130,7 +1130,7 @@ bool Editor::event(QEvent *event)
!mCompletionPopup->isVisible()
&& !mHeaderCompletionPopup->isVisible()) {
if (pSettings->editor().enableIdentifierToolTips())
hint = getParserHint(QStringList(),s,p.Line);
hint = getParserHint(QStringList(),s,p.line);
}
break;
case TipType::Identifier:
@ -1139,9 +1139,9 @@ bool Editor::event(QEvent *event)
&& !mHeaderCompletionPopup->isVisible()) {
if (pMainWindow->debugger()->executing()
&& (pSettings->editor().enableDebugTooltips())) {
showDebugHint(s,p.Line);
showDebugHint(s,p.line);
} else if (pSettings->editor().enableIdentifierToolTips()) { //if devEditor.ParserHints {
hint = getParserHint(expression, s, p.Line);
hint = getParserHint(expression, s, p.line);
}
}
break;
@ -1209,7 +1209,7 @@ void Editor::mouseReleaseEvent(QMouseEvent *event)
BufferCoord p;
if (pointToCharLine(event->pos(),p)) {
QString s = document()->getString(p.Line - 1);
QString s = document()->getString(p.line - 1);
if (mParser->isIncludeLine(s)) {
QString filename = mParser->getHeaderFileName(mFilename,s);
Editor * e = pMainWindow->editorList()->getEditorByFilename(filename);
@ -1323,8 +1323,8 @@ void Editor::resizeEvent(QResizeEvent *event)
void Editor::copyToClipboard()
{
if (pSettings->editor().copySizeLimit()) {
int startLine = blockBegin().Line;
int endLine = blockEnd().Line;
int startLine = blockBegin().line;
int endLine = blockEnd().line;
if ((endLine-startLine+1) > pSettings->editor().copyLineLimits()) {
QMessageBox::critical(pMainWindow,tr("Error"),
tr("The text to be copied exceeds count limit!"));
@ -1348,8 +1348,8 @@ void Editor::copyToClipboard()
void Editor::cutToClipboard()
{
if (pSettings->editor().copySizeLimit()) {
int startLine = blockBegin().Line;
int endLine = blockEnd().Line;
int startLine = blockBegin().line;
int endLine = blockEnd().line;
if ((endLine-startLine+1) > pSettings->editor().copyLineLimits()) {
QMessageBox::critical(pMainWindow,tr("Error"),
tr("The text to be cut exceeds count limit!"));
@ -1428,8 +1428,8 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT
if ((line<1) || (line>document()->count()))
return;
pError = std::make_shared<SyntaxIssue>();
p.Char = startChar;
p.Line = line;
p.ch = startChar;
p.line = line;
if (startChar >= document()->getString(line-1).length()) {
start = 1;
token = document()->getString(line-1);
@ -1472,8 +1472,8 @@ void Editor::gotoNextSyntaxIssue()
if (iter==mSyntaxIssues.end())
return;
BufferCoord p;
p.Char = (*iter)->at(0)->startChar;
p.Line = iter.key();
p.ch = (*iter)->at(0)->startChar;
p.line = iter.key();
setCaretXY(p);
}
@ -1486,8 +1486,8 @@ void Editor::gotoPrevSyntaxIssue()
return;
iter--;
BufferCoord p;
p.Char = (*iter)->at(0)->startChar;
p.Line = iter.key();
p.ch = (*iter)->at(0)->startChar;
p.line = iter.key();
setCaretXY(p);
}
@ -1522,11 +1522,11 @@ Editor::PSyntaxIssueList Editor::getSyntaxIssuesAtLine(int line)
Editor::PSyntaxIssue Editor::getSyntaxIssueAtPosition(const BufferCoord &pos)
{
PSyntaxIssueList lst = getSyntaxIssuesAtLine(pos.Line);
PSyntaxIssueList lst = getSyntaxIssuesAtLine(pos.line);
if (!lst)
return PSyntaxIssue();
foreach (const PSyntaxIssue& issue, *lst) {
if (issue->startChar<=pos.Char && pos.Char<=issue->endChar)
if (issue->startChar<=pos.ch && pos.ch<=issue->endChar)
return issue;
}
return PSyntaxIssue();
@ -1590,8 +1590,8 @@ void Editor::onStatusChanged(SynStatusChanges changes)
}
}
} else if (!selAvail() && highlighter() && pSettings->editor().highlightMathingBraces()){
invalidateLine(mHighlightCharPos1.Line);
invalidateLine(mHighlightCharPos2.Line);
invalidateLine(mHighlightCharPos1.line);
invalidateLine(mHighlightCharPos2.line);
mHighlightCharPos1 = BufferCoord{0,0};
mHighlightCharPos2 = BufferCoord{0,0};
// Is there a bracket char before us?
@ -1599,26 +1599,26 @@ void Editor::onStatusChanged(SynStatusChanges changes)
int ch = caretX() - 2;
BufferCoord coord;
if (ch>=0 && ch<lineLength && isBraceChar(lineText()[ch]) ) {
coord.Char = ch+1;
coord.Line = caretY();
coord.ch = ch+1;
coord.line = caretY();
}
//or after us?
ch = caretX()-1;
if (ch>=0 && ch<lineLength && isBraceChar(lineText()[ch]) ) {
coord.Char = ch+1;
coord.Line = caretY();
coord.ch = ch+1;
coord.line = caretY();
}
PSynHighlighterAttribute attr;
QString token;
if (getHighlighterAttriAtRowCol(coord,token,attr)
&& attr == highlighter()->symbolAttribute()) {
BufferCoord complementCharPos = getMatchingBracketEx(coord);
if (!foldHidesLine(coord.Line)
&& !foldHidesLine(complementCharPos.Line)) {
if (!foldHidesLine(coord.line)
&& !foldHidesLine(complementCharPos.line)) {
mHighlightCharPos1 = coord;
mHighlightCharPos2 = complementCharPos;
invalidateLine(mHighlightCharPos1.Line);
invalidateLine(mHighlightCharPos2.Line);
invalidateLine(mHighlightCharPos1.line);
invalidateLine(mHighlightCharPos2.line);
}
}
@ -1812,8 +1812,8 @@ QStringList Editor::getExpressionAtPosition(
QStringList result;
if (!highlighter())
return result;
int line = pos.Line-1;
int ch = pos.Char-1;
int line = pos.line-1;
int ch = pos.ch-1;
int symbolMatchingLevel = 0;
LastSymbolType lastSymbolType=LastSymbolType::None;
PSynHighlighter highlighter;
@ -1842,7 +1842,7 @@ QStringList Editor::getExpressionAtPosition(
break;
}
PSynHighlighterAttribute attr = highlighter->getTokenAttribute();
if ( (line == pos.Line-1)
if ( (line == pos.line-1)
&& (start<=ch) && (ch<=endPos)) {
if (attr==highlighter->commentAttribute() || attr == highlighter->stringAttribute()) {
return result;
@ -2035,11 +2035,11 @@ QString Editor::getWordForCompletionSearch(const BufferCoord &pos,bool permitTil
QString result = "";
QString s;
s = document()->getString(pos.Line - 1);
s = document()->getString(pos.line - 1);
int len = s.length();
int wordBegin = pos.Char - 1 - 1; //BufferCoord::Char starts with 1
int wordEnd = pos.Char - 1 - 1;
int wordBegin = pos.ch - 1 - 1; //BufferCoord::Char starts with 1
int wordEnd = pos.ch - 1 - 1;
while ((wordBegin >= 0) && (wordBegin<len)) {
if (isIdentChar(s[wordBegin])) {
@ -2228,7 +2228,7 @@ bool Editor::handleParentheseSkip()
}
} else {
BufferCoord pos = getMatchingBracket();
if (pos.Line != 0) {
if (pos.line != 0) {
setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over
return true;
}
@ -2279,7 +2279,7 @@ bool Editor::handleBracketSkip()
}
} else {
BufferCoord pos = getMatchingBracket();
if (pos.Line != 0) {
if (pos.line != 0) {
setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over
return true;
}
@ -2368,7 +2368,7 @@ bool Editor::handleBraceSkip()
}
} else {
BufferCoord pos = getMatchingBracket();
if (pos.Line != 0) {
if (pos.line != 0) {
bool oldInsertMode = insertMode();
setInsertMode(false); //set mode to overwrite
commandProcessor(SynEditorCommand::ecChar,'}');
@ -2484,7 +2484,7 @@ bool Editor::handleGlobalIncludeSkip()
if (!s.startsWith("include")) //it's not #include
return false;
BufferCoord pos = getMatchingBracket();
if (pos.Line != 0) {
if (pos.line != 0) {
setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over
return true;
}
@ -2970,7 +2970,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete)
QString memberOperator;
QStringList memberExpression;
BufferCoord pos = caretXY();
pos.Char--;
pos.ch--;
QStringList ownerExpression = getOwnerExpressionAndMemberAtPositionForCompletion(
pos,
memberOperator,
@ -3128,7 +3128,7 @@ void Editor::completionInsert(bool appendFunc)
||
(statement->kind == StatementKind::skPreprocessor
&& !statement->args.isEmpty())) {
QChar nextCh = nextNonSpaceChar(caretY()-1,p.Char-1);
QChar nextCh = nextNonSpaceChar(caretY()-1,p.ch-1);
if (nextCh=='(') {
funcAddOn = "";
} else if (isIdentChar(nextCh) || nextCh == '"'
@ -3188,8 +3188,8 @@ void Editor::headerCompletionInsert()
// delete the part of the word that's already been typed ...
BufferCoord p = caretXY();
int posBegin = p.Char-1;
int posEnd = p.Char-1;
int posBegin = p.ch-1;
int posEnd = p.ch-1;
QString sLine = lineText();
while ((posBegin>0) &&
(isIdentChar(sLine[posBegin-1]) || (sLine[posBegin-1]=='.') || (sLine[posBegin-1]=='+')))
@ -3198,9 +3198,9 @@ void Editor::headerCompletionInsert()
while ((posEnd < sLine.length())
&& (isIdentChar(sLine[posEnd]) || (sLine[posEnd]=='.') || (sLine[posBegin-1]=='+')))
posEnd++;
p.Char = posBegin+1;
p.ch = posBegin+1;
setBlockBegin(p);
p.Char = posEnd+1;
p.ch = posEnd+1;
setBlockEnd(p);
setSelText(headerName);
@ -3379,7 +3379,7 @@ Editor::TipType Editor::getTipType(QPoint point, BufferCoord& pos)
// do not allow when dragging selection
if (isPointInSelection(pos))
return TipType::Selection;
} else if (mParser && mParser->isIncludeLine(document()->getString(pos.Line-1))) {
} else if (mParser && mParser->isIncludeLine(document()->getString(pos.line-1))) {
return TipType::Preprocessor;
}else if (attr == highlighter()->identifierAttribute())
return TipType::Identifier;
@ -3539,8 +3539,8 @@ void Editor::updateFunctionTip(bool showTip)
});
const int maxLines=10;
BufferCoord caretPos = caretXY();
int currentLine = caretPos.Line-1;
int currentChar = caretPos.Char-1;
int currentLine = caretPos.line-1;
int currentChar = caretPos.ch-1;
BufferCoord functionNamePos{-1,-1};
bool foundFunctionStart = false;
int parenthesisLevel = 0;
@ -3556,7 +3556,7 @@ void Editor::updateFunctionTip(bool showTip)
while (currentLine>=0) {
QString line = document()->getString(currentLine);
if (currentLine!=caretPos.Line-1)
if (currentLine!=caretPos.line-1)
currentChar = line.length();
QStringList tokens;
QList<int> positions;
@ -3578,15 +3578,15 @@ void Editor::updateFunctionTip(bool showTip)
if (foundFunctionStart) {
if (attr!=highlighter()->identifierAttribute())
return; // not a function
functionNamePos.Line = currentLine+1;
functionNamePos.Char = start+1;
functionNamePos.line = currentLine+1;
functionNamePos.ch = start+1;
break;
}
tokens.append(token);
positions.append(start);
} else if (attr == highlighter()->commentAttribute()
&& currentLine == caretPos.Line-1 && start<caretPos.Char
&& start+token.length()>=caretPos.Char) {
&& currentLine == caretPos.line-1 && start<caretPos.ch
&& start+token.length()>=caretPos.ch) {
return; // in comment, do nothing
}
highlighter()->next();
@ -3616,8 +3616,8 @@ void Editor::updateFunctionTip(bool showTip)
// found start of function
foundFunctionStart = true;
if (i>0) {
functionNamePos.Line = currentLine+1;
functionNamePos.Char = positions[i-1]+1;
functionNamePos.line = currentLine+1;
functionNamePos.ch = positions[i-1]+1;
}
break;
} else if (tokens[i]=="[") {
@ -3641,13 +3641,13 @@ void Editor::updateFunctionTip(bool showTip)
}
}
}
if (functionNamePos.Char>=0)
if (functionNamePos.ch>=0)
break;
currentLine--;
if (caretPos.Line-currentLine>maxLines)
if (caretPos.line-currentLine>maxLines)
break;
}
isFunction = functionNamePos.Char>=0;
isFunction = functionNamePos.ch>=0;
currentParamPos = paramsCount-1;
if (!isFunction)
return;
@ -3655,8 +3655,8 @@ void Editor::updateFunctionTip(bool showTip)
QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation);
int x = pWordBegin.Char-1-1;
QString line = document()->getString(pWordBegin.Line-1);
int x = pWordBegin.ch-1-1;
QString line = document()->getString(pWordBegin.line-1);
bool hasPreviousWord=false;
while (x>=0) {
QChar ch=line[x];
@ -3674,13 +3674,13 @@ void Editor::updateFunctionTip(bool showTip)
if (x >= 0 && hasPreviousWord) {
BufferCoord pos = pWordBegin;
pos.Char = x+1;
pos.ch = x+1;
QString previousWord = getPreviousWordAtPositionForSuggestion(pos);
PStatement statement = mParser->findStatementOf(
mFilename,
previousWord,
pos.Line);
pos.line);
if (statement) {
PStatement typeStatement = mParser->findTypeDef(statement,mFilename);
if (typeStatement && typeStatement->kind == StatementKind::skClass) {
@ -3703,7 +3703,7 @@ void Editor::updateFunctionTip(bool showTip)
pMainWindow->functionTip()->clearTips();
QList<PStatement> statements=mParser->getListOfFunctions(mFilename,
s,
functionNamePos.Line);
functionNamePos.line);
foreach (const PStatement statement, statements) {
pMainWindow->functionTip()->addTip(
@ -3762,11 +3762,11 @@ void Editor::popUserCodeInTabStops()
tabStopEnd = n+p->endX+1;
}
mTabStopY = caretY() + p->y;
newCursorPos.Line = mTabStopY;
newCursorPos.Char = tabStopBegin;
newCursorPos.line = mTabStopY;
newCursorPos.ch = tabStopBegin;
setCaretXY(newCursorPos);
setBlockBegin(newCursorPos);
newCursorPos.Char = tabStopEnd;
newCursorPos.ch = tabStopEnd;
setBlockEnd(newCursorPos);
mTabStopBegin = tabStopBegin;
@ -3794,13 +3794,13 @@ void Editor::onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line,
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
// qDebug()<<s;
PStatement statement = mParser->findStatementOf(mFilename,
s , p.Line);
s , p.line);
StatementKind kind = getKindOfStatement(statement);
if (kind == StatementKind::skUnknown) {
if ((pEndPos.Line>=1)
&& (pEndPos.Char>=0)
&& (pEndPos.Char < document()->getString(pEndPos.Line-1).length())
&& (document()->getString(pEndPos.Line-1)[pEndPos.Char] == '(')) {
if ((pEndPos.line>=1)
&& (pEndPos.ch>=0)
&& (pEndPos.ch < document()->getString(pEndPos.line-1).length())
&& (document()->getString(pEndPos.line-1)[pEndPos.ch] == '(')) {
kind = StatementKind::skFunction;
} else {
kind = StatementKind::skVariable;
@ -3926,7 +3926,7 @@ void Editor::gotoDeclaration(const BufferCoord &pos)
PStatement statement = parser()->findStatementOf(
filename(),
expression,
pos.Line);
pos.line);
// QString phrase = getWordAtPosition(this,pos,pBeginPos,pEndPos, WordPurpose::wpInformation);
// if (phrase.isEmpty())
// return;
@ -3940,7 +3940,7 @@ void Editor::gotoDeclaration(const BufferCoord &pos)
}
QString filename;
int line;
if (statement->fileName == mFilename && statement->line == pos.Line) {
if (statement->fileName == mFilename && statement->line == pos.line) {
filename = statement->definitionFileName;
line = statement->definitionLine;
} else {
@ -3961,7 +3961,7 @@ void Editor::gotoDefinition(const BufferCoord &pos)
PStatement statement = parser()->findStatementOf(
filename(),
expression,
pos.Line);
pos.line);
if (!statement) {
// pMainWindow->updateStatusbarMessage(tr("Symbol '%1' not found!").arg(phrase));
@ -3969,7 +3969,7 @@ void Editor::gotoDefinition(const BufferCoord &pos)
}
QString filename;
int line;
if (statement->definitionFileName == mFilename && statement->definitionLine == pos.Line) {
if (statement->definitionFileName == mFilename && statement->definitionLine == pos.line) {
filename = statement->fileName;
line = statement->line;
} else {
@ -3986,17 +3986,17 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW
{
QString result = "";
QString s;
if ((p.Line<1) || (p.Line>editor->document()->count())) {
if ((p.line<1) || (p.line>editor->document()->count())) {
pWordBegin = p;
pWordEnd = p;
return "";
}
s = editor->document()->getString(p.Line - 1);
s = editor->document()->getString(p.line - 1);
int len = s.length();
int wordBegin = p.Char - 1 - 1; //BufferCoord::Char starts with 1
int wordEnd = p.Char - 1 - 1;
int wordBegin = p.ch - 1 - 1; //BufferCoord::Char starts with 1
int wordEnd = p.ch - 1 - 1;
// Copy forward until end of word
if (purpose == Editor::WordPurpose::wpEvaluation
@ -4121,10 +4121,10 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW
// Get end result
result = s.mid(wordBegin+1, wordEnd - wordBegin);
pWordBegin.Line = p.Line;
pWordBegin.Char = wordBegin+1;
pWordEnd.Line = p.Line;
pWordEnd.Char = wordEnd;
pWordBegin.line = p.line;
pWordBegin.ch = wordBegin+1;
pWordEnd.line = p.line;
pWordEnd.ch = wordEnd;
// last line still have part of word
if (!result.isEmpty()
@ -4135,7 +4135,7 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW
|| purpose == Editor::WordPurpose::wpEvaluation
|| purpose == Editor::WordPurpose::wpInformation)) {
int i = wordBegin;
int line=p.Line;
int line=p.line;
while (line>=1) {
while (i>=0) {
if (s[i] == ' '
@ -4155,8 +4155,8 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW
} else {
BufferCoord highlightPos;
BufferCoord pDummy;
highlightPos.Line = line;
highlightPos.Char = i+1;
highlightPos.line = line;
highlightPos.ch = i+1;
result = getWordAtPosition(editor, highlightPos,pWordBegin,pDummy,purpose)+result;
break;
}
@ -4197,14 +4197,14 @@ QString getWordAtPosition(SynEdit *editor, const BufferCoord &p, BufferCoord &pW
QString Editor::getPreviousWordAtPositionForSuggestion(const BufferCoord &p)
{
QString result;
if ((p.Line<1) || (p.Line>document()->count())) {
if ((p.line<1) || (p.line>document()->count())) {
return "";
}
bool inFunc = testInFunc(p.Char-1,p.Line-1);
bool inFunc = testInFunc(p.ch-1,p.line-1);
QString s = document()->getString(p.Line - 1);
QString s = document()->getString(p.line - 1);
int wordBegin;
int wordEnd = p.Char-1;
int wordEnd = p.ch-1;
if (wordEnd >= s.length())
wordEnd = s.length()-1;
while (true) {

View File

@ -2203,8 +2203,8 @@ void MainWindow::loadLastOpens()
if (!editor)
continue;
BufferCoord pos;
pos.Char = lastOpenIni.GetLongValue(sectionName,"CursorCol", 1);
pos.Line = lastOpenIni.GetLongValue(sectionName,"CursorRow", 1);
pos.ch = lastOpenIni.GetLongValue(sectionName,"CursorCol", 1);
pos.line = lastOpenIni.GetLongValue(sectionName,"CursorRow", 1);
editor->setCaretXY(pos);
editor->setTopLine(
lastOpenIni.GetLongValue(sectionName,"TopLine", 1)
@ -4002,7 +4002,7 @@ void MainWindow::onEditorContextMenu(const QPoint& pos)
mEditorContextMenuPos = pos;
int line;
if (editor->getPositionOfMouse(p)) {
line=p.Line;
line=p.line;
//mouse on editing area
menu.addAction(ui->actionCompile_Run);
menu.addAction(ui->actionDebug);
@ -6466,16 +6466,16 @@ void MainWindow::on_actionRename_Symbol_triggered()
}
}
QStringList expression = editor->getExpressionAtPosition(oldCaretXY);
if (expression.isEmpty() && oldCaretXY.Char>1) {
if (expression.isEmpty() && oldCaretXY.ch>1) {
BufferCoord coord=oldCaretXY;
coord.Char--;
coord.ch--;
expression = editor->getExpressionAtPosition(coord);
}
// Find it's definition
PStatement oldStatement = editor->parser()->findStatementOf(
editor->filename(),
expression,
oldCaretXY.Line);
oldCaretXY.line);
// definition of the symbol not found
if (!oldStatement)
return;

View File

@ -621,16 +621,16 @@ int CountLines(const QString &Line, int start)
void ensureNotAfter(BufferCoord &cord1, BufferCoord &cord2)
{
if((cord1.Line > cord2.Line) || (
cord1.Line == cord2.Line &&
cord1.Char > cord2.Char)) {
if((cord1.line > cord2.line) || (
cord1.line == cord2.line &&
cord1.ch > cord2.ch)) {
std::swap(cord1,cord2);
}
}
BufferCoord minBufferCoord(const BufferCoord &P1, const BufferCoord &P2)
{
if ( (P2.Line < P1.Line) || ( (P2.Line == P1.Line) && (P2.Char < P1.Char)) ) {
if ( (P2.line < P1.line) || ( (P2.line == P1.line) && (P2.ch < P1.ch)) ) {
return P2;
} else {
return P1;
@ -639,7 +639,7 @@ BufferCoord minBufferCoord(const BufferCoord &P1, const BufferCoord &P2)
BufferCoord maxBufferCoord(const BufferCoord &P1, const BufferCoord &P2)
{
if ( (P2.Line > P1.Line) || ( (P2.Line == P1.Line) && (P2.Char > P1.Char)) ) {
if ( (P2.line > P1.line) || ( (P2.line == P1.line) && (P2.ch > P1.ch)) ) {
return P2;
} else {
return P1;
@ -672,5 +672,5 @@ QStringList splitStrings(const QString &text)
int calSpanLines(const BufferCoord &startPos, const BufferCoord &endPos)
{
return std::abs(endPos.Line - startPos.Line+1);
return std::abs(endPos.line - startPos.line+1);
}

File diff suppressed because it is too large Load Diff

View File

@ -184,8 +184,8 @@ public:
BufferCoord displayToBufferPos(const DisplayCoord& p) const;
//normalized buffer coord operations
ContentsCoord fromBufferCoord(const BufferCoord& p) const;
ContentsCoord createNormalizedBufferCoord(int aChar,int aLine) const;
// 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);
@ -272,7 +272,7 @@ public:
void addLeftTopToUndo();
void addSelectionToUndo();
void replaceAll(const QString& text) {
mUndoList->AddChange(SynChangeReason::crSelection,mBlockBegin,mBlockEnd,QStringList(), activeSelectionMode());
mUndoList->addChange(SynChangeReason::Selection,mBlockBegin,mBlockEnd,QStringList(), activeSelectionMode());
selectAll();
setSelText(text);
}

View File

@ -846,7 +846,7 @@ SynEditUndoList::SynEditUndoList():QObject()
mInitialChangeNumber = 0;
}
void SynEditUndoList::AddChange(SynChangeReason AReason, const BufferCoord &AStart,
void SynEditUndoList::addChange(SynChangeReason AReason, const BufferCoord &AStart,
const BufferCoord &AEnd, const QStringList& ChangeText,
SynSelectionMode SelMode)
{
@ -867,31 +867,32 @@ void SynEditUndoList::AddChange(SynChangeReason AReason, const BufferCoord &ASta
PSynEditUndoItem NewItem = std::make_shared<SynEditUndoItem>(AReason,
SelMode,AStart,AEnd,ChangeText,
changeNumber);
PushItem(NewItem);
pushItem(NewItem);
}
void SynEditUndoList::AddGroupBreak()
void SynEditUndoList::addGroupBreak()
{
//Add the GroupBreak even if ItemCount = 0. Since items are stored in
//reverse order in TCustomSynEdit.fRedoList, a GroupBreak could be lost.
if (LastChangeReason() != SynChangeReason::crGroupBreak) {
AddChange(SynChangeReason::crGroupBreak, {0,0}, {0,0}, QStringList(), SynSelectionMode::smNormal);
if (!canUndo())
return;
if (lastChangeReason() != SynChangeReason::GroupBreak) {
addChange(SynChangeReason::GroupBreak, {0,0}, {0,0}, QStringList(), SynSelectionMode::Normal);
}
}
void SynEditUndoList::BeginBlock()
void SynEditUndoList::beginBlock()
{
mBlockCount++;
mBlockChangeNumber = mNextChangeNumber;
}
void SynEditUndoList::Clear()
void SynEditUndoList::clear()
{
mItems.clear();
mFullUndoImposible = false;
}
void SynEditUndoList::DeleteItem(int index)
void SynEditUndoList::deleteItem(int index)
{
if (index <0 || index>=mItems.count()) {
ListIndexOutOfBounds(index);
@ -899,7 +900,7 @@ void SynEditUndoList::DeleteItem(int index)
mItems.removeAt(index);
}
void SynEditUndoList::EndBlock()
void SynEditUndoList::endBlock()
{
if (mBlockCount > 0) {
mBlockCount--;
@ -909,16 +910,16 @@ void SynEditUndoList::EndBlock()
mNextChangeNumber++;
if (mNextChangeNumber == 0)
mNextChangeNumber++;
if (mItems.count() > 0 && PeekItem()->changeNumber() == iBlockID)
if (mItems.count() > 0 && peekItem()->changeNumber() == iBlockID)
emit addedUndo();
}
}
}
SynChangeReason SynEditUndoList::LastChangeReason()
SynChangeReason SynEditUndoList::lastChangeReason()
{
if (mItems.count() == 0)
return SynChangeReason::crNothing;
return SynChangeReason::Nothing;
else
return mItems.last()->changeReason();
}
@ -928,12 +929,12 @@ bool SynEditUndoList::isEmpty()
return mItems.count()==0;
}
void SynEditUndoList::Lock()
void SynEditUndoList::lock()
{
mLockCount++;
}
PSynEditUndoItem SynEditUndoList::PeekItem()
PSynEditUndoItem SynEditUndoList::peekItem()
{
if (mItems.count() == 0)
return PSynEditUndoItem();
@ -941,7 +942,7 @@ PSynEditUndoItem SynEditUndoList::PeekItem()
return mItems.last();
}
PSynEditUndoItem SynEditUndoList::PopItem()
PSynEditUndoItem SynEditUndoList::popItem()
{
if (mItems.count() == 0)
return PSynEditUndoItem();
@ -952,28 +953,28 @@ PSynEditUndoItem SynEditUndoList::PopItem()
}
}
void SynEditUndoList::PushItem(PSynEditUndoItem Item)
void SynEditUndoList::pushItem(PSynEditUndoItem Item)
{
if (!Item)
return;
mItems.append(Item);
ensureMaxEntries();
if (Item->changeReason()!= SynChangeReason::crGroupBreak)
if (Item->changeReason()!= SynChangeReason::GroupBreak)
emit addedUndo();
}
void SynEditUndoList::Unlock()
void SynEditUndoList::unlock()
{
if (mLockCount > 0)
mLockCount--;
}
bool SynEditUndoList::CanUndo()
bool SynEditUndoList::canUndo()
{
return mItems.count()>0;
}
int SynEditUndoList::ItemCount()
int SynEditUndoList::itemCount()
{
return mItems.count();
}
@ -993,10 +994,10 @@ void SynEditUndoList::setMaxUndoActions(int maxUndoActions)
bool SynEditUndoList::initialState()
{
if (ItemCount() == 0) {
if (itemCount() == 0) {
return mInitialChangeNumber == 0;
} else {
return PeekItem()->changeNumber() == mInitialChangeNumber;
return peekItem()->changeNumber() == mInitialChangeNumber;
}
}
@ -1011,15 +1012,15 @@ PSynEditUndoItem SynEditUndoList::item(int index)
void SynEditUndoList::setInitialState(const bool Value)
{
if (Value) {
if (ItemCount() == 0)
if (itemCount() == 0)
mInitialChangeNumber = 0;
else
mInitialChangeNumber = PeekItem()->changeNumber();
} else if (ItemCount() == 0) {
mInitialChangeNumber = peekItem()->changeNumber();
} else if (itemCount() == 0) {
if (mInitialChangeNumber == 0) {
mInitialChangeNumber = -1;
}
} else if (PeekItem()->changeNumber() == mInitialChangeNumber) {
} else if (peekItem()->changeNumber() == mInitialChangeNumber) {
mInitialChangeNumber = -1;
}
}

View File

@ -161,16 +161,16 @@ private:
};
enum class SynChangeReason {
crInsert,
crDelete,
crCaret, //just restore the Caret, allowing better Undo behavior
crSelection, //restore Selection
crGroupBreak,
crLeftTop,
crLineBreak,
crMoveSelectionUp,
crMoveSelectionDown,
crNothing
Insert,
Delete,
Caret, //just restore the Caret, allowing better Undo behavior
Selection, //restore Selection
GroupBreak,
LeftTop,
LineBreak,
MoveSelectionUp,
MoveSelectionDown,
Nothing // undo list empty
};
class SynEditUndoItem {
private:
@ -202,24 +202,24 @@ class SynEditUndoList : public QObject {
public:
explicit SynEditUndoList();
void AddChange(SynChangeReason AReason, const BufferCoord& AStart, const BufferCoord& AEnd,
void addChange(SynChangeReason AReason, const BufferCoord& AStart, const BufferCoord& AEnd,
const QStringList& ChangeText, SynSelectionMode SelMode);
void AddGroupBreak();
void BeginBlock();
void Clear();
void DeleteItem(int index);
void EndBlock();
SynChangeReason LastChangeReason();
void addGroupBreak();
void beginBlock();
void clear();
void deleteItem(int index);
void endBlock();
SynChangeReason lastChangeReason();
bool isEmpty();
void Lock();
PSynEditUndoItem PeekItem();
PSynEditUndoItem PopItem();
void PushItem(PSynEditUndoItem Item);
void Unlock();
void lock();
PSynEditUndoItem peekItem();
PSynEditUndoItem popItem();
void pushItem(PSynEditUndoItem Item);
void unlock();
bool CanUndo();
int ItemCount();
bool canUndo();
int itemCount();
int maxUndoActions() const;
void setMaxUndoActions(int maxUndoActions);

View File

@ -133,7 +133,7 @@ void SynEditTextPainter::paintGutter(const QRect& clip)
if (edit->mGutter.activeLineTextColor().isValid()) {
if (
(edit->mCaretY==vLine) ||
(edit->mActiveSelectionMode == SynSelectionMode::smColumn && vLine >= selectionStart.Line && vLine <= selectionEnd.Line)
(edit->mActiveSelectionMode == SynSelectionMode::Column && vLine >= selectionStart.line && vLine <= selectionEnd.line)
)
painter->setPen(edit->mGutter.activeLineTextColor());
else
@ -253,59 +253,59 @@ void SynEditTextPainter::ComputeSelectionInfo()
if (!edit->mHideSelection || edit->hasFocus()) {
bAnySelection = true;
// Get the *real* start of the selected area.
if (edit->mBlockBegin.Line < edit->mBlockEnd.Line) {
if (edit->mBlockBegin.line < edit->mBlockEnd.line) {
vStart = edit->mBlockBegin;
vEnd = edit->mBlockEnd;
} else if (edit->mBlockBegin.Line > edit->mBlockEnd.Line) {
} else if (edit->mBlockBegin.line > edit->mBlockEnd.line) {
vEnd = edit->mBlockBegin;
vStart = edit->mBlockEnd;
} else if (edit->mBlockBegin.Char != edit->mBlockEnd.Char) {
} else if (edit->mBlockBegin.ch != edit->mBlockEnd.ch) {
// it is only on this line.
vStart.Line = edit->mBlockBegin.Line;
vEnd.Line = vStart.Line;
if (edit->mBlockBegin.Char < edit->mBlockEnd.Char) {
vStart.Char = edit->mBlockBegin.Char;
vEnd.Char = edit->mBlockEnd.Char;
vStart.line = edit->mBlockBegin.line;
vEnd.line = vStart.line;
if (edit->mBlockBegin.ch < edit->mBlockEnd.ch) {
vStart.ch = edit->mBlockBegin.ch;
vEnd.ch = edit->mBlockEnd.ch;
} else {
vStart.Char = edit->mBlockEnd.Char;
vEnd.Char = edit->mBlockBegin.Char;
vStart.ch = edit->mBlockEnd.ch;
vEnd.ch = edit->mBlockBegin.ch;
}
} else
bAnySelection = false;
if (edit->mInputPreeditString.length()>0) {
if (vStart.Line == edit->mCaretY && vStart.Char >=edit->mCaretX) {
vStart.Char+=edit->mInputPreeditString.length();
if (vStart.line == edit->mCaretY && vStart.ch >=edit->mCaretX) {
vStart.ch+=edit->mInputPreeditString.length();
}
if (vEnd.Line == edit->mCaretY && vEnd.Char >edit->mCaretX) {
vEnd.Char+=edit->mInputPreeditString.length();
if (vEnd.line == edit->mCaretY && vEnd.ch >edit->mCaretX) {
vEnd.ch+=edit->mInputPreeditString.length();
}
}
// If there is any visible selection so far, then test if there is an
// intersection with the area to be painted.
if (bAnySelection) {
// Don't care if the selection is not visible.
bAnySelection = (vEnd.Line >= vFirstLine) && (vStart.Line <= vLastLine);
bAnySelection = (vEnd.line >= vFirstLine) && (vStart.line <= vLastLine);
if (bAnySelection) {
// Transform the selection from text space into screen space
vSelStart = edit->bufferToDisplayPos(vStart);
vSelEnd = edit->bufferToDisplayPos(vEnd);
if (edit->mInputPreeditString.length()
&& vStart.Line == edit->mCaretY) {
&& vStart.line == edit->mCaretY) {
QString sLine = edit->lineText().left(edit->mCaretX-1)
+ edit->mInputPreeditString
+ edit->lineText().mid(edit->mCaretX-1);
vSelStart.Column = edit->charToColumn(sLine,vStart.Char);
vSelStart.Column = edit->charToColumn(sLine,vStart.ch);
}
if (edit->mInputPreeditString.length()
&& vEnd.Line == edit->mCaretY) {
&& vEnd.line == edit->mCaretY) {
QString sLine = edit->lineText().left(edit->mCaretX-1)
+ edit->mInputPreeditString
+ edit->lineText().mid(edit->mCaretX-1);
vSelEnd.Column = edit->charToColumn(sLine,vEnd.Char);
vSelEnd.Column = edit->charToColumn(sLine,vEnd.ch);
}
// In the column selection mode sort the begin and end of the selection,
// this makes the painting code simpler.
if (edit->mActiveSelectionMode == SynSelectionMode::smColumn && vSelStart.Column > vSelEnd.Column)
if (edit->mActiveSelectionMode == SynSelectionMode::Column && vSelStart.Column > vSelEnd.Column)
std::swap(vSelStart.Column, vSelEnd.Column);
}
}
@ -821,8 +821,8 @@ void SynEditTextPainter::PaintLines()
// Get the line.
sLine = edit->mDocument->getString(vLine - 1);
// determine whether will be painted with ActiveLineColor
if (edit->mActiveSelectionMode == SynSelectionMode::smColumn) {
bCurrentLine = (vLine >= selectionBegin.Line && vLine <= selectionEnd.Line);
if (edit->mActiveSelectionMode == SynSelectionMode::Column) {
bCurrentLine = (vLine >= selectionBegin.line && vLine <= selectionEnd.line);
} else {
bCurrentLine = (edit->mCaretY == vLine);
}
@ -859,8 +859,8 @@ void SynEditTextPainter::PaintLines()
// selection mode and a good start for the smNormal mode.
nLineSelStart = FirstCol;
nLineSelEnd = LastCol + 1;
if ((edit->mActiveSelectionMode == SynSelectionMode::smColumn) ||
((edit->mActiveSelectionMode == SynSelectionMode::smNormal) && (cRow == vSelStart.Row)) ) {
if ((edit->mActiveSelectionMode == SynSelectionMode::Column) ||
((edit->mActiveSelectionMode == SynSelectionMode::Normal) && (cRow == vSelStart.Row)) ) {
int ch = edit->columnToChar(vLine,vSelStart.Column);
ch = edit->charToColumn(vLine,ch);
if (ch > LastCol) {
@ -871,8 +871,8 @@ void SynEditTextPainter::PaintLines()
bComplexLine = true;
}
}
if ( (edit->mActiveSelectionMode == SynSelectionMode::smColumn) ||
((edit->mActiveSelectionMode == SynSelectionMode::smNormal) && (cRow == vSelEnd.Row)) ) {
if ( (edit->mActiveSelectionMode == SynSelectionMode::Column) ||
((edit->mActiveSelectionMode == SynSelectionMode::Normal) && (cRow == vSelEnd.Row)) ) {
int ch = edit->columnToChar(vLine,vSelEnd.Column);
int col = edit->charToColumn(vLine,ch);
if (col<vSelEnd.Column)

View File

@ -17,270 +17,37 @@
#include "Types.h"
#include "SynEdit.h"
#include <QDebug>
ContentsCoord::ContentsCoord(const SynEdit *edit, int ch, int line)
{
Q_ASSERT(edit!=nullptr);
mEdit = edit;
mChar = ch;
mLine = line;
normalize();
}
void ContentsCoord::normalize()
{
if (mEdit->document()->count()==0) {
mChar = 0;
mLine = 0;
return;
}
int aLine = mLine;
int aChar = mChar;
int line = aLine-1;
int lineCount = mEdit->document()->count();
if (line>=lineCount) {
mChar = mEdit->document()->getString(lineCount-1).length()+1;
mLine = lineCount;
return;
}
if (line<0) {
mChar = 0;
mLine = 0;
return;
}
if (aChar<1) {
while (true) {
line--;
if (line < 0) {
mChar = 0;
mLine = 0;
return;
}
QString s = mEdit->document()->getString(line);
int len = s.length();
aChar+=len+1;
if (aChar>=1) {
break;
}
}
} else {
while (true) {
QString s =mEdit->document()->getString(line);
int len = s.length();
if (aChar<=len+1) {
break;
}
if (line == lineCount-1) {
mChar = 1;
mLine = lineCount+1;
return;
}
aChar -= len+1;
line++;
}
}
mChar = aChar;
mLine = line+1;
return;
}
int ContentsCoord::line() const
{
return mLine;
}
void ContentsCoord::setLine(int newLine)
{
mLine = newLine;
}
bool ContentsCoord::atStart()
{
return mLine<1;
}
bool ContentsCoord::atEnd()
{
Q_ASSERT(mEdit!=nullptr);
return mLine>mEdit->document()->count();
}
const SynEdit *ContentsCoord::edit() const
{
return mEdit;
}
const ContentsCoord &ContentsCoord::operator=(const ContentsCoord &coord)
{
mEdit = coord.mEdit;
mChar = coord.mChar;
mLine = coord.mLine;
return *this;
}
const ContentsCoord &ContentsCoord::operator=(const ContentsCoord &&coord)
{
if (this!=&coord) {
mEdit = coord.mEdit;
mChar = coord.mChar;
mLine = coord.mLine;
}
return *this;
}
bool ContentsCoord::operator==(const ContentsCoord &coord) const
{
Q_ASSERT(mEdit == coord.mEdit);
return (mLine == coord.mLine)
&& (mChar == coord.mChar);
}
bool ContentsCoord::operator<(const ContentsCoord &coord) const
{
Q_ASSERT(mEdit == coord.mEdit);
return (mLine < coord.mLine) || (mLine == coord.mLine && mChar < coord.mChar);
}
bool ContentsCoord::operator<=(const ContentsCoord &coord) const
{
Q_ASSERT(mEdit == coord.mEdit);
return (mLine < coord.mLine) || (mLine == coord.mLine && mChar <= coord.mChar);
}
bool ContentsCoord::operator>(const ContentsCoord &coord) const
{
Q_ASSERT(mEdit == coord.mEdit);
return (mLine > coord.mLine) || (mLine == coord.mLine && mChar > coord.mChar);
}
bool ContentsCoord::operator>=(const ContentsCoord &coord) const
{
Q_ASSERT(mEdit == coord.mEdit);
return (mLine > coord.mLine) || (mLine == coord.mLine && mChar >= coord.mChar);
}
size_t ContentsCoord::operator-(const ContentsCoord& coord) const
{
Q_ASSERT(mEdit == coord.mEdit);
if (mLine == coord.mLine) {
return mChar - coord.mChar;
} else if (mLine > coord.mLine) {
size_t result = mEdit->document()->getString(coord.mLine-1).length()+1-coord.mChar;
int line = coord.mLine+1;
while (line<=mLine-1) {
result += mEdit->document()->getString(line-1).length()+1;
line++;
}
if (mLine<=mEdit->document()->count()) {
result += mChar;
}
return result;
} else {
return coord - (*this);
}
}
const ContentsCoord &ContentsCoord::operator+=(int delta)
{
mChar+=delta;
normalize();
return *this;
}
const ContentsCoord &ContentsCoord::operator-=(int delta)
{
mChar-=delta;
normalize();
return *this;
}
BufferCoord ContentsCoord::toBufferCoord() const
{
return BufferCoord{mChar,mLine};
}
ContentsCoord ContentsCoord::operator-(int delta) const
{
Q_ASSERT(mEdit != nullptr);
return ContentsCoord(mEdit,mChar-delta,mLine);
}
ContentsCoord ContentsCoord::operator+(int delta) const
{
Q_ASSERT(mEdit != nullptr);
return ContentsCoord(mEdit,mChar+delta,mLine);
}
QChar ContentsCoord::operator*() const
{
Q_ASSERT(mEdit != nullptr);
if (mLine < 1) {
return QChar('\0');
}
if (mLine > mEdit->document()->count()) {
return QChar('\0');
}
QString s = mEdit->document()->getString(mLine-1);
if (mChar >= s.length()+1 ) {
return QChar('\n');
}
//qDebug()<<mLine<<":"<<mChar<<" '"<<s<<"'";
return s[mChar-1];
}
ContentsCoord::ContentsCoord()
{
mEdit = nullptr;
mLine = 0;
mEdit = 0;
}
ContentsCoord::ContentsCoord(const ContentsCoord &coord):
ContentsCoord(coord.mEdit,
coord.mChar,
coord.mLine)
{
}
int ContentsCoord::ch() const
{
return mChar;
}
void ContentsCoord::setCh(int newChar)
{
mChar = newChar;
}
bool BufferCoord::operator==(const BufferCoord &coord)
{
return coord.Char == Char && coord.Line == Line;
return coord.ch == ch && coord.line == line;
}
bool BufferCoord::operator>=(const BufferCoord &coord)
{
return (Line > coord.Line)
|| (Line == coord.Line && Char >= coord.Char);
return (line > coord.line)
|| (line == coord.line && ch >= coord.ch);
}
bool BufferCoord::operator>(const BufferCoord &coord)
{
return (Line > coord.Line)
|| (Line == coord.Line && Char > coord.Char);
return (line > coord.line)
|| (line == coord.line && ch > coord.ch);
}
bool BufferCoord::operator<(const BufferCoord &coord)
{
return (Line < coord.Line)
|| (Line == coord.Line && Char < coord.Char);
return (line < coord.line)
|| (line == coord.line && ch < coord.ch);
}
bool BufferCoord::operator<=(const BufferCoord &coord)
{
return (Line < coord.Line)
|| (Line == coord.Line && Char <= coord.Char);
return (line < coord.line)
|| (line == coord.line && ch <= coord.ch);
}
bool BufferCoord::operator!=(const BufferCoord &coord)
{
return coord.Char != Char || coord.Line != Line;
return coord.ch != ch || coord.line != line;
}

View File

@ -22,11 +22,11 @@
#include <QFlags>
#include <memory>
enum class SynSelectionMode {smNormal, smLine, smColumn};
enum class SynSelectionMode {Normal, Line, Column};
struct BufferCoord {
int Char;
int Line;
int ch;
int line;
bool operator==(const BufferCoord& coord);
bool operator>=(const BufferCoord& coord);
bool operator>(const BufferCoord& coord);
@ -35,50 +35,6 @@ struct BufferCoord {
bool operator!=(const BufferCoord& coord);
};
class SynEdit;
/**
* Nomalized buffer posistion:
* (0,0) means at the start of the file ('\0')
* (1,count of lines+1) means at the end of the file ('\0')
* (length of the line+1, line) means at the line break of the line ('\n')
*/
class ContentsCoord {
public:
ContentsCoord();
ContentsCoord(const ContentsCoord& coord);
int ch() const;
void setCh(int newChar);
int line() const;
void setLine(int newLine);
bool atStart();
bool atEnd();
const SynEdit *edit() 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:
ContentsCoord(const SynEdit* edit, int ch, int line);
void normalize();
private:
int mChar;
int mLine;
const SynEdit* mEdit;
friend class SynEdit;
};
struct DisplayCoord {
int Column;
int Row;

View File

@ -63,24 +63,24 @@ void SynExporter::ExportRange(PSynDocument ALines, BufferCoord Start, BufferCoor
// abort if not all necessary conditions are met
if (!ALines || !mHighlighter || (ALines->count() == 0))
return;
Stop.Line = std::max(1, std::min(Stop.Line, ALines->count()));
Stop.Char = std::max(1, std::min(Stop.Char, ALines->getString(Stop.Line - 1).length() + 1));
Start.Line = std::max(1, std::min(Start.Line, ALines->count()));
Start.Char = std::max(1, std::min(Start.Char, ALines->getString(Start.Line - 1).length() + 1));
if ( (Start.Line > ALines->count()) || (Start.Line > Stop.Line) )
Stop.line = std::max(1, std::min(Stop.line, ALines->count()));
Stop.ch = std::max(1, std::min(Stop.ch, ALines->getString(Stop.line - 1).length() + 1));
Start.line = std::max(1, std::min(Start.line, ALines->count()));
Start.ch = std::max(1, std::min(Start.ch, ALines->getString(Start.line - 1).length() + 1));
if ( (Start.line > ALines->count()) || (Start.line > Stop.line) )
return;
if ((Start.Line == Stop.Line) && (Start.Char >= Stop.Char))
if ((Start.line == Stop.line) && (Start.ch >= Stop.ch))
return;
// initialization
mBuffer.clear();
// export all the lines into fBuffer
mFirstAttribute = true;
if (Start.Line == 1)
if (Start.line == 1)
mHighlighter->resetState();
else
mHighlighter->setState(ALines->ranges(Start.Line-2));
for (int i = Start.Line; i<=Stop.Line; i++) {
mHighlighter->setState(ALines->ranges(Start.line-2));
for (int i = Start.line; i<=Stop.line; i++) {
QString Line = ALines->getString(i-1);
// order is important, since Start.Y might be equal to Stop.Y
// if (i == Stop.Line)
@ -93,19 +93,19 @@ void SynExporter::ExportRange(PSynDocument ALines, BufferCoord Start, BufferCoor
PSynHighlighterAttribute attri = mHighlighter->getTokenAttribute();
int startPos = mHighlighter->getTokenPos();
QString token = mHighlighter->getToken();
if (i==Start.Line && (startPos+token.length() < Start.Char)) {
if (i==Start.line && (startPos+token.length() < Start.ch)) {
mHighlighter->next();
continue;
}
if (i==Stop.Line && (startPos >= Stop.Char-1)) {
if (i==Stop.line && (startPos >= Stop.ch-1)) {
mHighlighter->next();
continue;
}
if (i==Stop.Line && (startPos+token.length() > Stop.Char)) {
token = token.remove(Stop.Char - startPos - 1);
if (i==Stop.line && (startPos+token.length() > Stop.ch)) {
token = token.remove(Stop.ch - startPos - 1);
}
if (i==Start.Line && startPos < Start.Char-1) {
token = token.mid(Start.Char-1-startPos);
if (i==Start.line && startPos < Start.ch-1) {
token = token.mid(Start.ch-1-startPos);
}
QString Token = ReplaceReservedChars(token);
@ -115,7 +115,7 @@ void SynExporter::ExportRange(PSynDocument ALines, BufferCoord Start, BufferCoor
FormatToken(Token);
mHighlighter->next();
}
if (i!=Stop.Line)
if (i!=Stop.line)
FormatNewLine();
}
if (!mFirstAttribute)

View File

@ -1374,7 +1374,6 @@ void Settings::Editor::doLoad()
mAutoDetectFileEncoding = boolValue("auto_detect_file_encoding",true);
mUndoLimit = intValue("undo_limit",0);
//tooltips
mEnableTooltips = boolValue("enable_tooltips",true);
mEnableDebugTooltips = boolValue("enable_debug_tooltips",true);