* fix: use backspace to delete selected text is not correctly handled
* done: delete symbol pairs
This commit is contained in:
parent
0f59b1c665
commit
aad78fa475
|
@ -211,6 +211,56 @@ QTabWidget* Editor::pageControl() noexcept{
|
||||||
return mParentPageControl;
|
return mParentPageControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::undoSymbolCompletion(int pos)
|
||||||
|
{
|
||||||
|
PSynHighlighterAttribute Attr;
|
||||||
|
QString Token;
|
||||||
|
bool tokenFinished;
|
||||||
|
SynHighlighterTokenType tokenType;
|
||||||
|
|
||||||
|
if (!highlighter())
|
||||||
|
return;
|
||||||
|
if (!pSettings->editor().removeSymbolPairs())
|
||||||
|
return;
|
||||||
|
if (!GetHighlighterAttriAtRowCol(caretXY(), Token, tokenFinished, tokenType, Attr))
|
||||||
|
return;
|
||||||
|
if ((tokenType == SynHighlighterTokenType::Comment) && (!tokenFinished))
|
||||||
|
return ;
|
||||||
|
//convert caret x to string index;
|
||||||
|
pos--;
|
||||||
|
|
||||||
|
if (pos<0 || pos+1>=lineText().length())
|
||||||
|
return;
|
||||||
|
QChar DeletedChar = lineText()[pos];
|
||||||
|
QChar NextChar = lineText()[pos+1];
|
||||||
|
if ((tokenType == SynHighlighterTokenType::Character) && (DeletedChar != '\''))
|
||||||
|
return;
|
||||||
|
if (tokenType == SynHighlighterTokenType::StringEscapeSequence)
|
||||||
|
return;
|
||||||
|
if (tokenType == SynHighlighterTokenType::String) {
|
||||||
|
if ((DeletedChar!='"') && (DeletedChar!='('))
|
||||||
|
return;
|
||||||
|
if ((DeletedChar=='"') && (Token!="\"\""))
|
||||||
|
return;
|
||||||
|
if ((DeletedChar=='(') && (!Token.startsWith("R\"")))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((DeletedChar == '\'') && (tokenType == SynHighlighterTokenType::Number))
|
||||||
|
return;
|
||||||
|
if ((DeletedChar == '<') &&
|
||||||
|
((tokenType != SynHighlighterTokenType::PreprocessDirective)
|
||||||
|
|| !lineText().startsWith("#include")))
|
||||||
|
return;
|
||||||
|
if ( (pSettings->editor().completeBracket() && (DeletedChar == '[') && (NextChar == ']')) ||
|
||||||
|
(pSettings->editor().completeParenthese() && (DeletedChar == '(') && (NextChar == ')')) ||
|
||||||
|
(pSettings->editor().completeGlobalInclude() && (DeletedChar == '<') && (NextChar == '>')) ||
|
||||||
|
(pSettings->editor().completeBrace() && (DeletedChar == '{') && (NextChar == '}')) ||
|
||||||
|
(pSettings->editor().completeSingleQuote() && (DeletedChar == '\'') && (NextChar == '\'')) ||
|
||||||
|
(pSettings->editor().completeDoubleQuote() && (DeletedChar == '\"') && (NextChar == '\"'))) {
|
||||||
|
CommandProcessor(SynEditorCommand::ecDeleteChar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::wheelEvent(QWheelEvent *event) {
|
void Editor::wheelEvent(QWheelEvent *event) {
|
||||||
if ( (event->modifiers() & Qt::ControlModifier)!=0) {
|
if ( (event->modifiers() & Qt::ControlModifier)!=0) {
|
||||||
int size = pSettings->editor().fontSize();
|
int size = pSettings->editor().fontSize();
|
||||||
|
@ -250,24 +300,38 @@ void Editor::focusOutEvent(QFocusEvent *event)
|
||||||
void Editor::keyPressEvent(QKeyEvent *event)
|
void Editor::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
QString t = event->text();
|
switch (event->key()) {
|
||||||
if (!t.isEmpty()) {
|
case Qt::Key_Delete:
|
||||||
QChar ch = t[0];
|
// remove completed character
|
||||||
switch (ch.unicode()) {
|
//fLastIdCharPressed:=0;
|
||||||
case '"':
|
undoSymbolCompletion(caretX());
|
||||||
case '\'':
|
break;;
|
||||||
case '(':
|
case Qt::Key_Backspace:
|
||||||
case ')':
|
// remove completed character
|
||||||
case '{':
|
//fLastIdCharPressed:=0;
|
||||||
case '}':
|
undoSymbolCompletion(caretX()-1);
|
||||||
case '[':
|
break;;
|
||||||
case ']':
|
default: {
|
||||||
case '<':
|
QString t = event->text();
|
||||||
case '>':
|
if (!t.isEmpty()) {
|
||||||
case '*':
|
QChar ch = t[0];
|
||||||
handled = handleSymbolCompletion(ch);
|
switch (ch.unicode()) {
|
||||||
|
case '"':
|
||||||
|
case '\'':
|
||||||
|
case '(':
|
||||||
|
case ')':
|
||||||
|
case '{':
|
||||||
|
case '}':
|
||||||
|
case '[':
|
||||||
|
case ']':
|
||||||
|
case '<':
|
||||||
|
case '>':
|
||||||
|
case '*':
|
||||||
|
handled = handleSymbolCompletion(ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
SynEdit::keyPressEvent(event);
|
SynEdit::keyPressEvent(event);
|
||||||
} else {
|
} else {
|
||||||
|
@ -676,7 +740,7 @@ bool Editor::handleSingleQuoteCompletion()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (status == QuoteStatus::NotQuote) {
|
if (status == QuoteStatus::NotQuote) {
|
||||||
if (highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
||||||
// insert ''
|
// insert ''
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
CommandProcessor(SynEditorCommand::ecChar,'\'');
|
CommandProcessor(SynEditorCommand::ecChar,'\'');
|
||||||
|
@ -696,13 +760,13 @@ 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) {
|
||||||
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 (highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
||||||
// insert ""
|
// insert ""
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
CommandProcessor(SynEditorCommand::ecChar,'"');
|
CommandProcessor(SynEditorCommand::ecChar,'"');
|
||||||
|
@ -759,7 +823,7 @@ Editor::QuoteStatus Editor::getQuoteStatus()
|
||||||
if (posX >= Line.length()) {
|
if (posX >= Line.length()) {
|
||||||
posX = Line.length()-1;
|
posX = Line.length()-1;
|
||||||
}
|
}
|
||||||
for (int i=0; i<=posX;i++) {
|
for (int i=0; i<posX;i++) {
|
||||||
if (i+1<Line.length() && (Line[i] == 'R') && (Line[i+1] == '"') && (Result == QuoteStatus::NotQuote)) {
|
if (i+1<Line.length() && (Line[i] == 'R') && (Line[i+1] == '"') && (Result == QuoteStatus::NotQuote)) {
|
||||||
Result = QuoteStatus::RawString;
|
Result = QuoteStatus::RawString;
|
||||||
i++; // skip R
|
i++; // skip R
|
||||||
|
|
|
@ -103,6 +103,7 @@ private:
|
||||||
bool handleDoubleQuoteCompletion();
|
bool handleDoubleQuoteCompletion();
|
||||||
bool handleGlobalIncludeCompletion();
|
bool handleGlobalIncludeCompletion();
|
||||||
bool handleGlobalIncludeSkip();
|
bool handleGlobalIncludeSkip();
|
||||||
|
void undoSymbolCompletion(int pos);
|
||||||
QuoteStatus getQuoteStatus();
|
QuoteStatus getQuoteStatus();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -4059,8 +4059,8 @@ void SynEdit::SetSelTextPrimitiveEx(SynSelectionMode PasteMode, const QString &V
|
||||||
mLines->endUpdate();
|
mLines->endUpdate();
|
||||||
decPaintLock();
|
decPaintLock();
|
||||||
});
|
});
|
||||||
BufferCoord BB = mBlockBegin;
|
BufferCoord BB = blockBegin();
|
||||||
BufferCoord BE = mBlockEnd;
|
BufferCoord BE = blockEnd();
|
||||||
if (selAvail()) {
|
if (selAvail()) {
|
||||||
DeleteSelection(BB,BE);
|
DeleteSelection(BB,BE);
|
||||||
internalSetCaretXY(BB);
|
internalSetCaretXY(BB);
|
||||||
|
|
|
@ -293,14 +293,14 @@ void Settings::Editor::setColorScheme(const QString &colorScheme)
|
||||||
mColorScheme = colorScheme;
|
mColorScheme = colorScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::Editor::removeMathcingSymbol() const
|
bool Settings::Editor::removeSymbolPairs() const
|
||||||
{
|
{
|
||||||
return mRemoveMathcingSymbol;
|
return mRemoveSymbolPairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::Editor::setRemoveMathcingSymbol(bool removeMathcingSymbol)
|
void Settings::Editor::setRemoveSymbolPairs(bool value)
|
||||||
{
|
{
|
||||||
mRemoveMathcingSymbol = removeMathcingSymbol;
|
mRemoveSymbolPairs = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::Editor::overwriteSymbols() const
|
bool Settings::Editor::overwriteSymbols() const
|
||||||
|
@ -721,7 +721,7 @@ void Settings::Editor::doSave()
|
||||||
saveValue("complete_double_quote", mCompleteDoubleQuote);
|
saveValue("complete_double_quote", mCompleteDoubleQuote);
|
||||||
saveValue("complete_global_include", mCompleteGlobalInclude);
|
saveValue("complete_global_include", mCompleteGlobalInclude);
|
||||||
saveValue("overwrite_symbols", mOverwriteSymbols);
|
saveValue("overwrite_symbols", mOverwriteSymbols);
|
||||||
saveValue("remove_matching_symbols",mRemoveMathcingSymbol);
|
saveValue("remove_symbol_pairs",mRemoveSymbolPairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::Editor::doLoad()
|
void Settings::Editor::doLoad()
|
||||||
|
@ -794,7 +794,7 @@ void Settings::Editor::doLoad()
|
||||||
mCompleteDoubleQuote = boolValue("complete_double_quote",true);
|
mCompleteDoubleQuote = boolValue("complete_double_quote",true);
|
||||||
mCompleteGlobalInclude = boolValue("complete_global_include",true);
|
mCompleteGlobalInclude = boolValue("complete_global_include",true);
|
||||||
mOverwriteSymbols = boolValue("overwrite_symbols",true);
|
mOverwriteSymbols = boolValue("overwrite_symbols",true);
|
||||||
mRemoveMathcingSymbol = boolValue("remove_matching_symbols",true);
|
mRemoveSymbolPairs = boolValue("remove_symbol_pairs",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SynEditCaretType Settings::Editor::caretForOverwrite() const
|
SynEditCaretType Settings::Editor::caretForOverwrite() const
|
||||||
|
|
|
@ -245,8 +245,8 @@ public:
|
||||||
bool overwriteSymbols() const;
|
bool overwriteSymbols() const;
|
||||||
void setOverwriteSymbols(bool overwriteSymbols);
|
void setOverwriteSymbols(bool overwriteSymbols);
|
||||||
|
|
||||||
bool removeMathcingSymbol() const;
|
bool removeSymbolPairs() const;
|
||||||
void setRemoveMathcingSymbol(bool removeMathcingSymbol);
|
void setRemoveSymbolPairs(bool value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray mDefaultEncoding;
|
QByteArray mDefaultEncoding;
|
||||||
|
@ -317,7 +317,7 @@ public:
|
||||||
bool mCompleteDoubleQuote;
|
bool mCompleteDoubleQuote;
|
||||||
bool mCompleteGlobalInclude;
|
bool mCompleteGlobalInclude;
|
||||||
bool mOverwriteSymbols;
|
bool mOverwriteSymbols;
|
||||||
bool mRemoveMathcingSymbol;
|
bool mRemoveSymbolPairs;
|
||||||
|
|
||||||
// _Base interface
|
// _Base interface
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -24,7 +24,7 @@ void EditorSymbolCompletionWidget::doLoad()
|
||||||
ui->chkCompleteGlobalInclude->setChecked(pSettings->editor().completeGlobalInclude());
|
ui->chkCompleteGlobalInclude->setChecked(pSettings->editor().completeGlobalInclude());
|
||||||
ui->chkCompleteParenthesis->setChecked(pSettings->editor().completeParenthese());
|
ui->chkCompleteParenthesis->setChecked(pSettings->editor().completeParenthese());
|
||||||
ui->chkCompleteSingleQuotation->setChecked(pSettings->editor().completeSingleQuote());
|
ui->chkCompleteSingleQuotation->setChecked(pSettings->editor().completeSingleQuote());
|
||||||
ui->chkRemoveMatchingSymbols->setChecked(pSettings->editor().removeMathcingSymbol());
|
ui->chkRemoveSymbolPairs->setChecked(pSettings->editor().removeSymbolPairs());
|
||||||
ui->chkSkipMathingSymbols->setChecked(pSettings->editor().overwriteSymbols());
|
ui->chkSkipMathingSymbols->setChecked(pSettings->editor().overwriteSymbols());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ void EditorSymbolCompletionWidget::doSave()
|
||||||
pSettings->editor().setCompleteGlobalInclude(ui->chkCompleteGlobalInclude->isChecked());
|
pSettings->editor().setCompleteGlobalInclude(ui->chkCompleteGlobalInclude->isChecked());
|
||||||
pSettings->editor().setCompleteParenthese(ui->chkCompleteParenthesis->isChecked());
|
pSettings->editor().setCompleteParenthese(ui->chkCompleteParenthesis->isChecked());
|
||||||
pSettings->editor().setCompleteSingleQuote(ui->chkCompleteSingleQuotation->isChecked());
|
pSettings->editor().setCompleteSingleQuote(ui->chkCompleteSingleQuotation->isChecked());
|
||||||
pSettings->editor().setRemoveMathcingSymbol(ui->chkRemoveMatchingSymbols->isChecked());
|
pSettings->editor().setRemoveSymbolPairs(ui->chkRemoveSymbolPairs->isChecked());
|
||||||
pSettings->editor().setOverwriteSymbols(ui->chkSkipMathingSymbols->isChecked());
|
pSettings->editor().setOverwriteSymbols(ui->chkSkipMathingSymbols->isChecked());
|
||||||
|
|
||||||
pSettings->editor().save();
|
pSettings->editor().save();
|
||||||
|
|
|
@ -118,13 +118,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="chkRemoveMatchingSymbols">
|
|
||||||
<property name="text">
|
|
||||||
<string>Remove matching symbols when delete chars</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -144,7 +137,7 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="2" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
|
@ -157,6 +150,13 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QCheckBox" name="chkRemoveSymbolPairs">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove symbol pairs when delete chars</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
Loading…
Reference in New Issue