MCPcopy Create free account
hub / github.com/SpartanJ/eepp / loadFromStrings

Method loadFromStrings

src/eepp/ui/tools/uidiffview.cpp:796–845  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

794}
795
796void UIDiffView::loadFromStrings( const std::string& oldText, const std::string& newText,
797 const std::string& originalFilePath ) {
798 mLines.clear();
799
800 std::vector<std::string> leftLines = String::split( oldText, '\n', true );
801 std::vector<std::string> rightLines = String::split( newText, '\n', true );
802
803 dtl::Diff<std::string> diff( leftLines, rightLines );
804 diff.compose();
805 auto ranges = diff.getSes().getSequence();
806
807 size_t leftIndex = 0;
808 size_t rightIndex = 0;
809
810 for ( auto& pair : ranges ) {
811 DiffLine dline;
812 dline.text = pair.first;
813 switch ( pair.second.type ) {
814 case dtl::SES_COMMON:
815 dline.type = DiffLineType::Common;
816 dline.oldLineNum = ++leftIndex;
817 dline.newLineNum = ++rightIndex;
818 break;
819 case dtl::SES_ADD:
820 dline.type = DiffLineType::Added;
821 dline.newLineNum = ++rightIndex;
822 break;
823 case dtl::SES_DELETE:
824 dline.type = DiffLineType::Removed;
825 dline.oldLineNum = ++leftIndex;
826 break;
827 }
828 mLines.push_back( dline );
829 }
830
831 applySubLineDiff( mLines, [this]( DiffLine& oldLine, DiffLine& newLine ) {
832 computeSubLineDiff( oldLine, newLine );
833 } );
834
835 if ( !originalFilePath.empty() ) {
836 auto def = SyntaxDefinitionManager::instance()->getByExtension( originalFilePath );
837 mSyntaxDef =
838 SyntaxDefinitionManager::instance()->getLanguageDefinition( def.getLanguageIndex() );
839 mFileName = FileSystem::fileNameFromPath( originalFilePath );
840 }
841
842 updateEditorsText();
843 updateButtonsText();
844 onSizeChange();
845}
846
847void UIDiffView::loadFromFile( const std::string& oldFilePath, const std::string& newFilePath ) {
848 std::string oldText, newText;

Callers 2

loadDiffFromStringsMethod · 0.80
UTESTFunction · 0.80

Calls 6

applySubLineDiffFunction · 0.85
push_backMethod · 0.80
getLanguageDefinitionMethod · 0.80
getLanguageIndexMethod · 0.80
clearMethod · 0.45
emptyMethod · 0.45

Tested by 1

UTESTFunction · 0.64