work save

This commit is contained in:
royqh1979@gmail.com 2021-08-18 13:42:32 +08:00
parent 9272b767d5
commit 0c6be9b93c
2 changed files with 117 additions and 29 deletions

View File

@ -311,37 +311,39 @@ void Editor::focusOutEvent(QFocusEvent *event)
void Editor::keyPressEvent(QKeyEvent *event) void Editor::keyPressEvent(QKeyEvent *event)
{ {
bool handled = false; bool handled = false;
switch (event->key()) { if (!readOnly()) {
case Qt::Key_Delete: switch (event->key()) {
// remove completed character case Qt::Key_Delete:
//fLastIdCharPressed:=0; // remove completed character
undoSymbolCompletion(caretX()); //fLastIdCharPressed:=0;
break;; undoSymbolCompletion(caretX());
case Qt::Key_Backspace: break;;
// remove completed character case Qt::Key_Backspace:
//fLastIdCharPressed:=0; // remove completed character
undoSymbolCompletion(caretX()-1); //fLastIdCharPressed:=0;
break;; undoSymbolCompletion(caretX()-1);
default: { break;;
QString t = event->text(); default: {
if (!t.isEmpty()) { QString t = event->text();
QChar ch = t[0]; if (!t.isEmpty()) {
switch (ch.unicode()) { QChar ch = t[0];
case '"': switch (ch.unicode()) {
case '\'': case '"':
case '(': case '\'':
case ')': case '(':
case '{': case ')':
case '}': case '{':
case '[': case '}':
case ']': case '[':
case '<': case ']':
case '>': case '<':
case '*': case '>':
handled = handleSymbolCompletion(ch); case '*':
handled = handleSymbolCompletion(ch);
}
} }
} }
} }
} }
if (!handled) { if (!handled) {
SynEdit::keyPressEvent(event); SynEdit::keyPressEvent(event);

View File

@ -776,6 +776,92 @@ void CppParser::handleEnum()
mIndex++; mIndex++;
} }
void CppParser::handleForBlock()
{
int startLine = mTokenizer[mIndex]->line;
mIndex++; // skip for/catch;
if (!(mIndex < mTokenizer.tokenCount()))
return;
int i=mIndex;
while ((i<mTokenizer.tokenCount()) && !mTokenizer[i]->text.startsWith(';'))
i++;
if (i>=mTokenizer.tokenCount())
return;
int i2 = i+1; //skip over ';' (tokenizer have change for(;;) to for(;)
if (i2>=mTokenizer.tokenCount())
return;
if (mTokenizer[i2]->text.startsWith('{')) {
mBlockBeginSkips.append(i2);
i=skipBraces(i2);
if (i==i2)
mBlockEndSkips.append(mTokenizer.tokenCount());
else
mBlockEndSkips.append(i);
} else {
i=i2;
while ((i<mTokenizer.tokenCount()) && !mTokenizer[i]->text.startsWith(';'))
i++;
mBlockEndSkips.append(i);
}
// add a block
PStatement block = addStatement(
getCurrentScope(),
mCurrentFile,
"", // override hint
"",
"",
"",
"",
startLine,
StatementKind::skBlock,
getScope(),
mClassScope,
true,
false);
addSoloScopeLevel(block,startLine);
}
void CppParser::handleKeyword()
{
// Skip
SkipType skipType = CppKeywords.value(mTokenizer[mIndex]->text,SkipType::skNone);
switch (skipType) {
case SkipType::skItself:
// skip it;
mIndex++;
break;
case SkipType::skToSemicolon:
// Skip to ;
while (mIndex < mTokenizer.tokenCount() && !mTokenizer[mIndex]->text.startsWith(';'))
mIndex++;
mIndex++;// step over
break;
case SkipType::skToColon:
// Skip to :
while (mIndex < mTokenizer.tokenCount() && !mTokenizer[mIndex]->text.startsWith(':'))
mIndex++;
break;
case SkipType::skToRightParenthesis:
// skip to )
while (mIndex < mTokenizer.tokenCount() && !mTokenizer[mIndex]->text.startsWith(')'))
mIndex++;
mIndex++; // step over
break;
case SkipType::skToLeftBrace:
// Skip to {
while (mIndex < mTokenizer.tokenCount() && !mTokenizer[mIndex]->text.startsWith('{'))
mIndex++;
break;
case SkipType::skToRightBrace:
// Skip to }
while (mIndex < mTokenizer.tokenCount() && !mTokenizer[mIndex]->text.startsWith('}'))
mIndex++;
mIndex++; // step over
break;
}
}
QString CppParser::expandMacroType(const QString &name) QString CppParser::expandMacroType(const QString &name)
{ {
//its done in the preprocessor //its done in the preprocessor