- use QMutex instead of QRecursiveMutex in SynEdit

- Can use tab / shift-tab as shortcut for indent/unindent
This commit is contained in:
royqh1979@gmail.com 2021-10-06 23:35:45 +08:00
parent 48e97dc15d
commit 3e8200d307
6 changed files with 47 additions and 25 deletions

View File

@ -578,21 +578,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
pMainWindow->functionTip()->hide();
return;
case Qt::Key_Tab:
if (mUserCodeInTabStops.count()>0) {
handled = true;
int oldLine = caretY();
popUserCodeInTabStops();
if (oldLine!=caretY()) {
invalidateLine(oldLine);
}
invalidateLine(caretY());
} else {
if (mTabStopBegin >= 0) {
handled = true;
mTabStopBegin = -1;
invalidateLine(caretY());
}
}
tab();
return;
case Qt::Key_Up:
if (pMainWindow->functionTip()->isVisible()) {
@ -3177,6 +3163,26 @@ const PCppParser &Editor::parser()
return mParser;
}
void Editor::tab()
{
if (mUserCodeInTabStops.count()>0) {
int oldLine = caretY();
popUserCodeInTabStops();
if (oldLine!=caretY()) {
invalidateLine(oldLine);
}
invalidateLine(caretY());
return;
} else {
if (mTabStopBegin >= 0) {
mTabStopBegin = -1;
invalidateLine(caretY());
return;
}
}
SynEdit::tab();
}
int Editor::gutterClickedLine() const
{
return mGutterClickedLine;

View File

@ -161,6 +161,8 @@ public:
const PCppParser &parser();
void tab() override;
private slots:
void onModificationChanged(bool status) ;
void onStatusChanged(SynStatusChanges changes);

View File

@ -2899,7 +2899,7 @@ void MainWindow::on_actionUnIndent_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
editor->untab();
editor->shifttab();
}
}

View File

@ -1264,6 +1264,9 @@
<property name="text">
<string>Indent</string>
</property>
<property name="shortcut">
<string>Tab</string>
</property>
</action>
<action name="actionUnIndent">
<property name="icon">
@ -1274,6 +1277,9 @@
<property name="text">
<string>UnIndent</string>
</property>
<property name="shortcut">
<string>Shift+Tab</string>
</property>
</action>
<action name="actionToggleComment">
<property name="text">

View File

@ -2387,7 +2387,7 @@ void SynEdit::doAddChar(QChar AChar)
}
}
}
setSelText(AChar);
doSetSelText(AChar);
mUndoList->EndBlock();
//DoOnPaintTransient(ttAfter);
@ -2402,7 +2402,7 @@ void SynEdit::doCutToClipboard()
mUndoList->EndBlock();
});
internalDoCopyToClipboard(selText());
setSelText("");
doSetSelText("");
}
void SynEdit::doCopyToClipboard()
@ -3535,7 +3535,7 @@ void SynEdit::doAddStr(const QString &s)
BE.Char = BB.Char + s.length();
setCaretAndSelection(caretXY(),BB,BE);
}
setSelText(s);
doSetSelText(s);
}
void SynEdit::doUndo()
@ -4330,9 +4330,8 @@ void SynEdit::setSelTextPrimitiveEx(SynSelectionMode PasteMode, const QString &V
internalSetCaretY(1);
}
void SynEdit::setSelText(const QString &Value)
void SynEdit::doSetSelText(const QString &Value)
{
QMutexLocker locker(&mMutex);
mUndoList->BeginBlock();
auto action = finally([this]{
mUndoList->EndBlock();
@ -4494,7 +4493,7 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS
mUndoList->BeginBlock();
dobatchReplace = true;
}
setSelText(replaceText);
doSetSelText(replaceText);
nReplaceLen = caretX() - nFound;
// fix the caret position and the remaining results
if (!bBackward) {
@ -5906,6 +5905,13 @@ void SynEdit::setSelLength(int Value)
}
}
void SynEdit::setSelText(const QString &text)
{
QMutexLocker locker(&mMutex);
doSetSelText(text);
}
BufferCoord SynEdit::blockBegin() const
{
if ((mBlockEnd.Line < mBlockBegin.Line)

View File

@ -221,8 +221,8 @@ public:
void uncollapseAroundLine(int line);
PSynEditFoldRange foldHidesLine(int line);
void setSelText(const QString& Value);
void setSelLength(int Value);
void setSelText(const QString& text);
int searchReplace(const QString& sSearch, const QString& sReplace, SynSearchOptions options,
PSynSearchBase searchEngine, SynSearchMathedProc matchedCallback = nullptr);
@ -249,7 +249,7 @@ public:
virtual void zoomOut() { commandProcessor(SynEditorCommand::ecZoomOut);}
virtual void selectAll() { commandProcessor(SynEditorCommand::ecSelectAll);}
virtual void tab() { commandProcessor(SynEditorCommand::ecTab);}
virtual void untab() { commandProcessor(SynEditorCommand::ecShiftTab);}
virtual void shifttab() { commandProcessor(SynEditorCommand::ecShiftTab);}
virtual void toggleComment() { commandProcessor(SynEditorCommand::ecToggleComment);}
virtual void beginUpdate();
@ -432,6 +432,8 @@ private:
QRect clientRect();
void synFontChanged();
void doOnPaintTransient(SynTransientType TransientType);
void doSetSelText(const QString& Value);
void updateLastCaretX();
void ensureCursorPosVisible();
void ensureCursorPosVisibleEx(bool ForceToMiddle);
@ -675,7 +677,7 @@ private:
QString mInputPreeditString;
QRecursiveMutex mMutex;
QMutex mMutex;
friend class SynEditTextPainter;