- enhancement: symbol completion when editor has selection
This commit is contained in:
parent
81f404d63c
commit
fa9916e28e
1
NEWS.md
1
NEWS.md
|
@ -20,6 +20,7 @@ Red Panda C++ Version 0.14.5
|
||||||
- fix: calculation of caret position is not in consistence.
|
- fix: calculation of caret position is not in consistence.
|
||||||
- fix: undo one symbol completion as a whole operation
|
- fix: undo one symbol completion as a whole operation
|
||||||
- fix: crash when open a project that contains custom folder
|
- fix: crash when open a project that contains custom folder
|
||||||
|
- enhancement: symbol completion when editor has selection
|
||||||
|
|
||||||
Red Panda C++ Version 0.14.4
|
Red Panda C++ Version 0.14.4
|
||||||
- enhancement: git - log
|
- enhancement: git - log
|
||||||
|
|
|
@ -1947,7 +1947,7 @@ QChar Editor::getCurrentChar()
|
||||||
|
|
||||||
bool Editor::handleSymbolCompletion(QChar key)
|
bool Editor::handleSymbolCompletion(QChar key)
|
||||||
{
|
{
|
||||||
if (!pSettings->editor().completeSymbols() || selAvail())
|
if (!pSettings->editor().completeSymbols())
|
||||||
return false;
|
return false;
|
||||||
if (!insertMode())
|
if (!insertMode())
|
||||||
return false;
|
return false;
|
||||||
|
@ -1994,6 +1994,8 @@ bool Editor::handleSymbolCompletion(QChar key)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case ')':
|
case ')':
|
||||||
|
if (selAvail())
|
||||||
|
return false;
|
||||||
if (pSettings->editor().completeParenthese() && pSettings->editor().overwriteSymbols()) {
|
if (pSettings->editor().completeParenthese() && pSettings->editor().overwriteSymbols()) {
|
||||||
return handleParentheseSkip();
|
return handleParentheseSkip();
|
||||||
}
|
}
|
||||||
|
@ -2004,22 +2006,26 @@ bool Editor::handleSymbolCompletion(QChar key)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case ']':
|
case ']':
|
||||||
if (pSettings->editor().completeBracket() && pSettings->editor().overwriteSymbols()) {
|
if (selAvail())
|
||||||
return handleBracketSkip();
|
return false;
|
||||||
}
|
if (pSettings->editor().completeBracket() && pSettings->editor().overwriteSymbols()) {
|
||||||
return false;
|
return handleBracketSkip();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
case '*':
|
case '*':
|
||||||
status = getQuoteStatus();
|
status = getQuoteStatus();
|
||||||
if (pSettings->editor().completeComment() && (status == QuoteStatus::NotQuote)) {
|
if (pSettings->editor().completeComment() && (status == QuoteStatus::NotQuote)) {
|
||||||
return handleMultilineCommentCompletion();
|
return handleMultilineCommentCompletion();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case '{':
|
case '{':
|
||||||
if (pSettings->editor().completeBrace()) {
|
if (pSettings->editor().completeBrace()) {
|
||||||
return handleBraceCompletion();
|
return handleBraceCompletion();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case '}':
|
case '}':
|
||||||
|
if (selAvail())
|
||||||
|
return false;
|
||||||
if (pSettings->editor().completeBrace() && pSettings->editor().overwriteSymbols()) {
|
if (pSettings->editor().completeBrace() && pSettings->editor().overwriteSymbols()) {
|
||||||
return handleBraceSkip();
|
return handleBraceSkip();
|
||||||
}
|
}
|
||||||
|
@ -2035,11 +2041,15 @@ bool Editor::handleSymbolCompletion(QChar key)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case '<':
|
case '<':
|
||||||
|
if (selAvail())
|
||||||
|
return false;
|
||||||
if (pSettings->editor().completeGlobalInclude()) { // #include <>
|
if (pSettings->editor().completeGlobalInclude()) { // #include <>
|
||||||
return handleGlobalIncludeCompletion();
|
return handleGlobalIncludeCompletion();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case '>':
|
case '>':
|
||||||
|
if (selAvail())
|
||||||
|
return false;
|
||||||
if (pSettings->editor().completeGlobalInclude() && pSettings->editor().overwriteSymbols()) { // #include <>
|
if (pSettings->editor().completeGlobalInclude() && pSettings->editor().overwriteSymbols()) { // #include <>
|
||||||
return handleGlobalIncludeSkip();
|
return handleGlobalIncludeSkip();
|
||||||
}
|
}
|
||||||
|
@ -2052,14 +2062,25 @@ bool Editor::handleParentheseCompletion()
|
||||||
{
|
{
|
||||||
QuoteStatus status = getQuoteStatus();
|
QuoteStatus status = getQuoteStatus();
|
||||||
if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) {
|
if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) {
|
||||||
beginUpdate();
|
if (selAvail() && status == QuoteStatus::NotQuote) {
|
||||||
beginUndoBlock();
|
QString text=selText();
|
||||||
commandProcessor(SynEditorCommand::ecChar,'(');
|
beginUpdate();
|
||||||
BufferCoord oldCaret = caretXY();
|
beginUndoBlock();
|
||||||
commandProcessor(SynEditorCommand::ecChar,')');
|
commandProcessor(SynEditorCommand::ecChar,'(');
|
||||||
setCaretXY(oldCaret);
|
setSelText(text);
|
||||||
endUndoBlock();
|
commandProcessor(SynEditorCommand::ecChar,')');
|
||||||
endUpdate();
|
endUndoBlock();
|
||||||
|
endUpdate();
|
||||||
|
} else {
|
||||||
|
beginUpdate();
|
||||||
|
beginUndoBlock();
|
||||||
|
commandProcessor(SynEditorCommand::ecChar,'(');
|
||||||
|
BufferCoord oldCaret = caretXY();
|
||||||
|
commandProcessor(SynEditorCommand::ecChar,')');
|
||||||
|
setCaretXY(oldCaret);
|
||||||
|
endUndoBlock();
|
||||||
|
endUpdate();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// if (status == QuoteStatus::NotQuote) && FunctionTipAllowed then
|
// if (status == QuoteStatus::NotQuote) && FunctionTipAllowed then
|
||||||
|
@ -2103,14 +2124,26 @@ bool Editor::handleBracketCompletion()
|
||||||
{
|
{
|
||||||
// QuoteStatus status = getQuoteStatus();
|
// QuoteStatus status = getQuoteStatus();
|
||||||
// if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) {
|
// if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) {
|
||||||
beginUpdate();
|
QuoteStatus status = getQuoteStatus();
|
||||||
beginUndoBlock();
|
if (selAvail() && status == QuoteStatus::NotQuote) {
|
||||||
commandProcessor(SynEditorCommand::ecChar,'[');
|
QString text=selText();
|
||||||
BufferCoord oldCaret = caretXY();
|
beginUpdate();
|
||||||
commandProcessor(SynEditorCommand::ecChar,']');
|
beginUndoBlock();
|
||||||
setCaretXY(oldCaret);
|
commandProcessor(SynEditorCommand::ecChar,'[');
|
||||||
endUndoBlock();
|
setSelText(text);
|
||||||
endUpdate();
|
commandProcessor(SynEditorCommand::ecChar,']');
|
||||||
|
endUndoBlock();
|
||||||
|
endUpdate();
|
||||||
|
} else {
|
||||||
|
beginUpdate();
|
||||||
|
beginUndoBlock();
|
||||||
|
commandProcessor(SynEditorCommand::ecChar,'[');
|
||||||
|
BufferCoord oldCaret = caretXY();
|
||||||
|
commandProcessor(SynEditorCommand::ecChar,']');
|
||||||
|
setCaretXY(oldCaret);
|
||||||
|
endUndoBlock();
|
||||||
|
endUpdate();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
@ -2139,13 +2172,19 @@ bool Editor::handleBracketSkip()
|
||||||
bool Editor::handleMultilineCommentCompletion()
|
bool Editor::handleMultilineCommentCompletion()
|
||||||
{
|
{
|
||||||
if ((caretX()-2 < lineText().length()) && (lineText()[caretX() - 2] == '/')) {
|
if ((caretX()-2 < lineText().length()) && (lineText()[caretX() - 2] == '/')) {
|
||||||
|
QString text=selText();
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
beginUndoBlock();
|
beginUndoBlock();
|
||||||
commandProcessor(SynEditorCommand::ecChar,'*');
|
commandProcessor(SynEditorCommand::ecChar,'*');
|
||||||
BufferCoord oldCaret = caretXY();
|
BufferCoord oldCaret;
|
||||||
|
if (text.isEmpty())
|
||||||
|
oldCaret = caretXY();
|
||||||
|
else
|
||||||
|
setSelText(text);
|
||||||
commandProcessor(SynEditorCommand::ecChar,'*');
|
commandProcessor(SynEditorCommand::ecChar,'*');
|
||||||
commandProcessor(SynEditorCommand::ecChar,'/');
|
commandProcessor(SynEditorCommand::ecChar,'/');
|
||||||
setCaretXY(oldCaret);
|
if (text.isEmpty())
|
||||||
|
setCaretXY(oldCaret);
|
||||||
endUndoBlock();
|
endUndoBlock();
|
||||||
endUpdate();
|
endUpdate();
|
||||||
return true;
|
return true;
|
||||||
|
@ -2161,10 +2200,18 @@ bool Editor::handleBraceCompletion()
|
||||||
s=lines()->getString(i);
|
s=lines()->getString(i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
QString text=selText();
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
beginUndoBlock();
|
beginUndoBlock();
|
||||||
commandProcessor(SynEditorCommand::ecChar,'{');
|
commandProcessor(SynEditorCommand::ecChar,'{');
|
||||||
BufferCoord oldCaret = caretXY();
|
BufferCoord oldCaret;
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
oldCaret = caretXY();
|
||||||
|
} else {
|
||||||
|
commandProcessor(SynEditorCommand::ecInsertLine);
|
||||||
|
setSelText(text);
|
||||||
|
commandProcessor(SynEditorCommand::ecInsertLine);
|
||||||
|
}
|
||||||
commandProcessor(SynEditorCommand::ecChar,'}');
|
commandProcessor(SynEditorCommand::ecChar,'}');
|
||||||
if (
|
if (
|
||||||
( (s.startsWith("struct")
|
( (s.startsWith("struct")
|
||||||
|
@ -2178,7 +2225,8 @@ bool Editor::handleBraceCompletion()
|
||||||
) || s.endsWith('=')) {
|
) || s.endsWith('=')) {
|
||||||
commandProcessor(SynEditorCommand::ecChar,';');
|
commandProcessor(SynEditorCommand::ecChar,';');
|
||||||
}
|
}
|
||||||
setCaretXY(oldCaret);
|
if (text.isEmpty())
|
||||||
|
setCaretXY(oldCaret);
|
||||||
endUndoBlock();
|
endUndoBlock();
|
||||||
endUpdate();
|
endUpdate();
|
||||||
return true;
|
return true;
|
||||||
|
@ -2217,12 +2265,23 @@ bool Editor::handleSingleQuoteCompletion()
|
||||||
QuoteStatus status = getQuoteStatus();
|
QuoteStatus status = getQuoteStatus();
|
||||||
QChar ch = getCurrentChar();
|
QChar ch = getCurrentChar();
|
||||||
if (ch == '\'') {
|
if (ch == '\'') {
|
||||||
if (status == QuoteStatus::SingleQuote) {
|
if (status == QuoteStatus::SingleQuote && !selAvail()) {
|
||||||
setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over
|
setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (status == QuoteStatus::NotQuote) {
|
if (status == QuoteStatus::NotQuote) {
|
||||||
|
if (selAvail()) {
|
||||||
|
QString text=selText();
|
||||||
|
beginUpdate();
|
||||||
|
beginUndoBlock();
|
||||||
|
commandProcessor(SynEditorCommand::ecChar,'\'');
|
||||||
|
setSelText(text);
|
||||||
|
commandProcessor(SynEditorCommand::ecChar,'\'');
|
||||||
|
endUndoBlock();
|
||||||
|
endUpdate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
||||||
// insert ''
|
// insert ''
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
|
@ -2245,12 +2304,24 @@ bool Editor::handleDoubleQuoteCompletion()
|
||||||
QuoteStatus status = getQuoteStatus();
|
QuoteStatus status = getQuoteStatus();
|
||||||
QChar ch = getCurrentChar();
|
QChar ch = getCurrentChar();
|
||||||
if (ch == '"') {
|
if (ch == '"') {
|
||||||
if (status == QuoteStatus::DoubleQuote || status == QuoteStatus::RawString) {
|
if ((status == QuoteStatus::DoubleQuote || status == QuoteStatus::RawString)
|
||||||
|
&& !selAvail()) {
|
||||||
setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over
|
setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (status == QuoteStatus::NotQuote) {
|
if (status == QuoteStatus::NotQuote) {
|
||||||
|
if (selAvail()) {
|
||||||
|
QString text=selText();
|
||||||
|
beginUpdate();
|
||||||
|
beginUndoBlock();
|
||||||
|
commandProcessor(SynEditorCommand::ecChar,'"');
|
||||||
|
setSelText(text);
|
||||||
|
commandProcessor(SynEditorCommand::ecChar,'"');
|
||||||
|
endUndoBlock();
|
||||||
|
endUpdate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
||||||
// insert ""
|
// insert ""
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
|
|
|
@ -686,7 +686,7 @@ void SynEdit::invalidateGutterLines(int FirstLine, int LastLine)
|
||||||
DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) const
|
DisplayCoord SynEdit::pixelsToRowColumn(int aX, int aY) const
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
std::max(1, mLeftChar + ((aX - mGutterWidth - 2) / mCharWidth)),
|
std::max(1, (int)(mLeftChar + round((aX - mGutterWidth - 2.0) / mCharWidth))),
|
||||||
std::max(1, mTopLine + (aY / mTextHeight))
|
std::max(1, mTopLine + (aY / mTextHeight))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue