TextDucument: push modifications in the document when is being saved, this will allow to "undo" previous changes correctly.
ecode:
Minor fix in LSP protocol implementation. Closes SpartanJ/ecode#19.
Minor fix in FileSystemListener when no file system model is present.
This commit is contained in:
Martín Lucas Golini
2023-01-31 19:29:16 -03:00
parent 5871b78fae
commit 280d378c82
4 changed files with 9 additions and 21 deletions

1
.gitignore vendored
View File

@@ -38,6 +38,7 @@ external_projects.lua
src/thirdparty/SDL2/include/SDL2
projects/ios/eepp.app/assets
projects/ios/eepp.app/eepp
bin/*.so
bin/*.dylib
*.iml
.idea/

View File

@@ -507,7 +507,6 @@ bool TextDocument::save( IOStream& stream, bool keepUndoRedoStatus ) {
if ( !stream.isOpen() || mLines.empty() )
return false;
const std::string whitespaces( " \t\f\v\n\r" );
char nl = '\n';
if ( mIsBOM ) {
unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
stream.write( (char*)bom, sizeof( bom ) );
@@ -518,19 +517,13 @@ bool TextDocument::save( IOStream& stream, bool keepUndoRedoStatus ) {
if ( !keepUndoRedoStatus && mTrimTrailingWhitespaces && text.size() > 1 &&
whitespaces.find( text[text.size() - 2] ) != std::string::npos ) {
size_t pos = text.find_last_not_of( whitespaces );
size_t oriSize = text.size();
Int64 curLine = i;
if ( pos != std::string::npos ) {
text.erase( pos + 1 );
text += nl;
remove( 0, { { curLine, static_cast<Int64>( pos + 1 ) },
{ curLine, static_cast<Int64>( mLines[i].getText().size() ) } } );
} else {
text = nl;
remove( 0, { startOfLine( { curLine, 0 } ), { endOfLine( { curLine, 0 } ) } } );
}
mLines[i].setText( text );
notifyLineChanged( i );
notifyTextChanged(
{ { { static_cast<Int64>( i ), static_cast<Int64>( oriSize ) },
{ static_cast<Int64>( i ), static_cast<Int64>( text.size() - 1 ) } },
"" } );
}
if ( i == lastLine ) {
if ( !text.empty() && text[text.size() - 1] == '\n' ) {
@@ -542,14 +535,7 @@ bool TextDocument::save( IOStream& stream, bool keepUndoRedoStatus ) {
if ( !keepUndoRedoStatus && mForceNewLineAtEndOfFile && !text.empty() &&
text[text.size() - 1] != '\n' ) {
text += "\n";
mLines.emplace_back( TextDocumentLine( "\n" ) );
notifyTextChanged( { { TextPosition{ static_cast<Int64>( i ),
static_cast<Int64>( mLines[i].size() - 1 ) },
TextPosition{ static_cast<Int64>( i ),
static_cast<Int64>( mLines[i].size() - 1 ) } },
"\n" } );
notifyLineChanged( i );
notifyLineCountChanged( lastLine, lastLine + 1 );
insert( 0, endOfDoc(), "\n" );
}
}
if ( mLineEnding == LineEnding::CRLF ) {

View File

@@ -43,7 +43,8 @@ void FileSystemListener::handleFileAction( efsw::WatchID, const std::string& dir
Log::debug( txt );
}
mFileSystemModel.get()->handleFileEvent( event );
if ( mFileSystemModel )
mFileSystemModel.get()->handleFileEvent( event );
if ( mDirTree )
mDirTree.get()->onChange( (ProjectDirectoryTree::Action)action, file, oldFilename );

View File

@@ -834,7 +834,7 @@ void LSPClientServer::initialize() {
{ "hover", json{ { "contentFormat", { "plaintext", "markdown" } } } } },
},
{ "window", json{ { "workDoneProgress", true } } },
{ "workspace", json{ { "workspaceFolders", true }, { "configuration", false } } },
//{ "workspace", json{ { "workspaceFolders", true }, { "configuration", false } } },
{ "general", json{ { "positionEncodings", json::array( { "utf-32" } ) } } } };
json params{ { "processId", Sys::getProcessID() },