Skip to content

Commit 6866e12

Browse files
jtydhr88github-actions
andauthored
new design for left click and wheel (#5566)
* new design for left click and wheel * update snap * fix import * fix test * default value * fix test * Update test expectations [skip ci] --------- Co-authored-by: github-actions <[email protected]>
1 parent ff5d092 commit 6866e12

File tree

12 files changed

+123
-351
lines changed

12 files changed

+123
-351
lines changed

browser_tests/tests/interaction.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,8 @@ test.describe('Canvas Navigation', () => {
10121012
test('Shift + mouse wheel should pan canvas horizontally', async ({
10131013
comfyPage
10141014
}) => {
1015+
await comfyPage.setSetting('Comfy.Canvas.MouseWheelScroll', 'panning')
1016+
10151017
await comfyPage.page.click('canvas')
10161018
await comfyPage.nextFrame()
10171019

-836 Bytes
Loading
-1.11 KB
Loading
4.13 KB
Loading

src/lib/litegraph/src/LGraphCanvas.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@ export class LGraphCanvas
23482348
if (
23492349
ctrlOrMeta &&
23502350
!e.altKey &&
2351-
LiteGraph.canvasNavigationMode === 'legacy'
2351+
LiteGraph.leftMouseClickBehavior === 'panning'
23522352
) {
23532353
this.#setupNodeSelectionDrag(e, pointer, node)
23542354

@@ -2616,8 +2616,8 @@ export class LGraphCanvas
26162616
!pointer.onDrag &&
26172617
this.allow_dragcanvas
26182618
) {
2619-
// allow dragging canvas if canvas is not in standard, or read-only (pan mode in standard)
2620-
if (LiteGraph.canvasNavigationMode !== 'standard' || this.read_only) {
2619+
// allow dragging canvas based on leftMouseClickBehavior or read-only mode
2620+
if (LiteGraph.leftMouseClickBehavior === 'panning' || this.read_only) {
26212621
pointer.onClick = () => this.processSelect(null, e)
26222622
pointer.finally = () => (this.dragging_canvas = false)
26232623
this.dragging_canvas = true
@@ -3629,8 +3629,8 @@ export class LGraphCanvas
36293629
e.ctrlKey || (e.metaKey && navigator.platform.includes('Mac'))
36303630
const isZoomModifier = isCtrlOrMacMeta && !e.altKey && !e.shiftKey
36313631

3632-
if (isZoomModifier || LiteGraph.canvasNavigationMode === 'legacy') {
3633-
// Legacy mode or standard mode with ctrl - use wheel for zoom
3632+
if (isZoomModifier || LiteGraph.mouseWheelScroll === 'zoom') {
3633+
// Zoom mode or modifier key pressed - use wheel for zoom
36343634
if (isTrackpad) {
36353635
// Trackpad gesture - use smooth scaling
36363636
scale *= 1 + e.deltaY * (1 - this.zoom_speed) * 0.18
@@ -3645,7 +3645,6 @@ export class LGraphCanvas
36453645
this.ds.changeScale(scale, [e.clientX, e.clientY])
36463646
}
36473647
} else {
3648-
// Standard mode without ctrl - use wheel / gestures to pan
36493648
// Trackpads and mice work on significantly different scales
36503649
const factor = isTrackpad ? 0.18 : 0.008_333
36513650

src/lib/litegraph/src/LiteGraphGlobal.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,14 @@ export class LiteGraphGlobal {
304304
/**
305305
* "standard": change the dragging on left mouse button click to select, enable middle-click or spacebar+left-click dragging
306306
* "legacy": Enable dragging on left-click (original behavior)
307+
* "custom": Use leftMouseClickBehavior and mouseWheelScroll settings
307308
* @default "legacy"
308309
*/
309-
canvasNavigationMode: 'standard' | 'legacy' = 'legacy'
310+
canvasNavigationMode: 'standard' | 'legacy' | 'custom' = 'legacy'
311+
312+
leftMouseClickBehavior: 'panning' | 'select' = 'panning'
313+
314+
mouseWheelScroll: 'panning' | 'zoom' = 'panning'
310315

311316
/**
312317
* If `true`, widget labels and values will both be truncated (proportionally to size),

src/lib/litegraph/test/__snapshots__/ConfigureGraph.test.ts.snap

Lines changed: 0 additions & 328 deletions
Original file line numberDiff line numberDiff line change
@@ -1,333 +1,5 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`LGraph configure() > LGraph matches previous snapshot (normal configure() usage) > configuredBasicGraph 1`] = `
4-
LGraph {
5-
"_groups": [
6-
LGraphGroup {
7-
"_bounding": Float32Array [
8-
20,
9-
20,
10-
1,
11-
3,
12-
],
13-
"_children": Set {},
14-
"_nodes": [],
15-
"_pos": Float32Array [
16-
20,
17-
20,
18-
],
19-
"_size": Float32Array [
20-
1,
21-
3,
22-
],
23-
"color": "#6029aa",
24-
"flags": {},
25-
"font": undefined,
26-
"font_size": 14,
27-
"graph": [Circular],
28-
"id": 123,
29-
"isPointInside": [Function],
30-
"selected": undefined,
31-
"setDirtyCanvas": [Function],
32-
"title": "A group to test with",
33-
},
34-
],
35-
"_input_nodes": undefined,
36-
"_last_trigger_time": undefined,
37-
"_links": Map {},
38-
"_nodes": [
39-
LGraphNode {
40-
"_collapsed_width": undefined,
41-
"_level": undefined,
42-
"_pos": Float32Array [
43-
10,
44-
10,
45-
],
46-
"_posSize": Float32Array [
47-
10,
48-
10,
49-
140,
50-
60,
51-
],
52-
"_relative_id": undefined,
53-
"_shape": undefined,
54-
"_size": Float32Array [
55-
140,
56-
60,
57-
],
58-
"action_call": undefined,
59-
"action_triggered": undefined,
60-
"badgePosition": "top-left",
61-
"badges": [],
62-
"bgcolor": undefined,
63-
"block_delete": undefined,
64-
"boxcolor": undefined,
65-
"clip_area": undefined,
66-
"clonable": undefined,
67-
"color": undefined,
68-
"console": undefined,
69-
"exec_version": undefined,
70-
"execute_triggered": undefined,
71-
"flags": {},
72-
"freeWidgetSpace": undefined,
73-
"gotFocusAt": undefined,
74-
"graph": [Circular],
75-
"has_errors": undefined,
76-
"id": 1,
77-
"ignore_remove": undefined,
78-
"inputs": [],
79-
"last_serialization": undefined,
80-
"locked": undefined,
81-
"lostFocusAt": undefined,
82-
"mode": 0,
83-
"mouseOver": undefined,
84-
"order": 0,
85-
"outputs": [],
86-
"progress": undefined,
87-
"properties": {},
88-
"properties_info": [],
89-
"redraw_on_mouse": undefined,
90-
"removable": undefined,
91-
"resizable": undefined,
92-
"selected": undefined,
93-
"serialize_widgets": undefined,
94-
"showAdvanced": undefined,
95-
"strokeStyles": {
96-
"error": [Function],
97-
"selected": [Function],
98-
},
99-
"title": "LGraphNode",
100-
"title_buttons": [],
101-
"type": "mustBeSet",
102-
"widgets": undefined,
103-
"widgets_start_y": undefined,
104-
"widgets_up": undefined,
105-
},
106-
],
107-
"_nodes_by_id": {
108-
"1": LGraphNode {
109-
"_collapsed_width": undefined,
110-
"_level": undefined,
111-
"_pos": Float32Array [
112-
10,
113-
10,
114-
],
115-
"_posSize": Float32Array [
116-
10,
117-
10,
118-
140,
119-
60,
120-
],
121-
"_relative_id": undefined,
122-
"_shape": undefined,
123-
"_size": Float32Array [
124-
140,
125-
60,
126-
],
127-
"action_call": undefined,
128-
"action_triggered": undefined,
129-
"badgePosition": "top-left",
130-
"badges": [],
131-
"bgcolor": undefined,
132-
"block_delete": undefined,
133-
"boxcolor": undefined,
134-
"clip_area": undefined,
135-
"clonable": undefined,
136-
"color": undefined,
137-
"console": undefined,
138-
"exec_version": undefined,
139-
"execute_triggered": undefined,
140-
"flags": {},
141-
"freeWidgetSpace": undefined,
142-
"gotFocusAt": undefined,
143-
"graph": [Circular],
144-
"has_errors": undefined,
145-
"id": 1,
146-
"ignore_remove": undefined,
147-
"inputs": [],
148-
"last_serialization": undefined,
149-
"locked": undefined,
150-
"lostFocusAt": undefined,
151-
"mode": 0,
152-
"mouseOver": undefined,
153-
"order": 0,
154-
"outputs": [],
155-
"progress": undefined,
156-
"properties": {},
157-
"properties_info": [],
158-
"redraw_on_mouse": undefined,
159-
"removable": undefined,
160-
"resizable": undefined,
161-
"selected": undefined,
162-
"serialize_widgets": undefined,
163-
"showAdvanced": undefined,
164-
"strokeStyles": {
165-
"error": [Function],
166-
"selected": [Function],
167-
},
168-
"title": "LGraphNode",
169-
"title_buttons": [],
170-
"type": "mustBeSet",
171-
"widgets": undefined,
172-
"widgets_start_y": undefined,
173-
"widgets_up": undefined,
174-
},
175-
},
176-
"_nodes_executable": [],
177-
"_nodes_in_order": [
178-
LGraphNode {
179-
"_collapsed_width": undefined,
180-
"_level": undefined,
181-
"_pos": Float32Array [
182-
10,
183-
10,
184-
],
185-
"_posSize": Float32Array [
186-
10,
187-
10,
188-
140,
189-
60,
190-
],
191-
"_relative_id": undefined,
192-
"_shape": undefined,
193-
"_size": Float32Array [
194-
140,
195-
60,
196-
],
197-
"action_call": undefined,
198-
"action_triggered": undefined,
199-
"badgePosition": "top-left",
200-
"badges": [],
201-
"bgcolor": undefined,
202-
"block_delete": undefined,
203-
"boxcolor": undefined,
204-
"clip_area": undefined,
205-
"clonable": undefined,
206-
"color": undefined,
207-
"console": undefined,
208-
"exec_version": undefined,
209-
"execute_triggered": undefined,
210-
"flags": {},
211-
"freeWidgetSpace": undefined,
212-
"gotFocusAt": undefined,
213-
"graph": [Circular],
214-
"has_errors": undefined,
215-
"id": 1,
216-
"ignore_remove": undefined,
217-
"inputs": [],
218-
"last_serialization": undefined,
219-
"locked": undefined,
220-
"lostFocusAt": undefined,
221-
"mode": 0,
222-
"mouseOver": undefined,
223-
"order": 0,
224-
"outputs": [],
225-
"progress": undefined,
226-
"properties": {},
227-
"properties_info": [],
228-
"redraw_on_mouse": undefined,
229-
"removable": undefined,
230-
"resizable": undefined,
231-
"selected": undefined,
232-
"serialize_widgets": undefined,
233-
"showAdvanced": undefined,
234-
"strokeStyles": {
235-
"error": [Function],
236-
"selected": [Function],
237-
},
238-
"title": "LGraphNode",
239-
"title_buttons": [],
240-
"type": "mustBeSet",
241-
"widgets": undefined,
242-
"widgets_start_y": undefined,
243-
"widgets_up": undefined,
244-
},
245-
],
246-
"_subgraphs": Map {},
247-
"_version": 3,
248-
"catch_errors": true,
249-
"config": {},
250-
"elapsed_time": 0.01,
251-
"errors_in_execution": undefined,
252-
"events": CustomEventTarget {},
253-
"execution_time": undefined,
254-
"execution_timer_id": undefined,
255-
"extra": {},
256-
"filter": undefined,
257-
"fixedtime": 0,
258-
"fixedtime_lapse": 0.01,
259-
"globaltime": 0,
260-
"id": "ca9da7d8-fddd-4707-ad32-67be9be13140",
261-
"iteration": 0,
262-
"last_update_time": 0,
263-
"links": Map {},
264-
"list_of_graphcanvas": null,
265-
"nodes_actioning": [],
266-
"nodes_executedAction": [],
267-
"nodes_executing": [],
268-
"revision": 0,
269-
"runningtime": 0,
270-
"starttime": 0,
271-
"state": {
272-
"lastGroupId": 123,
273-
"lastLinkId": 0,
274-
"lastNodeId": 1,
275-
"lastRerouteId": 0,
276-
},
277-
"status": 1,
278-
"vars": {},
279-
"version": 1,
280-
}
281-
`;
282-
283-
exports[`LGraph configure() > LGraph matches previous snapshot (normal configure() usage) > configuredMinGraph 1`] = `
284-
LGraph {
285-
"_groups": [],
286-
"_input_nodes": undefined,
287-
"_last_trigger_time": undefined,
288-
"_links": Map {},
289-
"_nodes": [],
290-
"_nodes_by_id": {},
291-
"_nodes_executable": [],
292-
"_nodes_in_order": [],
293-
"_subgraphs": Map {},
294-
"_version": 0,
295-
"catch_errors": true,
296-
"config": {},
297-
"elapsed_time": 0.01,
298-
"errors_in_execution": undefined,
299-
"events": CustomEventTarget {},
300-
"execution_time": undefined,
301-
"execution_timer_id": undefined,
302-
"extra": {},
303-
"filter": undefined,
304-
"fixedtime": 0,
305-
"fixedtime_lapse": 0.01,
306-
"globaltime": 0,
307-
"id": "d175890f-716a-4ece-ba33-1d17a513b7be",
308-
"iteration": 0,
309-
"last_update_time": 0,
310-
"links": Map {},
311-
"list_of_graphcanvas": null,
312-
"nodes_actioning": [],
313-
"nodes_executedAction": [],
314-
"nodes_executing": [],
315-
"revision": 0,
316-
"runningtime": 0,
317-
"starttime": 0,
318-
"state": {
319-
"lastGroupId": 0,
320-
"lastLinkId": 0,
321-
"lastNodeId": 0,
322-
"lastRerouteId": 0,
323-
},
324-
"status": 1,
325-
"vars": {},
326-
"version": 1,
327-
}
328-
`;
329-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
330-
3313
exports[`LGraph configure() > LGraph matches previous snapshot (normal configure() usage) > configuredBasicGraph 1`] = `
3324
LGraph {
3335
"_groups": [

0 commit comments

Comments
 (0)