diff --git a/src/tabs/presets/SourcesDialog/PresetSource.js b/src/tabs/presets/SourcesDialog/PresetSource.js index ead8760d..914dafd1 100644 --- a/src/tabs/presets/SourcesDialog/PresetSource.js +++ b/src/tabs/presets/SourcesDialog/PresetSource.js @@ -9,4 +9,15 @@ export default class PresetSource { static isUrlGithubRepo(url) { return url.trim().toLowerCase().startsWith("https://github.com/"); } + + static containsBranchName(url) { + return url.includes("/tree/"); + } + + static getBranchName(url) { + const pattern = /https:\/\/github\.com\/[^\/]+\/[^\/]+\/tree\/([^\/]+)/; + const match = url.match(pattern); + + return match ? match[1] : null; + } } diff --git a/src/tabs/presets/SourcesDialog/SourcePanel.js b/src/tabs/presets/SourcesDialog/SourcePanel.js index 7bf11869..b3162e5c 100644 --- a/src/tabs/presets/SourcesDialog/SourcePanel.js +++ b/src/tabs/presets/SourcesDialog/SourcePanel.js @@ -147,6 +147,10 @@ export default class SourcePanel { _onInputChange() { this._checkIfGithub(); + if (PresetSource.containsBranchName(this._domEditUrl.val())) { + this._domEditGitHubBranch.val(PresetSource.getBranchName(this._domEditUrl.val())); + this._domEditUrl.val(this._domEditUrl.val().split("/tree/")[0]); + } this._setIsSaved(false); }