Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/ShaderEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ShaderEditor::ShaderEditor( Scintilla::Surface *s )
nFontSize = 16;
bHasMouseCapture = false;
nOpacity = 0xC0;
bAutoCloseBlock = false;
}

void ShaderEditor::SetAStyle(int style, Scintilla::ColourDesired fore, Scintilla::ColourDesired back, int size, const char *face)
Expand Down Expand Up @@ -186,6 +187,7 @@ void ShaderEditor::Initialise( SHADEREDITOR_OPTIONS &options )
nTabSize = options.nTabSize;
bVisibleWhitespace = options.bVisibleWhitespace;
eAutoIndent = options.eAutoIndent;
bAutoCloseBlock = options.bAutoCloseBlock;
theme = options.theme;

Initialise();
Expand Down Expand Up @@ -622,8 +624,34 @@ void ShaderEditor::AutomaticIndentation(char ch) {
if (GetIndentState(curLine - 1) == isKeyWordStart) {
if (RangeIsAllWhitespace(thisLineStart, selStart - 1)) {
SetLineIndentation(curLine, indentBlock - indentSize);
if(bAutoCloseBlock)
indentBlock -= indentSize;
}
}

if(bAutoCloseBlock) {
char tabChar = bUseSpacesForTabs? ' ' : '\t';
int charSize = bUseSpacesForTabs? 1 : nTabSize;

char buf[256] = { '\0' }, *ptr = buf;

*ptr++ = '\n';

for(int i = 0; i < (indentBlock + indentSize) / charSize; ++i)
*ptr++ = tabChar;

*ptr++ = '\n';

for(int i = 0; i < indentBlock / charSize; ++i)
*ptr++ = tabChar;

*ptr = blockEnd;

WndProc(SCI_ADDTEXT, strlen(buf), (sptr_t)buf);

int pos = CurrentPosition() - indentBlock / charSize - 2;
SetSelection(pos, pos);
}
} else if ((ch == '\r' || ch == '\n') && (selStart == thisLineStart)) {
SetLineIndentation(curLine, indentBlock);
}
Expand Down
2 changes: 2 additions & 0 deletions src/ShaderEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct SHADEREDITOR_OPTIONS {
int nTabSize;
bool bVisibleWhitespace;
AutoIndentationType eAutoIndent;
bool bAutoCloseBlock;
SHADEREDITOR_THEME theme;
};

Expand All @@ -109,6 +110,7 @@ class ShaderEditor : public Scintilla::Editor
int nTabSize;
bool bVisibleWhitespace;
AutoIndentationType eAutoIndent;
bool bAutoCloseBlock;
SHADEREDITOR_THEME theme;

public:
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ int main( int argc, const char *argv[] )
editorOptions.eAutoIndent = aitNone;
}
}
if (options.get<jsonxx::Object>("gui").has<jsonxx::Boolean>("autoCloseBlock"))
editorOptions.bAutoCloseBlock = options.get<jsonxx::Object>("gui").get<jsonxx::Boolean>("autoCloseBlock");
if (options.get<jsonxx::Object>("gui").has<jsonxx::Number>("scrollXFactor"))
fScrollXFactor = options.get<jsonxx::Object>("gui").get<jsonxx::Number>("scrollXFactor");
if (options.get<jsonxx::Object>("gui").has<jsonxx::Number>("scrollYFactor"))
Expand Down