* 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;
|
||||
}
|
||||
|
||||
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) {
|
||||
if ( (event->modifiers() & Qt::ControlModifier)!=0) {
|
||||
int size = pSettings->editor().fontSize();
|
||||
|
@ -250,24 +300,38 @@ void Editor::focusOutEvent(QFocusEvent *event)
|
|||
void Editor::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
bool handled = false;
|
||||
QString t = event->text();
|
||||
if (!t.isEmpty()) {
|
||||
QChar ch = t[0];
|
||||
switch (ch.unicode()) {
|
||||
case '"':
|
||||
case '\'':
|
||||
case '(':
|
||||
case ')':
|
||||
case '{':
|
||||
case '}':
|
||||
case '[':
|
||||
case ']':
|
||||
case '<':
|
||||
case '>':
|
||||
case '*':
|
||||
handled = handleSymbolCompletion(ch);
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Delete:
|
||||
// remove completed character
|
||||
//fLastIdCharPressed:=0;
|
||||
undoSymbolCompletion(caretX());
|
||||
break;;
|
||||
case Qt::Key_Backspace:
|
||||
// remove completed character
|
||||
//fLastIdCharPressed:=0;
|
||||
undoSymbolCompletion(caretX()-1);
|
||||
break;;
|
||||
default: {
|
||||
QString t = event->text();
|
||||
if (!t.isEmpty()) {
|
||||
QChar ch = t[0];
|
||||
switch (ch.unicode()) {
|
||||
case '"':
|
||||
case '\'':
|
||||
case '(':
|
||||
case ')':
|
||||
case '{':
|
||||
case '}':
|
||||
case '[':
|
||||
case ']':
|
||||
case '<':
|
||||
case '>':
|
||||
case '*':
|
||||
handled = handleSymbolCompletion(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!handled) {
|
||||
SynEdit::keyPressEvent(event);
|
||||
} else {
|
||||
|
@ -676,7 +740,7 @@ bool Editor::handleSingleQuoteCompletion()
|
|||
}
|
||||
} else {
|
||||
if (status == QuoteStatus::NotQuote) {
|
||||
if (highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
||||
if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
||||
// insert ''
|
||||
beginUpdate();
|
||||
CommandProcessor(SynEditorCommand::ecChar,'\'');
|
||||
|
@ -696,13 +760,13 @@ bool Editor::handleDoubleQuoteCompletion()
|
|||
QuoteStatus status = getQuoteStatus();
|
||||
QChar ch = getCurrentChar();
|
||||
if (ch == '"') {
|
||||
if (status == QuoteStatus::DoubleQuote && status == QuoteStatus::RawString) {
|
||||
if (status == QuoteStatus::DoubleQuote || status == QuoteStatus::RawString) {
|
||||
setCaretXY( BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (status == QuoteStatus::NotQuote) {
|
||||
if (highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
||||
if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
||||
// insert ""
|
||||
beginUpdate();
|
||||
CommandProcessor(SynEditorCommand::ecChar,'"');
|
||||
|
@ -759,7 +823,7 @@ Editor::QuoteStatus Editor::getQuoteStatus()
|
|||
if (posX >= Line.length()) {
|
||||
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)) {
|
||||
Result = QuoteStatus::RawString;
|
||||
i++; // skip R
|
||||
|
|
|
@ -103,6 +103,7 @@ private:
|
|||
bool handleDoubleQuoteCompletion();
|
||||
bool handleGlobalIncludeCompletion();
|
||||
bool handleGlobalIncludeSkip();
|
||||
void undoSymbolCompletion(int pos);
|
||||
QuoteStatus getQuoteStatus();
|
||||
|
||||
private:
|
||||
|
|
|
@ -4059,8 +4059,8 @@ void SynEdit::SetSelTextPrimitiveEx(SynSelectionMode PasteMode, const QString &V
|
|||
mLines->endUpdate();
|
||||
decPaintLock();
|
||||
});
|
||||
BufferCoord BB = mBlockBegin;
|
||||
BufferCoord BE = mBlockEnd;
|
||||
BufferCoord BB = blockBegin();
|
||||
BufferCoord BE = blockEnd();
|
||||
if (selAvail()) {
|
||||
DeleteSelection(BB,BE);
|
||||
internalSetCaretXY(BB);
|
||||
|
|
|
@ -293,14 +293,14 @@ void Settings::Editor::setColorScheme(const QString &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
|
||||
|
@ -721,7 +721,7 @@ void Settings::Editor::doSave()
|
|||
saveValue("complete_double_quote", mCompleteDoubleQuote);
|
||||
saveValue("complete_global_include", mCompleteGlobalInclude);
|
||||
saveValue("overwrite_symbols", mOverwriteSymbols);
|
||||
saveValue("remove_matching_symbols",mRemoveMathcingSymbol);
|
||||
saveValue("remove_symbol_pairs",mRemoveSymbolPairs);
|
||||
}
|
||||
|
||||
void Settings::Editor::doLoad()
|
||||
|
@ -794,7 +794,7 @@ void Settings::Editor::doLoad()
|
|||
mCompleteDoubleQuote = boolValue("complete_double_quote",true);
|
||||
mCompleteGlobalInclude = boolValue("complete_global_include",true);
|
||||
mOverwriteSymbols = boolValue("overwrite_symbols",true);
|
||||
mRemoveMathcingSymbol = boolValue("remove_matching_symbols",true);
|
||||
mRemoveSymbolPairs = boolValue("remove_symbol_pairs",true);
|
||||
}
|
||||
|
||||
SynEditCaretType Settings::Editor::caretForOverwrite() const
|
||||
|
|
|
@ -245,8 +245,8 @@ public:
|
|||
bool overwriteSymbols() const;
|
||||
void setOverwriteSymbols(bool overwriteSymbols);
|
||||
|
||||
bool removeMathcingSymbol() const;
|
||||
void setRemoveMathcingSymbol(bool removeMathcingSymbol);
|
||||
bool removeSymbolPairs() const;
|
||||
void setRemoveSymbolPairs(bool value);
|
||||
|
||||
private:
|
||||
QByteArray mDefaultEncoding;
|
||||
|
@ -317,7 +317,7 @@ public:
|
|||
bool mCompleteDoubleQuote;
|
||||
bool mCompleteGlobalInclude;
|
||||
bool mOverwriteSymbols;
|
||||
bool mRemoveMathcingSymbol;
|
||||
bool mRemoveSymbolPairs;
|
||||
|
||||
// _Base interface
|
||||
protected:
|
||||
|
|
|
@ -24,7 +24,7 @@ void EditorSymbolCompletionWidget::doLoad()
|
|||
ui->chkCompleteGlobalInclude->setChecked(pSettings->editor().completeGlobalInclude());
|
||||
ui->chkCompleteParenthesis->setChecked(pSettings->editor().completeParenthese());
|
||||
ui->chkCompleteSingleQuotation->setChecked(pSettings->editor().completeSingleQuote());
|
||||
ui->chkRemoveMatchingSymbols->setChecked(pSettings->editor().removeMathcingSymbol());
|
||||
ui->chkRemoveSymbolPairs->setChecked(pSettings->editor().removeSymbolPairs());
|
||||
ui->chkSkipMathingSymbols->setChecked(pSettings->editor().overwriteSymbols());
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ void EditorSymbolCompletionWidget::doSave()
|
|||
pSettings->editor().setCompleteGlobalInclude(ui->chkCompleteGlobalInclude->isChecked());
|
||||
pSettings->editor().setCompleteParenthese(ui->chkCompleteParenthesis->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().save();
|
||||
|
|
|
@ -118,13 +118,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkRemoveMatchingSymbols">
|
||||
<property name="text">
|
||||
<string>Remove matching symbols when delete chars</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -144,7 +137,7 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
@ -157,6 +150,13 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
|
Loading…
Reference in New Issue