mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
Improved formatter modelue.
Updated efsw.
This commit is contained in:
@@ -6,5 +6,10 @@
|
||||
{
|
||||
"file_patterns": ["%.cpp$", "%.h$", "%.hpp$"],
|
||||
"command": "clang-format --style=file $FILENAME"
|
||||
},
|
||||
{
|
||||
"file_patterns": ["%.py$", "%.pyw$"],
|
||||
"command": "black $FILENAME",
|
||||
"type": "inplace"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1210,7 +1210,7 @@ void UICodeEditor::replaceKeyBinding( const KeyBindings::Shortcut& shortcut,
|
||||
void UICodeEditor::addKeyBindsString( const std::map<std::string, std::string>& binds,
|
||||
const bool& allowLocked ) {
|
||||
mKeyBindings.addKeybindsString( binds );
|
||||
for ( auto bind : binds ) {
|
||||
for ( const auto &bind : binds ) {
|
||||
if ( allowLocked ) {
|
||||
mUnlockedCmd.insert( bind.second );
|
||||
}
|
||||
@@ -1220,7 +1220,7 @@ void UICodeEditor::addKeyBindsString( const std::map<std::string, std::string>&
|
||||
void UICodeEditor::addKeyBinds( const std::map<KeyBindings::Shortcut, std::string>& binds,
|
||||
const bool& allowLocked ) {
|
||||
mKeyBindings.addKeybinds( binds );
|
||||
for ( auto bind : binds ) {
|
||||
for ( const auto &bind : binds ) {
|
||||
if ( allowLocked ) {
|
||||
mUnlockedCmd.insert( bind.second );
|
||||
}
|
||||
|
||||
2
src/thirdparty/efsw
vendored
2
src/thirdparty/efsw
vendored
Submodule src/thirdparty/efsw updated: 2bfda300a9...50176c94f5
@@ -91,12 +91,15 @@ static std::string randString( size_t len ) {
|
||||
void FormatterModule::formatDoc( UICodeEditor* editor ) {
|
||||
if ( !mReady )
|
||||
return;
|
||||
|
||||
Clock clock;
|
||||
std::shared_ptr<TextDocument> doc = editor->getDocumentRef();
|
||||
auto formatter = supportsFormatter( doc );
|
||||
if ( formatter.command.empty() && doc->getFilePath().empty() )
|
||||
if ( formatter.command.empty() || doc->getFilePath().empty() )
|
||||
return;
|
||||
IOStreamString fileString;
|
||||
if ( doc->isDirty() || !doc->hasFilepath() ) {
|
||||
std::string path;
|
||||
if ( doc->isDirty() || !doc->hasFilepath() || formatter.type == FormatterType::Inplace ) {
|
||||
std::string tmpPath;
|
||||
if ( !doc->hasFilepath() ) {
|
||||
tmpPath = Sys::getTempPath() + ".ecode-" + doc->getFilename() + "." + randString( 8 );
|
||||
@@ -110,15 +113,33 @@ void FormatterModule::formatDoc( UICodeEditor* editor ) {
|
||||
FileSystem::fileWrite( tmpPath, (Uint8*)fileString.getStreamPointer(),
|
||||
fileString.getSize() );
|
||||
runFormatter( editor, formatter, tmpPath );
|
||||
|
||||
if ( formatter.type == FormatterType::Inplace ) {
|
||||
std::string data;
|
||||
FileSystem::fileGet( tmpPath, data );
|
||||
|
||||
editor->runOnMainThread( [&, data, editor]() {
|
||||
std::shared_ptr<TextDocument> doc = editor->getDocumentRef();
|
||||
TextPosition pos = doc->getSelection().start();
|
||||
doc->selectAll();
|
||||
doc->textInput( data );
|
||||
doc->setSelection( pos );
|
||||
} );
|
||||
}
|
||||
|
||||
FileSystem::fileRemove( tmpPath );
|
||||
path = tmpPath;
|
||||
} else {
|
||||
runFormatter( editor, formatter, doc->getFilePath() );
|
||||
path = doc->getFilePath();
|
||||
}
|
||||
|
||||
Log::info( "FormatterModule::formatDoc for %s took %.2fms", path.c_str(),
|
||||
clock.getElapsedTime().asMilliseconds() );
|
||||
}
|
||||
|
||||
void FormatterModule::runFormatter( UICodeEditor* editor, const Formatter& formatter,
|
||||
const std::string& path ) {
|
||||
Clock clock;
|
||||
|
||||
std::string cmd( formatter.command );
|
||||
String::replaceAll( cmd, "$FILENAME", path );
|
||||
@@ -156,9 +177,6 @@ void FormatterModule::runFormatter( UICodeEditor* editor, const Formatter& forma
|
||||
doc->setSelection( pos );
|
||||
} );
|
||||
}
|
||||
|
||||
Log::info( "FormatterModule::formatDoc for %s took %.2fms", path.c_str(),
|
||||
clock.getElapsedTime().asMilliseconds() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user