[NEW_FEATURE] Smart Indent (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1291 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2014-11-15 17:45:47 +00:00
parent 8ceabd7850
commit 83debc292e

View File

@ -2325,11 +2325,11 @@ void Notepad_plus::maintainIndentation(TCHAR ch)
// get previous char from current line // get previous char from current line
int prevPos = _pEditView->execute(SCI_GETCURRENTPOS) - (eolMode == SC_EOL_CRLF ? 3 : 2); int prevPos = _pEditView->execute(SCI_GETCURRENTPOS) - (eolMode == SC_EOL_CRLF ? 3 : 2);
UCHAR prevChar = (UCHAR)_pEditView->execute(SCI_GETCHARAT, prevPos); UCHAR prevChar = (UCHAR)_pEditView->execute(SCI_GETCHARAT, prevPos);
int curPos = _pEditView->execute(SCI_GETCURRENTPOS);
UCHAR nextChar = (UCHAR)_pEditView->execute(SCI_GETCHARAT, curPos);
if (prevChar == '{')// && c++ java, c# js php) if (prevChar == '{')// && c++ java, c# js php)
{ {
int curPos = _pEditView->execute(SCI_GETCURRENTPOS);
UCHAR nextChar = (UCHAR)_pEditView->execute(SCI_GETCHARAT, curPos);
if (nextChar == '}') if (nextChar == '}')
{ {
_pEditView->execute(SCI_INSERTTEXT, _pEditView->execute(SCI_GETCURRENTPOS), (LPARAM)"\r\n"); _pEditView->execute(SCI_INSERTTEXT, _pEditView->execute(SCI_GETCURRENTPOS), (LPARAM)"\r\n");
@ -2337,6 +2337,10 @@ void Notepad_plus::maintainIndentation(TCHAR ch)
} }
_pEditView->setLineIndent(curLine, indentAmountPrevLine + tabWidth); _pEditView->setLineIndent(curLine, indentAmountPrevLine + tabWidth);
} }
else if (nextChar == '{')
{
_pEditView->setLineIndent(curLine, indentAmountPrevLine);
}
else if (isConditionExprLine(prevLine)) else if (isConditionExprLine(prevLine))
{ {
_pEditView->setLineIndent(curLine, indentAmountPrevLine + tabWidth); _pEditView->setLineIndent(curLine, indentAmountPrevLine + tabWidth);