From 9a150964f235ebe80338e2bca34fe2d3a2de4980 Mon Sep 17 00:00:00 2001 From: Sergei Shmakov Date: Tue, 14 Jul 2026 17:47:08 +0200 Subject: [PATCH 1/2] Optimizes graph columns for narrow layouts Automatically adjusts column visibility and mode when the graph view is horizontally constrained. Hides SHA and Changes columns, and sets the Graph column to compact mode to improve space utilization. Related column commands in context menus are disabled, and an informational message is displayed to explain the automatic adjustments. Ensures these layout-driven overrides are not persisted as user preferences, preserving custom column settings for wider graph views. (#5500, #5391) --- contributions.json | 21 ++- package.json | 130 ++++++++------- src/constants.commands.generated.ts | 1 + src/webviews/apps/plus/graph/graph-app.ts | 10 ++ .../plus/graph/graph-wrapper/graph-wrapper.ts | 155 +++++++++++++++++- 5 files changed, 253 insertions(+), 64 deletions(-) diff --git a/contributions.json b/contributions.json index d2b91ed59fda4..2182f0121bd80 100644 --- a/contributions.json +++ b/contributions.json @@ -3016,7 +3016,7 @@ }, "gitlens.graph.columnChangesOff": { "label": "Hide Changes Column", - "enablement": "webviewItemValue =~ /\\bcolumns:canHide\\b/", + "enablement": "webviewItemValue =~ /\\bcolumns:canHide\\b/ && !(webviewItemValue =~ /\\bcolumns:narrow\\b/)", "menus": { "webview/context": [ { @@ -3029,6 +3029,7 @@ }, "gitlens.graph.columnChangesOn": { "label": "Show Changes Column", + "enablement": "!(webviewItemValue =~ /\\bcolumns:narrow\\b/)", "menus": { "webview/context": [ { @@ -3066,6 +3067,7 @@ }, "gitlens.graph.columnGraphCompact": { "label": "Use Compact Graph Column", + "enablement": "!(webviewItemValue =~ /\\bcolumns:narrow\\b/)", "menus": { "webview/context": [ { @@ -3078,6 +3080,7 @@ }, "gitlens.graph.columnGraphDefault": { "label": "Use Expanded Graph Column", + "enablement": "!(webviewItemValue =~ /\\bcolumns:narrow\\b/)", "menus": { "webview/context": [ { @@ -3165,7 +3168,7 @@ }, "gitlens.graph.columnShaOff": { "label": "Hide SHA Column", - "enablement": "webviewItemValue =~ /\\bcolumns:canHide\\b/", + "enablement": "webviewItemValue =~ /\\bcolumns:canHide\\b/ && !(webviewItemValue =~ /\\bcolumns:narrow\\b/)", "menus": { "webview/context": [ { @@ -3178,6 +3181,7 @@ }, "gitlens.graph.columnShaOn": { "label": "Show SHA Column", + "enablement": "!(webviewItemValue =~ /\\bcolumns:narrow\\b/)", "menus": { "webview/context": [ { @@ -3188,6 +3192,19 @@ ] } }, + "gitlens.graph.columnsNarrowInfo": { + "label": "Some Options Return When the Graph Is Wider", + "enablement": "false", + "menus": { + "webview/context": [ + { + "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumns:narrow\\b/", + "group": "1_columns", + "order": 0 + } + ] + } + }, "gitlens.graph.commitViaSCM": { "label": "Commit via Source Control..." }, diff --git a/package.json b/package.json index bcc5b81cd7df0..91edefa484559 100644 --- a/package.json +++ b/package.json @@ -7809,11 +7809,12 @@ { "command": "gitlens.graph.columnChangesOff", "title": "Hide Changes Column", - "enablement": "webviewItemValue =~ /\\bcolumns:canHide\\b/" + "enablement": "webviewItemValue =~ /\\bcolumns:canHide\\b/ && !(webviewItemValue =~ /\\bcolumns:narrow\\b/)" }, { "command": "gitlens.graph.columnChangesOn", - "title": "Show Changes Column" + "title": "Show Changes Column", + "enablement": "!(webviewItemValue =~ /\\bcolumns:narrow\\b/)" }, { "command": "gitlens.graph.columnDateTimeOff", @@ -7826,11 +7827,13 @@ }, { "command": "gitlens.graph.columnGraphCompact", - "title": "Use Compact Graph Column" + "title": "Use Compact Graph Column", + "enablement": "!(webviewItemValue =~ /\\bcolumns:narrow\\b/)" }, { "command": "gitlens.graph.columnGraphDefault", - "title": "Use Expanded Graph Column" + "title": "Use Expanded Graph Column", + "enablement": "!(webviewItemValue =~ /\\bcolumns:narrow\\b/)" }, { "command": "gitlens.graph.columnGraphOff", @@ -7862,11 +7865,17 @@ { "command": "gitlens.graph.columnShaOff", "title": "Hide SHA Column", - "enablement": "webviewItemValue =~ /\\bcolumns:canHide\\b/" + "enablement": "webviewItemValue =~ /\\bcolumns:canHide\\b/ && !(webviewItemValue =~ /\\bcolumns:narrow\\b/)" }, { "command": "gitlens.graph.columnShaOn", - "title": "Show SHA Column" + "title": "Show SHA Column", + "enablement": "!(webviewItemValue =~ /\\bcolumns:narrow\\b/)" + }, + { + "command": "gitlens.graph.columnsNarrowInfo", + "title": "Some Options Return When the Graph Is Wider", + "enablement": "false" }, { "command": "gitlens.graph.commitViaSCM", @@ -13611,6 +13620,10 @@ "command": "gitlens.graph.columnShaOn", "when": "false" }, + { + "command": "gitlens.graph.columnsNarrowInfo", + "when": "false" + }, { "command": "gitlens.graph.commitViaSCM", "when": "false" @@ -27183,11 +27196,6 @@ "when": "webviewItem =~ /gitlens:commit\\b/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && gitlens:ai:allowed", "group": "1_gitlens_ai@10" }, - { - "submenu": "gitlens/graph/commit/changes", - "when": "webviewItem =~ /gitlens:(commit|stash|wip)\\b/ && !listMultiSelection", - "group": "2_gitlens_quickopen@1" - }, { "command": "gitlens.graph.openCommitOnRemote", "when": "webviewItem =~ /gitlens:commit\\b/ && !listMultiSelection && gitlens:repos:withRemotes", @@ -27313,6 +27321,11 @@ "when": "webviewItem =~ /gitlens:(branch|commit|stash|tag|file\\b(?=.*?\\b\\+(committed|staged|unstaged)\\b))\\b/", "group": "7_gitlens_a_share@1" }, + { + "submenu": "gitlens/graph/commit/changes", + "when": "webviewItem =~ /gitlens:(commit|stash|wip)\\b/ && !listMultiSelection", + "group": "2_gitlens_quickopen@1" + }, { "command": "gitlens.discardChanges:commitDetails", "when": "webviewItem =~ /gitlens:file\\b(?=.*?\\b\\+(staged|unstaged|conflict)\\b)/ && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webview == gitlens.views.commitDetails", @@ -27503,6 +27516,11 @@ "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/", "group": "0_markers@0" }, + { + "command": "gitlens.graph.columnsNarrowInfo", + "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumns:narrow\\b/", + "group": "1_columns@0" + }, { "command": "gitlens.graph.columnAuthorOff", "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:author:visible\\b/", @@ -27563,51 +27581,6 @@ "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:sha:hidden\\b/", "group": "1_columns@7" }, - { - "command": "gitlens.graph.columnGraphCompact", - "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:graph:visible(?![^,]*\\+compact\\b)/", - "group": "2_columns@2" - }, - { - "command": "gitlens.graph.columnGraphDefault", - "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:graph:visible[^,]*\\+compact\\b/", - "group": "2_columns@2" - }, - { - "command": "gitlens.fetchRemote:graph", - "when": "webviewItem =~ /gitlens:remote\\b/ && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders", - "group": "1_gitlens_actions@1" - }, - { - "command": "gitlens.discardChanges.multi:commitDetails", - "when": "listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webview == gitlens.views.commitDetails && webviewItemsUnion =~ /gitlens:file\\b(?=.*?\\b\\+(staged|unstaged|conflict)\\b)(?!.*?\\b\\+(committed|stashed)\\b)/", - "group": "1_gitlens_actions@3" - }, - { - "command": "gitlens.discardChanges.multi:graphDetails", - "when": "webviewItemsUnion =~ /gitlens:file\\b(?=.*?\\b\\+(staged|unstaged|conflict)\\b)(?!.*?\\b\\+(committed|stashed)\\b)/ && listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && (webview == gitlens.graph || webview == gitlens.views.graph)", - "group": "1_gitlens_actions@3" - }, - { - "command": "gitlens.copyRelativePathToClipboard:commitDetails", - "when": "webviewItem =~ /gitlens:(file|folder)\\b/ && webview == gitlens.views.commitDetails", - "group": "7_gitlens_cutcopypaste@2" - }, - { - "command": "gitlens.copyRelativePathToClipboard:graphDetails", - "when": "webviewItem =~ /gitlens:(file|folder)\\b/ && (webview == gitlens.graph || webview == gitlens.views.graph)", - "group": "7_gitlens_cutcopypaste@2" - }, - { - "command": "gitlens.graph.columnAuthorOn", - "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:author:hidden\\b/", - "group": "1_columns@1" - }, - { - "command": "gitlens.graph.columnChangesOff", - "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:changes:visible\\b/", - "group": "1_columns@3" - }, { "command": "gitlens.graph.setStyleAuto", "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && config.gitlens.graph.experimental.useNewEngine", @@ -27623,6 +27596,16 @@ "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && config.gitlens.graph.experimental.useNewEngine", "group": "2_columns@1" }, + { + "command": "gitlens.graph.columnGraphCompact", + "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:graph:visible(?![^,]*\\+compact\\b)/", + "group": "2_columns@2" + }, + { + "command": "gitlens.graph.columnGraphDefault", + "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:graph:visible[^,]*\\+compact\\b/", + "group": "2_columns@2" + }, { "command": "gitlens.graph.setLaneDensityToCompact", "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && config.gitlens.graph.experimental.useNewEngine && webviewItemValue =~ /lanes:density:expanded\\b/", @@ -27673,11 +27656,46 @@ "when": "webviewItem =~ /gitlens:rebase:conflict\\+file\\b(?=.*?\\+canStageIncoming\\b)/ && webview == gitlens.rebase", "group": "1_conflict@2" }, + { + "command": "gitlens.fetchRemote:graph", + "when": "webviewItem =~ /gitlens:remote\\b/ && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders", + "group": "1_gitlens_actions@1" + }, { "command": "gitlens.pruneRemote:graph", "when": "webviewItem =~ /gitlens:remote\\b/ && !gitlens:readonly && !gitlens:untrusted", "group": "1_gitlens_actions@2" }, + { + "command": "gitlens.discardChanges.multi:commitDetails", + "when": "listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webview == gitlens.views.commitDetails && webviewItemsUnion =~ /gitlens:file\\b(?=.*?\\b\\+(staged|unstaged|conflict)\\b)(?!.*?\\b\\+(committed|stashed)\\b)/", + "group": "1_gitlens_actions@3" + }, + { + "command": "gitlens.discardChanges.multi:graphDetails", + "when": "webviewItemsUnion =~ /gitlens:file\\b(?=.*?\\b\\+(staged|unstaged|conflict)\\b)(?!.*?\\b\\+(committed|stashed)\\b)/ && listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && (webview == gitlens.graph || webview == gitlens.views.graph)", + "group": "1_gitlens_actions@3" + }, + { + "command": "gitlens.copyRelativePathToClipboard:commitDetails", + "when": "webviewItem =~ /gitlens:(file|folder)\\b/ && webview == gitlens.views.commitDetails", + "group": "7_gitlens_cutcopypaste@2" + }, + { + "command": "gitlens.copyRelativePathToClipboard:graphDetails", + "when": "webviewItem =~ /gitlens:(file|folder)\\b/ && (webview == gitlens.graph || webview == gitlens.views.graph)", + "group": "7_gitlens_cutcopypaste@2" + }, + { + "command": "gitlens.graph.columnAuthorOn", + "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:author:hidden\\b/", + "group": "1_columns@1" + }, + { + "command": "gitlens.graph.columnChangesOff", + "when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/ && webviewItemValue =~ /\\bcolumn:changes:visible\\b/", + "group": "1_columns@3" + }, { "command": "gitlens.openRepoOnRemote:graph", "when": "webviewItem =~ /gitlens:remote\\b/", diff --git a/src/constants.commands.generated.ts b/src/constants.commands.generated.ts index 12b0807b42403..a9585812adfd5 100644 --- a/src/constants.commands.generated.ts +++ b/src/constants.commands.generated.ts @@ -164,6 +164,7 @@ export type ContributedCommands = | 'gitlens.graph.columnRefOn' | 'gitlens.graph.columnShaOff' | 'gitlens.graph.columnShaOn' + | 'gitlens.graph.columnsNarrowInfo' | 'gitlens.graph.compareAncestryWithWorking' | 'gitlens.graph.compareBranchWithHead' | 'gitlens.graph.compareSelectedCommits.multi' diff --git a/src/webviews/apps/plus/graph/graph-app.ts b/src/webviews/apps/plus/graph/graph-app.ts index 939cb8e736dd1..ac83e19301673 100644 --- a/src/webviews/apps/plus/graph/graph-app.ts +++ b/src/webviews/apps/plus/graph/graph-app.ts @@ -2010,6 +2010,7 @@ export class GraphApp extends SignalWatcher(LitElement) { : nothing}