-- Автозакрытие скобок - усовершенствованная модель -- Авторы: (gansA, mimir, Midas, mozers) полностью переделано Маслов Дмитрий -- Работает, если braces.autoclose=1 (параметр в файле SciTEGlobal.properties) ----------------------------------------------- -- Добавляем свой обработчик события OnChar local old_OnChar = OnChar function OnChar(char) -- обрабатываем по дефолту local result if old_OnChar then result = old_OnChar(char) end -- далее запускаем волшебный обработчик -- если находимся в редакторе if(editor.Focus)and(props['braces.autoclose']=='1') then local pos = editor.CurrentPos local nextSimbol = string.format("%c",editor.CharAt[pos]) if(nextSimbol=="(")or(nextSimbol=="[")or(nextSimbol==".")or(nextSimbol=="%")then nextSimbol=string.format("%%%s",nextSimbol) end if(char=="(")or(char=="[")or(char==".")or(char=="%")then char=string.format("%%%s",char) end local endBr = string.find(props['braces.close'],nextSimbol,1) -- если следующий символ закрывающаяся скобка -- и мы ее вводим, то ввод проглатываем if(endBr~=nil)and(endBr>0)and(nextSimbol==char)then editor:DeleteBack() editor:CharRight() else -- сразу вставляем закрывающуюся скобку если поставили открывающуюся local brIdx = string.find(props['braces.open'],char,1) if(brIdx~=nil)and(brIdx>0)then editor:BeginUndoAction() -- по волшебному обрабатываем скобку { и } в cpp if (char == '{')and(GetLexerName() == 'cpp') then editor:NewLine() editor:Tab() pos = editor.CurrentPos editor:NewLine() editor:InsertText(editor.CurrentPos,'}') editor:GotoPos(pos) elseif (char == '}')and(GetLexerName() == 'cpp') then editor:BackTab() else local symE = string.sub(props['braces.close'],brIdx,brIdx) if(symE~=nil)then editor:InsertText(pos,symE) end end editor:EndUndoAction() end end end return result end |