From 084152ec091cc8307d1a89caf162c48f089e48f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 27 Mar 2026 11:24:05 -0300 Subject: [PATCH] Don't force the Diff View when opening diff or patch files, give a menu option to show the diff preview (closes issue SpartanJ/ecode#863). --- src/tools/ecode/ecode.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index e96923929..3b5fc4197 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2793,8 +2793,6 @@ bool App::loadFileFromPath( } else if ( ( SoundFileFactory::isKnownFileExtension( path ) || tryFindMimeType ) && SoundFileFactory::isValidAudioFile( path ) ) { loadAudioFromPath( path ); - } else if ( ext == "diff" || ext == "patch" ) { - loadDiffFromPath( path ); } else if ( !openBinaryAsDocument && PathHelper::isOpenExternalExtension( ext ) ) { Engine::instance()->openURI( path ); } else if ( tryFindMimeType && TextDocument::fileMightBeBinary( path ) ) { @@ -3264,6 +3262,19 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { if ( removeUnusedEditor ) splitter->removeUnusedTab( tabWidget ); } ); + } else if ( ext == "diff" || ext == "patch" ) { + editor->getDocument().setCommand( + "show-diff-preview", [this]( TextDocument::Client* client ) { + auto editor = static_cast( client ); + if ( getSplitter()->editorExists( editor ) ) { + if ( !editor->isDirty() ) { + loadDiffFromPath( editor->getDocument().getFilePath() ); + } else { + loadDiffFromMemory( editor->getDocument().getText().toUtf8(), + editor->getDocument().getFilePath() ); + } + } + } ); } editor->getDocument().setCommand( "compare-to", [this]( TextDocument::Client* client ) { @@ -3314,6 +3325,11 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { menu->add( i18n( "show_markdown_preview", "Show Markdown Live Preview" ), findIcon( "filetype-md" ) ) ->setId( "show-markdown-preview" ); + } else if ( ext == "diff" || ext == "patch" ) { + menu->addSeparator(); + menu->add( i18n( "show_diff_preview", "Show Diff Preview" ), + findIcon( "filetype-diff" ) ) + ->setId( "show-diff-preview" ); } } );