- 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:
parent
0018ed5d7d
commit
833be397b0
7
NEWS.md
7
NEWS.md
|
@ -1,7 +1,10 @@
|
|||
Red Panda C++ Version 2.1
|
||||
|
||||
- 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 trigger switch breakpoint
|
||||
- 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
|
||||
|
|
|
@ -69,6 +69,8 @@ const char* SaveException::what() const noexcept {
|
|||
return mReasonBuffer;
|
||||
}
|
||||
|
||||
std::weak_ptr<CppParser> Editor::mSharedParser;
|
||||
|
||||
Editor::Editor(QWidget *parent):
|
||||
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*/)
|
||||
{
|
||||
if (pSettings->codeCompletion().clearWhenEditorHidden()
|
||||
&& !pSettings->codeCompletion().shareParser()
|
||||
&& !inProject() && mParser
|
||||
&& !pMainWindow->isMinimized()) {
|
||||
//recreate a parser, to totally clean memories the parse uses;
|
||||
|
@ -1833,6 +1836,16 @@ void Editor::deleteToBOL()
|
|||
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(
|
||||
const QSynedit::BufferCoord &pos,
|
||||
QString &memberOperator,
|
||||
|
@ -2567,6 +2580,15 @@ bool Editor::handleCodeCompletion(QChar key)
|
|||
void Editor::initParser()
|
||||
{
|
||||
// mParser=nullptr;
|
||||
if (pSettings->codeCompletion().shareParser()) {
|
||||
if (pSettings->codeCompletion().enabled()
|
||||
&& (highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter)
|
||||
) {
|
||||
mParser = sharedParser();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
mParser = std::make_shared<CppParser>();
|
||||
if (mUseCppSyntax) {
|
||||
mParser->setLanguage(ParserLanguage::CPlusPlus);
|
||||
|
@ -2721,12 +2743,14 @@ void Editor::reparse(bool resetParser)
|
|||
return;
|
||||
//mParser->setEnabled(pSettings->codeCompletion().enabled());
|
||||
ParserLanguage language = mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C;
|
||||
if (language!=mParser->language() && !inProject()) {
|
||||
if (!inProject() && !pSettings->codeCompletion().shareParser()) {
|
||||
if (language!=mParser->language()) {
|
||||
mParser->setLanguage(language);
|
||||
resetCppParser(mParser);
|
||||
} else if (resetParser && !inProject()) {
|
||||
} else if (resetParser) {
|
||||
resetCppParser(mParser);
|
||||
}
|
||||
}
|
||||
parseFile(mParser,mFilename, inProject());
|
||||
}
|
||||
|
||||
|
@ -3918,6 +3942,23 @@ void Editor::onScrollBarValueChanged()
|
|||
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
|
||||
{
|
||||
return mCanAutoSave;
|
||||
|
|
|
@ -216,6 +216,8 @@ public:
|
|||
void duplicateLine();
|
||||
void deleteToEOL();
|
||||
void deleteToBOL();
|
||||
void gotoBlockStart();
|
||||
void gotoBlockEnd();
|
||||
|
||||
QStringList getOwnerExpressionAndMemberAtPositionForCompletion(
|
||||
const QSynedit::BufferCoord& pos,
|
||||
|
@ -290,6 +292,7 @@ private:
|
|||
void onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString& token,
|
||||
QSynedit::PHighlighterAttribute &attr);
|
||||
void onScrollBarValueChanged();
|
||||
static PCppParser sharedParser();
|
||||
private:
|
||||
QByteArray mEncodingOption; // the encoding type set by the user
|
||||
QByteArray mFileEncoding; // the real encoding of the file (auto detected)
|
||||
|
@ -340,6 +343,8 @@ private:
|
|||
QTimer mFunctionTipTimer;
|
||||
int mHoverModifiedLine;
|
||||
|
||||
static std::weak_ptr<CppParser> mSharedParser;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
|
|
|
@ -8639,3 +8639,19 @@ bool MainWindow::isClosingAll() const
|
|||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -728,6 +728,10 @@ private slots:
|
|||
|
||||
void on_actionNew_Template_triggered();
|
||||
|
||||
void on_actionGoto_block_start_triggered();
|
||||
|
||||
void on_actionGoto_block_end_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
EditorList *mEditorList;
|
||||
|
|
|
@ -221,6 +221,8 @@
|
|||
<addaction name="separator"/>
|
||||
<addaction name="actionMatch_Bracket"/>
|
||||
<addaction name="actionGo_to_Line"/>
|
||||
<addaction name="actionGoto_block_start"/>
|
||||
<addaction name="actionGoto_block_end"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionAdd_bookmark"/>
|
||||
<addaction name="actionRemove_Bookmark"/>
|
||||
|
@ -3237,6 +3239,22 @@
|
|||
<string>New Template from Project</string>
|
||||
</property>
|
||||
</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>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -3691,8 +3691,14 @@ void Settings::CodeCompletion::setShowCodeIns(bool 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;
|
||||
}
|
||||
|
||||
|
@ -3721,6 +3727,23 @@ void Settings::CodeCompletion::setHideSymbolsStartsWithTwoUnderLine(bool newHide
|
|||
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
|
||||
{
|
||||
return mHideSymbolsStartsWithUnderLine;
|
||||
|
@ -3859,6 +3882,7 @@ void Settings::CodeCompletion::doSave()
|
|||
saveValue("min_char_required",mMinCharRequired);
|
||||
saveValue("hide_symbols_start_with_two_underline", mHideSymbolsStartsWithTwoUnderLine);
|
||||
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);
|
||||
|
||||
bool shouldShare=true;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
if (statex.ullAvailPhys < (long long int)1024*1024*1024) {
|
||||
mClearWhenEditorHidden = true;
|
||||
statex.dwLength = sizeof (statex);
|
||||
|
||||
GlobalMemoryStatusEx (&statex);
|
||||
if (statex.ullAvailPhys > (long long int)4*1024*1024*1024) {
|
||||
shouldShare = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
mShareParser = boolValue("share_parser",shouldShare);
|
||||
}
|
||||
|
||||
Settings::CodeFormatter::CodeFormatter(Settings *settings):
|
||||
|
|
|
@ -602,7 +602,7 @@ public:
|
|||
bool showCodeIns() const;
|
||||
void setShowCodeIns(bool newShowCodeIns);
|
||||
|
||||
bool clearWhenEditorHidden() const;
|
||||
bool clearWhenEditorHidden();
|
||||
void setClearWhenEditorHidden(bool newClearWhenEditorHidden);
|
||||
|
||||
int minCharRequired() const;
|
||||
|
@ -614,6 +614,9 @@ public:
|
|||
bool hideSymbolsStartsWithTwoUnderLine() const;
|
||||
void setHideSymbolsStartsWithTwoUnderLine(bool newHideSymbolsStartsWithTwoUnderLine);
|
||||
|
||||
bool shareParser();
|
||||
void setShareParser(bool newShareParser);
|
||||
|
||||
private:
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
|
@ -627,10 +630,11 @@ public:
|
|||
bool mIgnoreCase;
|
||||
bool mAppendFunc;
|
||||
bool mShowCodeIns;
|
||||
bool mClearWhenEditorHidden;
|
||||
int mMinCharRequired;
|
||||
bool mHideSymbolsStartsWithTwoUnderLine;
|
||||
bool mHideSymbolsStartsWithUnderLine;
|
||||
bool mClearWhenEditorHidden;
|
||||
bool mShareParser;
|
||||
|
||||
// _Base interface
|
||||
protected:
|
||||
|
|
|
@ -54,6 +54,7 @@ void EditorCodeCompletionWidget::doLoad()
|
|||
ui->chkHideSymbolsStartWithTwoUnderline->setChecked(pSettings->codeCompletion().hideSymbolsStartsWithTwoUnderLine());
|
||||
ui->chkHideSymbolsStartWithUnderline->setChecked(pSettings->codeCompletion().hideSymbolsStartsWithUnderLine());
|
||||
|
||||
ui->chkEditorShareCodeParser->setChecked(pSettings->codeCompletion().shareParser());
|
||||
ui->spinMinCharRequired->setValue(pSettings->codeCompletion().minCharRequired());
|
||||
}
|
||||
|
||||
|
@ -82,6 +83,8 @@ void EditorCodeCompletionWidget::doSave()
|
|||
pSettings->codeCompletion().setHideSymbolsStartsWithTwoUnderLine(ui->chkHideSymbolsStartWithTwoUnderline->isChecked());
|
||||
pSettings->codeCompletion().setHideSymbolsStartsWithUnderLine(ui->chkHideSymbolsStartWithUnderline->isChecked());
|
||||
|
||||
pSettings->codeCompletion().setShareParser(ui->chkEditorShareCodeParser->isChecked());
|
||||
|
||||
pSettings->codeCompletion().save();
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,13 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkEditorShareCodeParser">
|
||||
<property name="text">
|
||||
<string>Editors share one code parser</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkClearWhenEditorHidden">
|
||||
<property name="text">
|
||||
|
|
|
@ -39,17 +39,26 @@ void EnvironmentPerformanceWidget::doLoad()
|
|||
statex.dwLength = sizeof (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->setChecked(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
|
||||
ui->chkEditorsShareParser->setChecked(pSettings->codeCompletion().shareParser());
|
||||
}
|
||||
|
||||
void EnvironmentPerformanceWidget::doSave()
|
||||
{
|
||||
pSettings->codeCompletion().setClearWhenEditorHidden(ui->chkClearWhenEditorHidden->isChecked());
|
||||
pSettings->codeCompletion().setShareParser(ui->chkEditorsShareParser->isChecked());
|
||||
|
||||
pSettings->codeCompletion().save();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<width>431</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -20,13 +20,20 @@
|
|||
<string>Reduce Memory Usage</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="chkClearWhenEditorHidden">
|
||||
<property name="text">
|
||||
<string>Auto clear parsed symbols when editor hidden</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -1179,6 +1179,10 @@
|
|||
<source>Enable code competion</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Editors share one code parser</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>EditorColorSchemeWidget</name>
|
||||
|
@ -1707,6 +1711,10 @@
|
|||
<source>Auto clear parsed symbols when editor hidden</source>
|
||||
<translation>Limpar automaticamente símbolos verificados quando editor oculto</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Editors share one code parser</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>EnvironmentProgramsWidget</name>
|
||||
|
@ -4688,6 +4696,22 @@
|
|||
<source>In current project</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<name>NewClassDialog</name>
|
||||
|
@ -4838,7 +4862,7 @@
|
|||
</message>
|
||||
<message>
|
||||
<source>untitled</source>
|
||||
<translation>sem nome</translation>
|
||||
<translation type="vanished">sem nome</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Choose directory</source>
|
||||
|
@ -6623,7 +6647,7 @@
|
|||
</message>
|
||||
<message>
|
||||
<source>Column</source>
|
||||
<translation>Coluna</translation>
|
||||
<translation type="vanished">Coluna</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Content</source>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1076,6 +1076,10 @@
|
|||
<source>Completion suggestion window height:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Editors share one code parser</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>EditorColorSchemeWidget</name>
|
||||
|
@ -1600,6 +1604,10 @@
|
|||
<source>Auto clear parsed symbols when editor hidden</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Editors share one code parser</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>EnvironmentProgramsWidget</name>
|
||||
|
@ -4541,6 +4549,22 @@
|
|||
<source>In current project</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<name>NewClassDialog</name>
|
||||
|
@ -4689,10 +4713,6 @@
|
|||
<source>Cancel</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>untitled</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Choose directory</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -6384,10 +6404,6 @@
|
|||
<source>Line</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Column</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Content</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
|
|
@ -198,6 +198,11 @@ void EditKeyStrokes::resetDefaults()
|
|||
add(EditCommand::ecWordRight, Qt::Key_Right, 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::ecShrinkSelection, Qt::Key_Left, Qt::ShiftModifier | Qt::AltModifier);
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@ enum class EditCommand {
|
|||
ecEditorStart = 15, // Move cursor to absolute beginning
|
||||
ecEditorEnd = 16, // Move cursor to absolute end
|
||||
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
|
||||
|
@ -89,6 +91,8 @@ enum class EditCommand {
|
|||
ecSelEditorStart = ecEditorStart + ecSelection,
|
||||
ecSelEditorEnd = ecEditorEnd + ecSelection,
|
||||
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
|
||||
|
|
|
@ -5054,6 +5054,64 @@ void SynEdit::moveCaretToLineEnd(bool 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()
|
||||
{
|
||||
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();
|
||||
incPaintLock();
|
||||
|
@ -5731,40 +5789,40 @@ void SynEdit::executeCommand(EditCommand Command, QChar AChar, void *pData)
|
|||
decPaintLock();
|
||||
showCaret();
|
||||
});
|
||||
switch(Command) {
|
||||
switch(command) {
|
||||
//horizontal caret movement or selection
|
||||
case EditCommand::ecLeft:
|
||||
case EditCommand::ecSelLeft:
|
||||
moveCaretHorz(-1, Command == EditCommand::ecSelLeft);
|
||||
moveCaretHorz(-1, command == EditCommand::ecSelLeft);
|
||||
break;
|
||||
case EditCommand::ecRight:
|
||||
case EditCommand::ecSelRight:
|
||||
moveCaretHorz(1, Command == EditCommand::ecSelRight);
|
||||
moveCaretHorz(1, command == EditCommand::ecSelRight);
|
||||
break;
|
||||
case EditCommand::ecPageLeft:
|
||||
case EditCommand::ecSelPageLeft:
|
||||
moveCaretHorz(-mCharsInWindow, Command == EditCommand::ecSelPageLeft);
|
||||
moveCaretHorz(-mCharsInWindow, command == EditCommand::ecSelPageLeft);
|
||||
break;
|
||||
case EditCommand::ecPageRight:
|
||||
case EditCommand::ecSelPageRight:
|
||||
moveCaretHorz(mCharsInWindow, Command == EditCommand::ecSelPageRight);
|
||||
moveCaretHorz(mCharsInWindow, command == EditCommand::ecSelPageRight);
|
||||
break;
|
||||
case EditCommand::ecLineStart:
|
||||
case EditCommand::ecSelLineStart:
|
||||
moveCaretToLineStart(Command == EditCommand::ecSelLineStart);
|
||||
moveCaretToLineStart(command == EditCommand::ecSelLineStart);
|
||||
break;
|
||||
case EditCommand::ecLineEnd:
|
||||
case EditCommand::ecSelLineEnd:
|
||||
moveCaretToLineEnd(Command == EditCommand::ecSelLineEnd);
|
||||
moveCaretToLineEnd(command == EditCommand::ecSelLineEnd);
|
||||
break;
|
||||
// vertical caret movement or selection
|
||||
case EditCommand::ecUp:
|
||||
case EditCommand::ecSelUp:
|
||||
moveCaretVert(-1, Command == EditCommand::ecSelUp);
|
||||
moveCaretVert(-1, command == EditCommand::ecSelUp);
|
||||
break;
|
||||
case EditCommand::ecDown:
|
||||
case EditCommand::ecSelDown:
|
||||
moveCaretVert(1, Command == EditCommand::ecSelDown);
|
||||
moveCaretVert(1, command == EditCommand::ecSelDown);
|
||||
break;
|
||||
case EditCommand::ecPageUp:
|
||||
case EditCommand::ecSelPageUp:
|
||||
|
@ -5779,51 +5837,55 @@ void SynEdit::executeCommand(EditCommand Command, QChar AChar, void *pData)
|
|||
}
|
||||
if (counter<0)
|
||||
break;
|
||||
if (Command == EditCommand::ecPageUp || Command == EditCommand::ecSelPageUp) {
|
||||
if (command == EditCommand::ecPageUp || command == EditCommand::ecSelPageUp) {
|
||||
counter = -counter;
|
||||
}
|
||||
moveCaretVert(counter, Command == EditCommand::ecSelPageUp || Command == EditCommand::ecSelPageDown);
|
||||
moveCaretVert(counter, command == EditCommand::ecSelPageUp || command == EditCommand::ecSelPageDown);
|
||||
break;
|
||||
}
|
||||
case EditCommand::ecPageTop:
|
||||
case EditCommand::ecSelPageTop:
|
||||
moveCaretVert(mTopLine-mCaretY, Command == EditCommand::ecSelPageTop);
|
||||
moveCaretVert(mTopLine-mCaretY, command == EditCommand::ecSelPageTop);
|
||||
break;
|
||||
case EditCommand::ecPageBottom:
|
||||
case EditCommand::ecSelPageBottom:
|
||||
moveCaretVert(mTopLine+mLinesInWindow-1-mCaretY, Command == EditCommand::ecSelPageBottom);
|
||||
moveCaretVert(mTopLine+mLinesInWindow-1-mCaretY, command == EditCommand::ecSelPageBottom);
|
||||
break;
|
||||
case EditCommand::ecEditorStart:
|
||||
case EditCommand::ecSelEditorStart:
|
||||
moveCaretVert(1-mCaretY, Command == EditCommand::ecSelEditorStart);
|
||||
moveCaretToLineStart(Command == EditCommand::ecSelEditorStart);
|
||||
doGotoEditorStart(command == EditCommand::ecSelEditorStart);
|
||||
break;
|
||||
case EditCommand::ecEditorEnd:
|
||||
case EditCommand::ecSelEditorEnd:
|
||||
if (!mDocument->empty()) {
|
||||
moveCaretVert(mDocument->count()-mCaretY, Command == EditCommand::ecSelEditorEnd);
|
||||
moveCaretToLineEnd(Command == EditCommand::ecSelEditorEnd);
|
||||
}
|
||||
doGotoEditorEnd(command == EditCommand::ecSelEditorEnd);
|
||||
break;
|
||||
case EditCommand::ecBlockStart:
|
||||
case EditCommand::ecSelBlockStart:
|
||||
doGotoBlockStart(command == EditCommand::ecSelBlockStart);
|
||||
break;
|
||||
case EditCommand::ecBlockEnd:
|
||||
case EditCommand::ecSelBlockEnd:
|
||||
doGotoBlockEnd(command == EditCommand::ecSelBlockEnd);
|
||||
break;
|
||||
// goto special line / column position
|
||||
case EditCommand::ecGotoXY:
|
||||
case EditCommand::ecSelGotoXY:
|
||||
if (pData)
|
||||
moveCaretAndSelection(caretXY(), *((BufferCoord *)(pData)), Command == EditCommand::ecSelGotoXY);
|
||||
moveCaretAndSelection(caretXY(), *((BufferCoord *)(pData)), command == EditCommand::ecSelGotoXY);
|
||||
break;
|
||||
// word selection
|
||||
case EditCommand::ecWordLeft:
|
||||
case EditCommand::ecSelWordLeft:
|
||||
{
|
||||
BufferCoord CaretNew = prevWordPos();
|
||||
moveCaretAndSelection(caretXY(), CaretNew, Command == EditCommand::ecSelWordLeft);
|
||||
moveCaretAndSelection(caretXY(), CaretNew, command == EditCommand::ecSelWordLeft);
|
||||
break;
|
||||
}
|
||||
case EditCommand::ecWordRight:
|
||||
case EditCommand::ecSelWordRight:
|
||||
{
|
||||
BufferCoord CaretNew = nextWordPos();
|
||||
moveCaretAndSelection(caretXY(), CaretNew, Command == EditCommand::ecSelWordRight);
|
||||
moveCaretAndSelection(caretXY(), CaretNew, command == EditCommand::ecSelWordRight);
|
||||
break;
|
||||
}
|
||||
case EditCommand::ecSelWord:
|
||||
|
@ -5895,7 +5957,7 @@ void SynEdit::executeCommand(EditCommand Command, QChar AChar, void *pData)
|
|||
doShiftTabKey();
|
||||
break;
|
||||
case EditCommand::ecChar:
|
||||
doAddChar(AChar);
|
||||
doAddChar(ch);
|
||||
break;
|
||||
case EditCommand::ecInsertMode:
|
||||
if (!mReadOnly)
|
||||
|
|
|
@ -466,9 +466,9 @@ protected:
|
|||
virtual void onPreparePaintHighlightToken(int line,
|
||||
int aChar, const QString& token, PHighlighterAttribute attr,
|
||||
FontStyles& style, QColor& foreground, QColor& background);
|
||||
virtual void onProcessCommand(EditCommand Command, QChar AChar, void * pData);
|
||||
virtual void onCommandProcessed(EditCommand Command, QChar AChar, void * pData);
|
||||
virtual void executeCommand(EditCommand Command, QChar AChar, void * pData);
|
||||
virtual void onProcessCommand(EditCommand command, QChar car, void * pData);
|
||||
virtual void onCommandProcessed(EditCommand command, QChar car, void * pData);
|
||||
virtual void executeCommand(EditCommand command, QChar ch, void * pData);
|
||||
virtual void onEndFirstPaintLock();
|
||||
virtual void onBeginFirstPaintLock();
|
||||
|
||||
|
@ -540,6 +540,10 @@ private:
|
|||
bool isSelection);
|
||||
void moveCaretToLineStart(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 setSelTextPrimitive(const QStringList& text);
|
||||
void setSelTextPrimitiveEx(SelectionMode PasteMode,
|
||||
|
|
Loading…
Reference in New Issue