hello, jens:
refer to visual assist,I do a fes modifications for bracecompletion.
two modificactions:
1. the { } will stay in the same line now if current line have other words.
2. if the current caret postion's next char is not empty,the bracecompletion will not work.
here is the patch.
Index: cbeditor.cpp
===================================================================
--- cbeditor.cpp (revision 5731)
+++ cbeditor.cpp (working copy)
@@ -331,19 +331,26 @@
}
if ( IsCharacterOrString(style) )
return;
- wxString leftBrace(_T("([{"));
- wxString rightBrace(_T(")]}"));
+ const wxString leftBrace(_T("([{"));
+ const wxString rightBrace(_T(")]}"));
int index = leftBrace.find(ch);
- if (index != wxNOT_FOUND)
+ //Manager::Get()->GetLogManager()->DebugLog(F(_T("current: %d"),control->GetCharAt(pos)));
+ //Manager::Get()->GetLogManager()->DebugLog(_T("current:")+control->GetCharAt(pos));
+ const wxString unWant(_T("\n\r\t\b "));
+ if (index != wxNOT_FOUND && unWant.find(control->GetCharAt(pos)) != wxNOT_FOUND)
{
- control->AddText(rightBrace.GetChar(index));
- control->GotoPos(pos);
- if (ch == _T('{'))
- {
- control->NewLine();
+ control->AddText(rightBrace.GetChar(index));
control->GotoPos(pos);
- return;
- }
+ if (ch == _T('{'))
+ {
+ const wxRegEx reg(_T("^[ \t]*{}[ \t]*"));
+ if (reg.Matches(control->GetCurLine()))
+ {
+ control->NewLine();
+ control->GotoPos(pos);
+ return;
+ }
+ }
}
else
{
Hi blueshake,
2. if the current caret postion's next char is not empty,the bracecompletion will not work.
here is the patch.
I agree that the bracecompletion should not work if the next char is not empty. For example if you have a statement like
if (variable1 && variable2)
and now modify the condition
then I do not want to add instantly the closing bracket, since this is not the desired place.
but what if you have the following
and you want to add something like
to obtain
if(test1 && (test2 || test3))
then I want the "()"
I think mariocup is right.
so these codes can be changed to be so.add a ) will work.
const wxString unWant(_T(")\n\r\t\b "));
see my attachment.
snap1 is new one , the {} will stay in the some line.
snap3 is old one, the {} will stay in twol line.
snap2 is example ,the next char is m ,so bracecompletion will not work.it will work if next one is enter whitesapce , tab or ) (new added).
[attachment deleted by admin]
nice to hear that ,
here is my new patch.
the opening { work like this now ,it is more like what visual assist do.
see the attachment.
Index: cbeditor.cpp
===================================================================
--- cbeditor.cpp (revision 5731)
+++ cbeditor.cpp (working copy)
@@ -331,19 +331,25 @@
}
if ( IsCharacterOrString(style) )
return;
- wxString leftBrace(_T("([{"));
- wxString rightBrace(_T(")]}"));
+ const wxString leftBrace(_T("([{"));
+ const wxString rightBrace(_T(")]}"));
int index = leftBrace.find(ch);
- if (index != wxNOT_FOUND)
+ const wxString unWant(_T(")\n\r\t\b "));
+ if (index != wxNOT_FOUND && unWant.find(control->GetCharAt(pos)) != wxNOT_FOUND)
{
- control->AddText(rightBrace.GetChar(index));
- control->GotoPos(pos);
- if (ch == _T('{'))
- {
- control->NewLine();
+ control->AddText(rightBrace.GetChar(index));
control->GotoPos(pos);
- return;
- }
+ if (ch == _T('{'))
+ {
+ const wxRegEx reg(_T("^[ \t]*{}[ \t]*"));
+ if (reg.Matches(control->GetCurLine()))
+ {
+ control->NewLine();
+ control->GotoPos(pos);
+ control->NewLine();
+ return;
+ }
+ }
}
else
{
[attachment deleted by admin]
hi,killerbot,i paste the the codes,and upload the file as a attachment.
void DoBraceCompletion(const wxChar& ch)
{
cbStyledTextCtrl* control = m_pOwner->GetControl();
int pos = control->GetCurrentPos();
int style = control->GetStyleAt(pos);
if ( IsComment(style) || IsPreprocessor(style) )
return;
if ( ch == _T('\'') )
{
if ( control->GetCharAt(pos) == ch && pos > 1 && control->GetCharAt(pos-2) != _T('\\') )
{
control->DeleteBack();
control->GotoPos(pos);
}
else
{
if ( control->GetCharAt(pos-2) == _T('\\') || IsCharacterOrString(style) )
return;
control->AddText(ch);
control->GotoPos(pos);
}
return;
}
if ( ch == _T('"') )
{
if (control->GetCharAt(pos) == ch && pos > 1 && control->GetCharAt(pos-2) != _T('\\') )
{
control->DeleteBack();
control->GotoPos(pos);
}
else
{
if ( control->GetCharAt(pos-2) == _T('\\') || IsCharacter(style) )
return;
control->AddText(ch);
control->GotoPos(pos);
}
return;
}
if ( IsCharacterOrString(style) )
return;
const wxString leftBrace(_T("([{"));
const wxString rightBrace(_T(")]}"));
int index = leftBrace.find(ch);
const wxString unWant(_T(")\n\r\t\b "));
if (index != wxNOT_FOUND && unWant.find(control->GetCharAt(pos)) != wxNOT_FOUND)
{
control->AddText(rightBrace.GetChar(index));
control->GotoPos(pos);
if (ch == _T('{'))
{
const wxRegEx reg(_T("^[ \t]*{}[ \t]*"));
if (reg.Matches(control->GetCurLine()))
{
control->NewLine();
control->GotoPos(pos);
control->NewLine();
return;
}
}
}
else
{
index = rightBrace.find(ch);
if (index != wxNOT_FOUND)
{
if (control->GetCharAt(pos) == ch)
{
control->DeleteBack();
control->GotoPos(pos);
return;
}
}
}
}
[attachment deleted by admin]
I can confirm it works now.
I didn't have the ')' in :
const wxString unWant(_T(")\n\r\t\b "));
:oops:
hi,
recently,i am going to make a patch,its function is
when you delete a ([{ and the right char is )]} ,so the the relative one will be deleted too.
for example
int the "|" position ,you delete "(" and the ")" should be deleted too.
but i face a problem,
it seems that these codes can not work.the caret moved,but the ) didn't be delete.
any one have any idea about this?
these codes seems not be executed .
m_pControl->DeleteBack();
here are the codes.
void cbEditor::OnEditorModified(wxScintillaEvent& event)
{
// wxString txt = _T("OnEditorModified(): ");
// int flags = event.GetModificationType();
// if (flags & wxSCI_MOD_CHANGEMARKER) txt << _T("wxSCI_MOD_CHANGEMARKER, ");
// if (flags & wxSCI_MOD_INSERTTEXT) txt << _T("wxSCI_MOD_INSERTTEXT, ");
// if (flags & wxSCI_MOD_DELETETEXT) txt << _T("wxSCI_MOD_DELETETEXT, ");
// if (flags & wxSCI_MOD_CHANGEFOLD) txt << _T("wxSCI_MOD_CHANGEFOLD, ");
// if (flags & wxSCI_PERFORMED_USER) txt << _T("wxSCI_PERFORMED_USER, ");
// if (flags & wxSCI_MOD_BEFOREINSERT) txt << _T("wxSCI_MOD_BEFOREINSERT, ");
// if (flags & wxSCI_MOD_BEFOREDELETE) txt << _T("wxSCI_MOD_BEFOREDELETE, ");
// txt << _T("pos=")
// << wxString::Format(_T("%d"), event.GetPosition())
// << _T(", line=")
// << wxString::Format(_T("%d"), event.GetLine())
// << _T(", linesAdded=")
// << wxString::Format(_T("%d"), event.GetLinesAdded());
// Manager::Get()->GetLogManager()->DebugLog(txt);
// whenever event.GetLinesAdded() != 0, we must re-set breakpoints for lines greater
// than LineFromPosition(event.GetPosition())
int linesAdded = event.GetLinesAdded();
bool isAdd = event.GetModificationType() & wxSCI_MOD_INSERTTEXT;
bool isDel = event.GetModificationType() & wxSCI_MOD_DELETETEXT;
if ((isAdd || isDel) && linesAdded != 0)
{
// in case of no line numbers to be shown no need to set
// NOTE : on every modification of the Editor we consult ConfigManager
// hopefully not to time consuming, otherwise we make a member out of it
ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
if (mgr->ReadBool(_T("/show_line_numbers"), true))
{
m_pData->SetLineNumberColWidth();
}
// NB: I don't think polling for each debugger every time will slow things down enough
// to worry about unless there are automated tasks that call this routine regularly
//
// well, scintilla events happen regularly
// although we only reach this part of the code only if a line has been added/removed
// so, yes, it might not be that bad after all
PluginsArray arr = Manager::Get()->GetPluginManager()->GetOffersFor(ptDebugger);
int startline = m_pControl->LineFromPosition(event.GetPosition());
for(size_t i=0;i<arr.GetCount();i++)
{
cbDebuggerPlugin* debugger = (cbDebuggerPlugin*)arr[i];
debugger->EditorLinesAddedOrRemoved(this, startline, linesAdded);
}
}
if (isDel)
{
Manager::Get()->GetLogManager()->DebugLog(event.GetText());
Manager::Get()->GetLogManager()->DebugLog(F(_T("delete %d"),event.GetText().size()));
if (event.GetText().size() == 1)
{
const wxString leftBrace(_T("([{"));
const wxString rightBrace(_T(")]}"));
int left = leftBrace.find(event.GetText()[0]);
if (left != wxNOT_FOUND)
{
wxChar ch = m_pControl->GetCharAt(event.GetPosition());
int right = rightBrace.find(ch);
if (right != wxNOT_FOUND && right == left)
{
m_pControl->GotoPos(event.GetPosition() + 1);
m_pControl->DeleteBack();
}
}
}
}
OnScintillaEvent(event);
} // end of OnEditorModified