- fix: Insert line after comments may auto add an extra '*'.
This commit is contained in:
parent
0f654bdf75
commit
bbb3071d44
1
NEWS.md
1
NEWS.md
|
@ -17,6 +17,7 @@ Red Panda C++ Version 2.27
|
||||||
- enhancement: Support POSIX shell-like escaping in user inputs for compiler arguments.
|
- enhancement: Support POSIX shell-like escaping in user inputs for compiler arguments.
|
||||||
- fix: (Hopefully) properly escape filenames and arguments in makefile generation.
|
- fix: (Hopefully) properly escape filenames and arguments in makefile generation.
|
||||||
- enhancement: Beautify display for spaces and linebreaks.
|
- enhancement: Beautify display for spaces and linebreaks.
|
||||||
|
- fix: Insert line after comments may auto add an extra '*'.
|
||||||
|
|
||||||
Red Panda C++ Version 2.26
|
Red Panda C++ Version 2.26
|
||||||
- enhancement: Code suggestion for embedded std::vectors.
|
- enhancement: Code suggestion for embedded std::vectors.
|
||||||
|
|
|
@ -736,74 +736,83 @@ void Editor::keyPressEvent(QKeyEvent *event)
|
||||||
clearUserCodeInTabStops();
|
clearUserCodeInTabStops();
|
||||||
} else {
|
} else {
|
||||||
QString s = lineText().mid(0,caretX()-1).trimmed();
|
QString s = lineText().mid(0,caretX()-1).trimmed();
|
||||||
if (s=="/**") { //javadoc style docstring
|
if (syntaxer()) {
|
||||||
s = lineText().mid(caretX()-1).trimmed();
|
if (caretY()==1) {
|
||||||
if (s=="*/") {
|
syntaxer()->resetState();
|
||||||
QSynedit::BufferCoord p = caretXY();
|
|
||||||
setBlockBegin(p);
|
|
||||||
p.ch = lineText().length()+1;
|
|
||||||
setBlockEnd(p);
|
|
||||||
setSelText("");
|
|
||||||
}
|
|
||||||
handled = true;
|
|
||||||
QStringList insertString;
|
|
||||||
insertString.append("");
|
|
||||||
PStatement function;
|
|
||||||
if (mParser)
|
|
||||||
function = mParser->findFunctionAt(mFilename,caretY()+1);
|
|
||||||
if (function) {
|
|
||||||
QStringList params;
|
|
||||||
QString funcName = function->command;
|
|
||||||
bool isVoid = (function->type == "void");
|
|
||||||
foreach (const PStatement& child, function->children) {
|
|
||||||
if (child->kind == StatementKind::skParameter)
|
|
||||||
params.append(child->command);
|
|
||||||
}
|
|
||||||
insertString.append(QString(" * @brief ")+USER_CODE_IN_INSERT_POS);
|
|
||||||
if (!params.isEmpty())
|
|
||||||
insertString.append(" * ");
|
|
||||||
foreach (const QString& param, params) {
|
|
||||||
insertString.append(QString(" * @param %1 %2")
|
|
||||||
.arg(param, USER_CODE_IN_INSERT_POS));
|
|
||||||
}
|
|
||||||
if (!isVoid) {
|
|
||||||
insertString.append(" * ");
|
|
||||||
insertString.append(QString(" * @return ")+USER_CODE_IN_INSERT_POS);
|
|
||||||
}
|
|
||||||
insertString.append(" */");
|
|
||||||
// } else if (caretY()==1) { /* file header */
|
|
||||||
// insertString.append(QString(" * @file %1<SOURCEPATH>%2")
|
|
||||||
// .arg(USER_CODE_IN_REPL_POS_BEGIN)
|
|
||||||
// .arg(USER_CODE_IN_REPL_POS_END));
|
|
||||||
// insertString.append(QString(" * @brief: ")+ USER_CODE_IN_INSERT_POS);
|
|
||||||
// insertString.append(QString(" * @version: ")+ USER_CODE_IN_INSERT_POS);
|
|
||||||
// insertString.append(QString(" * @copyright: ")+ USER_CODE_IN_INSERT_POS);
|
|
||||||
// insertString.append(QString(" * @author: ")+ USER_CODE_IN_INSERT_POS);
|
|
||||||
// insertString.append(" * @date: <DATETIME>");
|
|
||||||
// insertString.append(" * ");
|
|
||||||
// insertString.append(" **/");
|
|
||||||
} else {
|
} else {
|
||||||
insertString.append(QString(" * ")+USER_CODE_IN_INSERT_POS);
|
syntaxer()->setState(document()->getSyntaxState(caretY()-2));
|
||||||
insertString.append(" */");
|
|
||||||
}
|
}
|
||||||
insertCodeSnippet(linesToText(insertString));
|
syntaxer()->setLine(s,caretY());
|
||||||
} else if (syntaxer()
|
syntaxer()->nextToEol();
|
||||||
&& caretY()>=2
|
int state = syntaxer()->getState().state;
|
||||||
&& syntaxer()->isLastLineCommentNotFinished(
|
if (syntaxer()->isLastLineCommentNotFinished(state)) {
|
||||||
document()->getSyntaxState(caretY()-2).state)) {
|
if (s=="/**") { //javadoc style docstring
|
||||||
s=trimLeft(lineText());
|
s = lineText().mid(caretX()-1).trimmed();
|
||||||
if (s.startsWith("* ")) {
|
if (s=="*/") {
|
||||||
handled = true;
|
QSynedit::BufferCoord p = caretXY();
|
||||||
int right = document()->getLine(caretY()-1).length()-caretX();
|
setBlockBegin(p);
|
||||||
s=lineBreak()+"* ";
|
p.ch = lineText().length()+1;
|
||||||
insertString(s,false);
|
setBlockEnd(p);
|
||||||
QSynedit::BufferCoord p = caretXY();
|
setSelText("");
|
||||||
p.line++;
|
}
|
||||||
p.ch = document()->getLine(p.line-1).length()+1;
|
handled = true;
|
||||||
if (right>0) {
|
QStringList insertString;
|
||||||
p.ch -=right+1;
|
insertString.append("");
|
||||||
|
PStatement function;
|
||||||
|
if (mParser)
|
||||||
|
function = mParser->findFunctionAt(mFilename,caretY()+1);
|
||||||
|
if (function) {
|
||||||
|
QStringList params;
|
||||||
|
QString funcName = function->command;
|
||||||
|
bool isVoid = (function->type == "void");
|
||||||
|
foreach (const PStatement& child, function->children) {
|
||||||
|
if (child->kind == StatementKind::skParameter)
|
||||||
|
params.append(child->command);
|
||||||
|
}
|
||||||
|
insertString.append(QString(" * @brief ")+USER_CODE_IN_INSERT_POS);
|
||||||
|
if (!params.isEmpty())
|
||||||
|
insertString.append(" * ");
|
||||||
|
foreach (const QString& param, params) {
|
||||||
|
insertString.append(QString(" * @param %1 %2")
|
||||||
|
.arg(param, USER_CODE_IN_INSERT_POS));
|
||||||
|
}
|
||||||
|
if (!isVoid) {
|
||||||
|
insertString.append(" * ");
|
||||||
|
insertString.append(QString(" * @return ")+USER_CODE_IN_INSERT_POS);
|
||||||
|
}
|
||||||
|
insertString.append(" */");
|
||||||
|
// } else if (caretY()==1) { /* file header */
|
||||||
|
// insertString.append(QString(" * @file %1<SOURCEPATH>%2")
|
||||||
|
// .arg(USER_CODE_IN_REPL_POS_BEGIN)
|
||||||
|
// .arg(USER_CODE_IN_REPL_POS_END));
|
||||||
|
// insertString.append(QString(" * @brief: ")+ USER_CODE_IN_INSERT_POS);
|
||||||
|
// insertString.append(QString(" * @version: ")+ USER_CODE_IN_INSERT_POS);
|
||||||
|
// insertString.append(QString(" * @copyright: ")+ USER_CODE_IN_INSERT_POS);
|
||||||
|
// insertString.append(QString(" * @author: ")+ USER_CODE_IN_INSERT_POS);
|
||||||
|
// insertString.append(" * @date: <DATETIME>");
|
||||||
|
// insertString.append(" * ");
|
||||||
|
// insertString.append(" **/");
|
||||||
|
} else {
|
||||||
|
insertString.append(QString(" * ")+USER_CODE_IN_INSERT_POS);
|
||||||
|
insertString.append(" */");
|
||||||
|
}
|
||||||
|
insertCodeSnippet(linesToText(insertString));
|
||||||
|
} else {
|
||||||
|
s=trimLeft(lineText());
|
||||||
|
if (s.startsWith("* ")) {
|
||||||
|
handled = true;
|
||||||
|
int right = document()->getLine(caretY()-1).length()-caretX();
|
||||||
|
s=lineBreak()+"* ";
|
||||||
|
insertString(s,false);
|
||||||
|
QSynedit::BufferCoord p = caretXY();
|
||||||
|
p.line++;
|
||||||
|
p.ch = document()->getLine(p.line-1).length()+1;
|
||||||
|
if (right>0) {
|
||||||
|
p.ch -=right+1;
|
||||||
|
}
|
||||||
|
setCaretXY(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setCaretXY(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue