- enhancement: add "editors share one code parser" in "options" / "editor" / "code completion", to reduce memory usage.

Turned off by default on PCs with memory > 4G; Force turned on PCs with memory < 1G.
  - enhancement: add "goto block start"/"goto block end" in "Code" menu
This commit is contained in:
Roy Qu 2022-10-27 15:18:57 +08:00
parent 0018ed5d7d
commit 833be397b0
19 changed files with 969 additions and 679 deletions

View File

@ -1,7 +1,10 @@
Red Panda C++ Version 2.1 Red Panda C++ Version 2.1
- editors that not in the editing panel shouldn't trigger switch breakpoint - fix: editors that not in the editing panel shouldn't trigger switch breakpoint
- editors that not in the editing panel shouldn't show context menu - fix:editors that not in the editing panel shouldn't show context menu
- enhancement: add "editors share one code parser" in "options" / "editor" / "code completion", to reduce memory usage.
Turned off by default on PCs with memory > 4G; Force turned on PCs with memory < 1G.
- enhancement: add "goto block start"/"goto block end" in "Code" menu
Red Panda C++ Version 2.0 Red Panda C++ Version 2.0

View File

@ -69,6 +69,8 @@ const char* SaveException::what() const noexcept {
return mReasonBuffer; return mReasonBuffer;
} }
std::weak_ptr<CppParser> Editor::mSharedParser;
Editor::Editor(QWidget *parent): Editor::Editor(QWidget *parent):
Editor(parent,QObject::tr("untitled"),ENCODING_AUTO_DETECT,nullptr,true,nullptr) Editor(parent,QObject::tr("untitled"),ENCODING_AUTO_DETECT,nullptr,true,nullptr)
{ {
@ -1321,6 +1323,7 @@ void Editor::showEvent(QShowEvent */*event*/)
void Editor::hideEvent(QHideEvent */*event*/) void Editor::hideEvent(QHideEvent */*event*/)
{ {
if (pSettings->codeCompletion().clearWhenEditorHidden() if (pSettings->codeCompletion().clearWhenEditorHidden()
&& !pSettings->codeCompletion().shareParser()
&& !inProject() && mParser && !inProject() && mParser
&& !pMainWindow->isMinimized()) { && !pMainWindow->isMinimized()) {
//recreate a parser, to totally clean memories the parse uses; //recreate a parser, to totally clean memories the parse uses;
@ -1833,6 +1836,16 @@ void Editor::deleteToBOL()
commandProcessor(QSynedit::EditCommand::ecDeleteBOL,QChar(),nullptr); commandProcessor(QSynedit::EditCommand::ecDeleteBOL,QChar(),nullptr);
} }
void Editor::gotoBlockStart()
{
commandProcessor(QSynedit::EditCommand::ecBlockStart,QChar(),nullptr);
}
void Editor::gotoBlockEnd()
{
commandProcessor(QSynedit::EditCommand::ecBlockEnd,QChar(),nullptr);
}
QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion( QStringList Editor::getOwnerExpressionAndMemberAtPositionForCompletion(
const QSynedit::BufferCoord &pos, const QSynedit::BufferCoord &pos,
QString &memberOperator, QString &memberOperator,
@ -2567,6 +2580,15 @@ bool Editor::handleCodeCompletion(QChar key)
void Editor::initParser() void Editor::initParser()
{ {
// mParser=nullptr; // mParser=nullptr;
if (pSettings->codeCompletion().shareParser()) {
if (pSettings->codeCompletion().enabled()
&& (highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter)
) {
mParser = sharedParser();
}
return;
}
mParser = std::make_shared<CppParser>(); mParser = std::make_shared<CppParser>();
if (mUseCppSyntax) { if (mUseCppSyntax) {
mParser->setLanguage(ParserLanguage::CPlusPlus); mParser->setLanguage(ParserLanguage::CPlusPlus);
@ -2721,11 +2743,13 @@ void Editor::reparse(bool resetParser)
return; return;
//mParser->setEnabled(pSettings->codeCompletion().enabled()); //mParser->setEnabled(pSettings->codeCompletion().enabled());
ParserLanguage language = mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C; ParserLanguage language = mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C;
if (language!=mParser->language() && !inProject()) { if (!inProject() && !pSettings->codeCompletion().shareParser()) {
mParser->setLanguage(language); if (language!=mParser->language()) {
resetCppParser(mParser); mParser->setLanguage(language);
} else if (resetParser && !inProject()) { resetCppParser(mParser);
resetCppParser(mParser); } else if (resetParser) {
resetCppParser(mParser);
}
} }
parseFile(mParser,mFilename, inProject()); parseFile(mParser,mFilename, inProject());
} }
@ -3918,6 +3942,23 @@ void Editor::onScrollBarValueChanged()
pMainWindow->functionTip()->hide(); pMainWindow->functionTip()->hide();
} }
PCppParser Editor::sharedParser()
{
PCppParser parser=mSharedParser.lock();
if (!parser) {
parser=std::make_shared<CppParser>();
parser->setLanguage(ParserLanguage::CPlusPlus);
parser->setOnGetFileStream(
std::bind(
&EditorList::getContentFromOpenedEditor,pMainWindow->editorList(),
std::placeholders::_1, std::placeholders::_2));
resetCppParser(parser);
parser->setEnabled(true);
mSharedParser=parser;
}
return parser;
}
bool Editor::canAutoSave() const bool Editor::canAutoSave() const
{ {
return mCanAutoSave; return mCanAutoSave;

View File

@ -216,6 +216,8 @@ public:
void duplicateLine(); void duplicateLine();
void deleteToEOL(); void deleteToEOL();
void deleteToBOL(); void deleteToBOL();
void gotoBlockStart();
void gotoBlockEnd();
QStringList getOwnerExpressionAndMemberAtPositionForCompletion( QStringList getOwnerExpressionAndMemberAtPositionForCompletion(
const QSynedit::BufferCoord& pos, const QSynedit::BufferCoord& pos,
@ -290,6 +292,7 @@ private:
void onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString& token, void onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString& token,
QSynedit::PHighlighterAttribute &attr); QSynedit::PHighlighterAttribute &attr);
void onScrollBarValueChanged(); void onScrollBarValueChanged();
static PCppParser sharedParser();
private: private:
QByteArray mEncodingOption; // the encoding type set by the user QByteArray mEncodingOption; // the encoding type set by the user
QByteArray mFileEncoding; // the real encoding of the file (auto detected) QByteArray mFileEncoding; // the real encoding of the file (auto detected)
@ -340,6 +343,8 @@ private:
QTimer mFunctionTipTimer; QTimer mFunctionTipTimer;
int mHoverModifiedLine; int mHoverModifiedLine;
static std::weak_ptr<CppParser> mSharedParser;
// QWidget interface // QWidget interface
protected: protected:
void wheelEvent(QWheelEvent *event) override; void wheelEvent(QWheelEvent *event) override;

View File

@ -8639,3 +8639,19 @@ bool MainWindow::isClosingAll() const
return mClosingAll; return mClosingAll;
} }
void MainWindow::on_actionGoto_block_start_triggered()
{
Editor* editor=mEditorList->getEditor();
if (editor)
editor->gotoBlockStart();
}
void MainWindow::on_actionGoto_block_end_triggered()
{
Editor* editor=mEditorList->getEditor();
if (editor)
editor->gotoBlockEnd();
}

View File

@ -728,6 +728,10 @@ private slots:
void on_actionNew_Template_triggered(); void on_actionNew_Template_triggered();
void on_actionGoto_block_start_triggered();
void on_actionGoto_block_end_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -221,6 +221,8 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionMatch_Bracket"/> <addaction name="actionMatch_Bracket"/>
<addaction name="actionGo_to_Line"/> <addaction name="actionGo_to_Line"/>
<addaction name="actionGoto_block_start"/>
<addaction name="actionGoto_block_end"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionAdd_bookmark"/> <addaction name="actionAdd_bookmark"/>
<addaction name="actionRemove_Bookmark"/> <addaction name="actionRemove_Bookmark"/>
@ -3237,6 +3239,22 @@
<string>New Template from Project</string> <string>New Template from Project</string>
</property> </property>
</action> </action>
<action name="actionGoto_block_start">
<property name="text">
<string>Goto block start</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+Up</string>
</property>
</action>
<action name="actionGoto_block_end">
<property name="text">
<string>Goto block end</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+Down</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -3691,8 +3691,14 @@ void Settings::CodeCompletion::setShowCodeIns(bool newShowCodeIns)
mShowCodeIns = newShowCodeIns; mShowCodeIns = newShowCodeIns;
} }
bool Settings::CodeCompletion::clearWhenEditorHidden() const bool Settings::CodeCompletion::clearWhenEditorHidden()
{ {
MEMORYSTATUSEX statex;
#ifdef Q_OS_WIN
if (statex.ullTotalPhys < (long long int)2*1024*1024*1024) {
mClearWhenEditorHidden = true;
}
#endif
return mClearWhenEditorHidden; return mClearWhenEditorHidden;
} }
@ -3721,6 +3727,23 @@ void Settings::CodeCompletion::setHideSymbolsStartsWithTwoUnderLine(bool newHide
mHideSymbolsStartsWithTwoUnderLine = newHideSymbolsStartsWithTwoUnderLine; mHideSymbolsStartsWithTwoUnderLine = newHideSymbolsStartsWithTwoUnderLine;
} }
bool Settings::CodeCompletion::shareParser()
{
#ifdef Q_OS_WIN
MEMORYSTATUSEX statex;
if (statex.ullTotalPhys < (long long int)1024*1024*1024) {
mShareParser = true;
}
#endif
return mShareParser;
}
void Settings::CodeCompletion::setShareParser(bool newShareParser)
{
mShareParser = newShareParser;
}
bool Settings::CodeCompletion::hideSymbolsStartsWithUnderLine() const bool Settings::CodeCompletion::hideSymbolsStartsWithUnderLine() const
{ {
return mHideSymbolsStartsWithUnderLine; return mHideSymbolsStartsWithUnderLine;
@ -3859,6 +3882,7 @@ void Settings::CodeCompletion::doSave()
saveValue("min_char_required",mMinCharRequired); saveValue("min_char_required",mMinCharRequired);
saveValue("hide_symbols_start_with_two_underline", mHideSymbolsStartsWithTwoUnderLine); saveValue("hide_symbols_start_with_two_underline", mHideSymbolsStartsWithTwoUnderLine);
saveValue("hide_symbols_start_with_underline", mHideSymbolsStartsWithUnderLine); saveValue("hide_symbols_start_with_underline", mHideSymbolsStartsWithUnderLine);
saveValue("share_parser",mShareParser);
} }
@ -3896,11 +3920,18 @@ void Settings::CodeCompletion::doLoad()
mClearWhenEditorHidden = boolValue("clear_when_editor_hidden",doClear); mClearWhenEditorHidden = boolValue("clear_when_editor_hidden",doClear);
bool shouldShare=true;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (statex.ullAvailPhys < (long long int)1024*1024*1024) { statex.dwLength = sizeof (statex);
mClearWhenEditorHidden = true;
GlobalMemoryStatusEx (&statex);
if (statex.ullAvailPhys > (long long int)4*1024*1024*1024) {
shouldShare = false;
} }
#endif #endif
mShareParser = boolValue("share_parser",shouldShare);
} }
Settings::CodeFormatter::CodeFormatter(Settings *settings): Settings::CodeFormatter::CodeFormatter(Settings *settings):

View File

@ -602,7 +602,7 @@ public:
bool showCodeIns() const; bool showCodeIns() const;
void setShowCodeIns(bool newShowCodeIns); void setShowCodeIns(bool newShowCodeIns);
bool clearWhenEditorHidden() const; bool clearWhenEditorHidden();
void setClearWhenEditorHidden(bool newClearWhenEditorHidden); void setClearWhenEditorHidden(bool newClearWhenEditorHidden);
int minCharRequired() const; int minCharRequired() const;
@ -614,6 +614,9 @@ public:
bool hideSymbolsStartsWithTwoUnderLine() const; bool hideSymbolsStartsWithTwoUnderLine() const;
void setHideSymbolsStartsWithTwoUnderLine(bool newHideSymbolsStartsWithTwoUnderLine); void setHideSymbolsStartsWithTwoUnderLine(bool newHideSymbolsStartsWithTwoUnderLine);
bool shareParser();
void setShareParser(bool newShareParser);
private: private:
int mWidth; int mWidth;
int mHeight; int mHeight;
@ -627,10 +630,11 @@ public:
bool mIgnoreCase; bool mIgnoreCase;
bool mAppendFunc; bool mAppendFunc;
bool mShowCodeIns; bool mShowCodeIns;
bool mClearWhenEditorHidden;
int mMinCharRequired; int mMinCharRequired;
bool mHideSymbolsStartsWithTwoUnderLine; bool mHideSymbolsStartsWithTwoUnderLine;
bool mHideSymbolsStartsWithUnderLine; bool mHideSymbolsStartsWithUnderLine;
bool mClearWhenEditorHidden;
bool mShareParser;
// _Base interface // _Base interface
protected: protected:

View File

@ -54,6 +54,7 @@ void EditorCodeCompletionWidget::doLoad()
ui->chkHideSymbolsStartWithTwoUnderline->setChecked(pSettings->codeCompletion().hideSymbolsStartsWithTwoUnderLine()); ui->chkHideSymbolsStartWithTwoUnderline->setChecked(pSettings->codeCompletion().hideSymbolsStartsWithTwoUnderLine());
ui->chkHideSymbolsStartWithUnderline->setChecked(pSettings->codeCompletion().hideSymbolsStartsWithUnderLine()); ui->chkHideSymbolsStartWithUnderline->setChecked(pSettings->codeCompletion().hideSymbolsStartsWithUnderLine());
ui->chkEditorShareCodeParser->setChecked(pSettings->codeCompletion().shareParser());
ui->spinMinCharRequired->setValue(pSettings->codeCompletion().minCharRequired()); ui->spinMinCharRequired->setValue(pSettings->codeCompletion().minCharRequired());
} }
@ -82,6 +83,8 @@ void EditorCodeCompletionWidget::doSave()
pSettings->codeCompletion().setHideSymbolsStartsWithTwoUnderLine(ui->chkHideSymbolsStartWithTwoUnderline->isChecked()); pSettings->codeCompletion().setHideSymbolsStartsWithTwoUnderLine(ui->chkHideSymbolsStartWithTwoUnderline->isChecked());
pSettings->codeCompletion().setHideSymbolsStartsWithUnderLine(ui->chkHideSymbolsStartWithUnderline->isChecked()); pSettings->codeCompletion().setHideSymbolsStartsWithUnderLine(ui->chkHideSymbolsStartWithUnderline->isChecked());
pSettings->codeCompletion().setShareParser(ui->chkEditorShareCodeParser->isChecked());
pSettings->codeCompletion().save(); pSettings->codeCompletion().save();
} }

View File

@ -74,6 +74,13 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="chkEditorShareCodeParser">
<property name="text">
<string>Editors share one code parser</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="chkClearWhenEditorHidden"> <widget class="QCheckBox" name="chkClearWhenEditorHidden">
<property name="text"> <property name="text">

View File

@ -39,17 +39,26 @@ void EnvironmentPerformanceWidget::doLoad()
statex.dwLength = sizeof (statex); statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex); GlobalMemoryStatusEx (&statex);
if (statex.ullAvailPhys < (long long int)1024*1024*1024) { if (statex.ullTotalPhys < (long long int)2*1024*1024*1024) {
ui->chkClearWhenEditorHidden->setEnabled(false); ui->chkClearWhenEditorHidden->setEnabled(false);
ui->chkClearWhenEditorHidden->setChecked(true); ui->chkClearWhenEditorHidden->setChecked(true);
pSettings->codeCompletion().setClearWhenEditorHidden(true); pSettings->codeCompletion().setClearWhenEditorHidden(true);
pSettings->codeCompletion().save();
}
if (statex.ullTotalPhys < (long long int)1024*1024*1024) {
ui->chkEditorsShareParser->setEnabled(false);
ui->chkEditorsShareParser->setChecked(true);
pSettings->codeCompletion().setShareParser(true);
pSettings->codeCompletion().save();
} }
#endif #endif
ui->chkEditorsShareParser->setChecked(pSettings->codeCompletion().shareParser());
} }
void EnvironmentPerformanceWidget::doSave() void EnvironmentPerformanceWidget::doSave()
{ {
pSettings->codeCompletion().setClearWhenEditorHidden(ui->chkClearWhenEditorHidden->isChecked()); pSettings->codeCompletion().setClearWhenEditorHidden(ui->chkClearWhenEditorHidden->isChecked());
pSettings->codeCompletion().setShareParser(ui->chkEditorsShareParser->isChecked());
pSettings->codeCompletion().save(); pSettings->codeCompletion().save();
} }

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>431</width>
<height>300</height> <height>300</height>
</rect> </rect>
</property> </property>
@ -20,13 +20,20 @@
<string>Reduce Memory Usage</string> <string>Reduce Memory Usage</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="1" column="0">
<widget class="QCheckBox" name="chkClearWhenEditorHidden"> <widget class="QCheckBox" name="chkClearWhenEditorHidden">
<property name="text"> <property name="text">
<string>Auto clear parsed symbols when editor hidden</string> <string>Auto clear parsed symbols when editor hidden</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QCheckBox" name="chkEditorsShareParser">
<property name="text">
<string>Editors share one code parser</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -1179,6 +1179,10 @@
<source>Enable code competion</source> <source>Enable code competion</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Editors share one code parser</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>EditorColorSchemeWidget</name> <name>EditorColorSchemeWidget</name>
@ -1707,6 +1711,10 @@
<source>Auto clear parsed symbols when editor hidden</source> <source>Auto clear parsed symbols when editor hidden</source>
<translation>Limpar automaticamente símbolos verificados quando editor oculto</translation> <translation>Limpar automaticamente símbolos verificados quando editor oculto</translation>
</message> </message>
<message>
<source>Editors share one code parser</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>EnvironmentProgramsWidget</name> <name>EnvironmentProgramsWidget</name>
@ -4688,6 +4696,22 @@
<source>In current project</source> <source>In current project</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Goto block start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+Alt+Up</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Goto block end</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+Alt+Down</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>NewClassDialog</name> <name>NewClassDialog</name>
@ -4838,7 +4862,7 @@
</message> </message>
<message> <message>
<source>untitled</source> <source>untitled</source>
<translation>sem nome</translation> <translation type="vanished">sem nome</translation>
</message> </message>
<message> <message>
<source>Choose directory</source> <source>Choose directory</source>
@ -6623,7 +6647,7 @@
</message> </message>
<message> <message>
<source>Column</source> <source>Column</source>
<translation>Coluna</translation> <translation type="vanished">Coluna</translation>
</message> </message>
<message> <message>
<source>Content</source> <source>Content</source>

File diff suppressed because it is too large Load Diff

View File

@ -1076,6 +1076,10 @@
<source>Completion suggestion window height:</source> <source>Completion suggestion window height:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Editors share one code parser</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>EditorColorSchemeWidget</name> <name>EditorColorSchemeWidget</name>
@ -1600,6 +1604,10 @@
<source>Auto clear parsed symbols when editor hidden</source> <source>Auto clear parsed symbols when editor hidden</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Editors share one code parser</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>EnvironmentProgramsWidget</name> <name>EnvironmentProgramsWidget</name>
@ -4541,6 +4549,22 @@
<source>In current project</source> <source>In current project</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Goto block start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+Alt+Up</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Goto block end</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ctrl+Alt+Down</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>NewClassDialog</name> <name>NewClassDialog</name>
@ -4689,10 +4713,6 @@
<source>Cancel</source> <source>Cancel</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>untitled</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Choose directory</source> <source>Choose directory</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -6384,10 +6404,6 @@
<source>Line</source> <source>Line</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Column</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Content</source> <source>Content</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>

View File

@ -198,6 +198,11 @@ void EditKeyStrokes::resetDefaults()
add(EditCommand::ecWordRight, Qt::Key_Right, Qt::ControlModifier); add(EditCommand::ecWordRight, Qt::Key_Right, Qt::ControlModifier);
add(EditCommand::ecSelWordRight, Qt::Key_Right, Qt::ShiftModifier|Qt::ControlModifier); add(EditCommand::ecSelWordRight, Qt::Key_Right, Qt::ShiftModifier|Qt::ControlModifier);
add(EditCommand::ecBlockStart, Qt::Key_Up, Qt::MetaModifier|Qt::ControlModifier);
add(EditCommand::ecSelBlockStart, Qt::Key_Up, Qt::ShiftModifier|Qt::ControlModifier|Qt::MetaModifier);
add(EditCommand::ecBlockEnd, Qt::Key_Down, Qt::MetaModifier|Qt::ControlModifier);
add(EditCommand::ecSelBlockEnd, Qt::Key_Down, Qt::ShiftModifier|Qt::ControlModifier|Qt::MetaModifier);
// add(SynEditorCommand::ecExpandSelection, Qt::Key_Right, Qt::ShiftModifier|Qt::AltModifier); // add(SynEditorCommand::ecExpandSelection, Qt::Key_Right, Qt::ShiftModifier|Qt::AltModifier);
// add(SynEditorCommand::ecShrinkSelection, Qt::Key_Left, Qt::ShiftModifier | Qt::AltModifier); // add(SynEditorCommand::ecShrinkSelection, Qt::Key_Left, Qt::ShiftModifier | Qt::AltModifier);

View File

@ -62,6 +62,8 @@ enum class EditCommand {
ecEditorStart = 15, // Move cursor to absolute beginning ecEditorStart = 15, // Move cursor to absolute beginning
ecEditorEnd = 16, // Move cursor to absolute end ecEditorEnd = 16, // Move cursor to absolute end
ecGotoXY = 17, // Move cursor to specific coordinates, Data = PPoint ecGotoXY = 17, // Move cursor to specific coordinates, Data = PPoint
ecBlockStart = 18, // Move cursor to begin of block
ecBlockEnd = 19, // Move cursor to end of block
//****************************************************************************** //******************************************************************************
// Maybe the command processor should just take a boolean that signifies if // Maybe the command processor should just take a boolean that signifies if
@ -89,6 +91,8 @@ enum class EditCommand {
ecSelEditorStart = ecEditorStart + ecSelection, ecSelEditorStart = ecEditorStart + ecSelection,
ecSelEditorEnd = ecEditorEnd + ecSelection, ecSelEditorEnd = ecEditorEnd + ecSelection,
ecSelGotoXY = ecGotoXY + ecSelection, // Data = PPoint ecSelGotoXY = ecGotoXY + ecSelection, // Data = PPoint
ecSelBlockStart = ecBlockStart + ecSelection, // Move cursor to begin of scope
ecSelBlockEnd = ecBlockEnd + ecSelection, // Move cursor to end of scope
ecCopy = 201, // Copy selection to clipboard ecCopy = 201, // Copy selection to clipboard

View File

@ -5054,6 +5054,64 @@ void SynEdit::moveCaretToLineEnd(bool isSelection)
moveCaretAndSelection(caretXY(), BufferCoord{vNewX, mCaretY}, isSelection); moveCaretAndSelection(caretXY(), BufferCoord{vNewX, mCaretY}, isSelection);
} }
void SynEdit::doGotoBlockStart(bool isSelection)
{
if (mCaretY<0 || mCaretY>document()->count())
return;
HighlighterState state = document()->ranges(mCaretY-1);
//todo: handle block other than {}
if (document()->braceLevels(mCaretY-1)==0) {
doGotoEditorStart(isSelection);
} else if (document()->leftBraces(mCaretY-1)==0){
int line=mCaretY-1;
while (line>=1) {
if (document()->leftBraces(line-1)>document()->rightBraces(line-1)) {
moveCaretVert(line+1-mCaretY, isSelection);
moveCaretToLineStart(isSelection);
setTopLine(line-1);
return;
}
line--;
}
}
}
void SynEdit::doGotoBlockEnd(bool isSelection)
{
if (mCaretY<0 || mCaretY>document()->count())
return;
HighlighterState state = document()->ranges(mCaretY-1);
//todo: handle block other than {}
if (document()->braceLevels(mCaretY-1)==0) {
doGotoEditorEnd(isSelection);
} else if (document()->rightBraces(mCaretY-1)==0){
int line=mCaretY+1;
while (line<=document()->count()) {
if (document()->rightBraces(line-1)>document()->leftBraces(line-1)) {
moveCaretVert(line-1-mCaretY, isSelection);
moveCaretToLineStart(isSelection);
setTopLine(line-mLinesInWindow+1);
return;
}
line++;
}
}
}
void SynEdit::doGotoEditorStart(bool isSelection)
{
moveCaretVert(1-mCaretY, isSelection);
moveCaretToLineStart(isSelection);
}
void SynEdit::doGotoEditorEnd(bool isSelection)
{
if (!mDocument->empty()) {
moveCaretVert(mDocument->count()-mCaretY, isSelection);
moveCaretToLineEnd(isSelection);
}
}
void SynEdit::setSelectedTextEmpty() void SynEdit::setSelectedTextEmpty()
{ {
BufferCoord startPos=blockBegin(); BufferCoord startPos=blockBegin();
@ -5722,7 +5780,7 @@ void SynEdit::onCommandProcessed(EditCommand , QChar , void *)
} }
void SynEdit::executeCommand(EditCommand Command, QChar AChar, void *pData) void SynEdit::executeCommand(EditCommand command, QChar ch, void *pData)
{ {
hideCaret(); hideCaret();
incPaintLock(); incPaintLock();
@ -5731,40 +5789,40 @@ void SynEdit::executeCommand(EditCommand Command, QChar AChar, void *pData)
decPaintLock(); decPaintLock();
showCaret(); showCaret();
}); });
switch(Command) { switch(command) {
//horizontal caret movement or selection //horizontal caret movement or selection
case EditCommand::ecLeft: case EditCommand::ecLeft:
case EditCommand::ecSelLeft: case EditCommand::ecSelLeft:
moveCaretHorz(-1, Command == EditCommand::ecSelLeft); moveCaretHorz(-1, command == EditCommand::ecSelLeft);
break; break;
case EditCommand::ecRight: case EditCommand::ecRight:
case EditCommand::ecSelRight: case EditCommand::ecSelRight:
moveCaretHorz(1, Command == EditCommand::ecSelRight); moveCaretHorz(1, command == EditCommand::ecSelRight);
break; break;
case EditCommand::ecPageLeft: case EditCommand::ecPageLeft:
case EditCommand::ecSelPageLeft: case EditCommand::ecSelPageLeft:
moveCaretHorz(-mCharsInWindow, Command == EditCommand::ecSelPageLeft); moveCaretHorz(-mCharsInWindow, command == EditCommand::ecSelPageLeft);
break; break;
case EditCommand::ecPageRight: case EditCommand::ecPageRight:
case EditCommand::ecSelPageRight: case EditCommand::ecSelPageRight:
moveCaretHorz(mCharsInWindow, Command == EditCommand::ecSelPageRight); moveCaretHorz(mCharsInWindow, command == EditCommand::ecSelPageRight);
break; break;
case EditCommand::ecLineStart: case EditCommand::ecLineStart:
case EditCommand::ecSelLineStart: case EditCommand::ecSelLineStart:
moveCaretToLineStart(Command == EditCommand::ecSelLineStart); moveCaretToLineStart(command == EditCommand::ecSelLineStart);
break; break;
case EditCommand::ecLineEnd: case EditCommand::ecLineEnd:
case EditCommand::ecSelLineEnd: case EditCommand::ecSelLineEnd:
moveCaretToLineEnd(Command == EditCommand::ecSelLineEnd); moveCaretToLineEnd(command == EditCommand::ecSelLineEnd);
break; break;
// vertical caret movement or selection // vertical caret movement or selection
case EditCommand::ecUp: case EditCommand::ecUp:
case EditCommand::ecSelUp: case EditCommand::ecSelUp:
moveCaretVert(-1, Command == EditCommand::ecSelUp); moveCaretVert(-1, command == EditCommand::ecSelUp);
break; break;
case EditCommand::ecDown: case EditCommand::ecDown:
case EditCommand::ecSelDown: case EditCommand::ecSelDown:
moveCaretVert(1, Command == EditCommand::ecSelDown); moveCaretVert(1, command == EditCommand::ecSelDown);
break; break;
case EditCommand::ecPageUp: case EditCommand::ecPageUp:
case EditCommand::ecSelPageUp: case EditCommand::ecSelPageUp:
@ -5779,51 +5837,55 @@ void SynEdit::executeCommand(EditCommand Command, QChar AChar, void *pData)
} }
if (counter<0) if (counter<0)
break; break;
if (Command == EditCommand::ecPageUp || Command == EditCommand::ecSelPageUp) { if (command == EditCommand::ecPageUp || command == EditCommand::ecSelPageUp) {
counter = -counter; counter = -counter;
} }
moveCaretVert(counter, Command == EditCommand::ecSelPageUp || Command == EditCommand::ecSelPageDown); moveCaretVert(counter, command == EditCommand::ecSelPageUp || command == EditCommand::ecSelPageDown);
break; break;
} }
case EditCommand::ecPageTop: case EditCommand::ecPageTop:
case EditCommand::ecSelPageTop: case EditCommand::ecSelPageTop:
moveCaretVert(mTopLine-mCaretY, Command == EditCommand::ecSelPageTop); moveCaretVert(mTopLine-mCaretY, command == EditCommand::ecSelPageTop);
break; break;
case EditCommand::ecPageBottom: case EditCommand::ecPageBottom:
case EditCommand::ecSelPageBottom: case EditCommand::ecSelPageBottom:
moveCaretVert(mTopLine+mLinesInWindow-1-mCaretY, Command == EditCommand::ecSelPageBottom); moveCaretVert(mTopLine+mLinesInWindow-1-mCaretY, command == EditCommand::ecSelPageBottom);
break; break;
case EditCommand::ecEditorStart: case EditCommand::ecEditorStart:
case EditCommand::ecSelEditorStart: case EditCommand::ecSelEditorStart:
moveCaretVert(1-mCaretY, Command == EditCommand::ecSelEditorStart); doGotoEditorStart(command == EditCommand::ecSelEditorStart);
moveCaretToLineStart(Command == EditCommand::ecSelEditorStart);
break; break;
case EditCommand::ecEditorEnd: case EditCommand::ecEditorEnd:
case EditCommand::ecSelEditorEnd: case EditCommand::ecSelEditorEnd:
if (!mDocument->empty()) { doGotoEditorEnd(command == EditCommand::ecSelEditorEnd);
moveCaretVert(mDocument->count()-mCaretY, Command == EditCommand::ecSelEditorEnd); break;
moveCaretToLineEnd(Command == EditCommand::ecSelEditorEnd); case EditCommand::ecBlockStart:
} case EditCommand::ecSelBlockStart:
doGotoBlockStart(command == EditCommand::ecSelBlockStart);
break;
case EditCommand::ecBlockEnd:
case EditCommand::ecSelBlockEnd:
doGotoBlockEnd(command == EditCommand::ecSelBlockEnd);
break; break;
// goto special line / column position // goto special line / column position
case EditCommand::ecGotoXY: case EditCommand::ecGotoXY:
case EditCommand::ecSelGotoXY: case EditCommand::ecSelGotoXY:
if (pData) if (pData)
moveCaretAndSelection(caretXY(), *((BufferCoord *)(pData)), Command == EditCommand::ecSelGotoXY); moveCaretAndSelection(caretXY(), *((BufferCoord *)(pData)), command == EditCommand::ecSelGotoXY);
break; break;
// word selection // word selection
case EditCommand::ecWordLeft: case EditCommand::ecWordLeft:
case EditCommand::ecSelWordLeft: case EditCommand::ecSelWordLeft:
{ {
BufferCoord CaretNew = prevWordPos(); BufferCoord CaretNew = prevWordPos();
moveCaretAndSelection(caretXY(), CaretNew, Command == EditCommand::ecSelWordLeft); moveCaretAndSelection(caretXY(), CaretNew, command == EditCommand::ecSelWordLeft);
break; break;
} }
case EditCommand::ecWordRight: case EditCommand::ecWordRight:
case EditCommand::ecSelWordRight: case EditCommand::ecSelWordRight:
{ {
BufferCoord CaretNew = nextWordPos(); BufferCoord CaretNew = nextWordPos();
moveCaretAndSelection(caretXY(), CaretNew, Command == EditCommand::ecSelWordRight); moveCaretAndSelection(caretXY(), CaretNew, command == EditCommand::ecSelWordRight);
break; break;
} }
case EditCommand::ecSelWord: case EditCommand::ecSelWord:
@ -5895,7 +5957,7 @@ void SynEdit::executeCommand(EditCommand Command, QChar AChar, void *pData)
doShiftTabKey(); doShiftTabKey();
break; break;
case EditCommand::ecChar: case EditCommand::ecChar:
doAddChar(AChar); doAddChar(ch);
break; break;
case EditCommand::ecInsertMode: case EditCommand::ecInsertMode:
if (!mReadOnly) if (!mReadOnly)

View File

@ -466,9 +466,9 @@ protected:
virtual void onPreparePaintHighlightToken(int line, virtual void onPreparePaintHighlightToken(int line,
int aChar, const QString& token, PHighlighterAttribute attr, int aChar, const QString& token, PHighlighterAttribute attr,
FontStyles& style, QColor& foreground, QColor& background); FontStyles& style, QColor& foreground, QColor& background);
virtual void onProcessCommand(EditCommand Command, QChar AChar, void * pData); virtual void onProcessCommand(EditCommand command, QChar car, void * pData);
virtual void onCommandProcessed(EditCommand Command, QChar AChar, void * pData); virtual void onCommandProcessed(EditCommand command, QChar car, void * pData);
virtual void executeCommand(EditCommand Command, QChar AChar, void * pData); virtual void executeCommand(EditCommand command, QChar ch, void * pData);
virtual void onEndFirstPaintLock(); virtual void onEndFirstPaintLock();
virtual void onBeginFirstPaintLock(); virtual void onBeginFirstPaintLock();
@ -540,6 +540,10 @@ private:
bool isSelection); bool isSelection);
void moveCaretToLineStart(bool isSelection); void moveCaretToLineStart(bool isSelection);
void moveCaretToLineEnd(bool isSelection); void moveCaretToLineEnd(bool isSelection);
void doGotoBlockStart(bool isSelection);
void doGotoBlockEnd(bool isSelection);
void doGotoEditorStart(bool isSelection);
void doGotoEditorEnd(bool isSelection);
void setSelectedTextEmpty(); void setSelectedTextEmpty();
void setSelTextPrimitive(const QStringList& text); void setSelTextPrimitive(const QStringList& text);
void setSelTextPrimitiveEx(SelectionMode PasteMode, void setSelTextPrimitiveEx(SelectionMode PasteMode,