FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(editor): ensure editor context in installDblClickHandler callback by tbouffard · Pull Request #934 · maxGraph/maxGraph · GitHub

forked from jgraph/mxgraph
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
33 changes: 32 additions & 1 deletion packages/core/__tests__/editor/Editor.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import { describe, expect, test } from '@jest/globals';
import { Editor, Geometry } from '../../src';
import { Editor, Geometry, EventObject, InternalEvent } from '../../src';
import { ModelChecker } from '../serialization/utils';
import { parseXml } from '../../src/util/xmlUtils';
import Cell from '../../src/view/cell/Cell';
Expand Down Expand Up @@ -138,3 +138,34 @@ describe('cycleAttribute', () => {
expect(cell.getStyle()).toEqual(originalStyle);
});
});

describe('installDblClickHandler', () => {
test('double-click handler has correct editor context', () => {
const editor = new Editor(null!);
const mockExecute = jest.fn();
editor.execute = mockExecute;
editor.dblClickAction = 'testAction';

// Create a container element for the graph
const container = document.createElement('div');
document.body.appendChild(container);
editor.setGraphContainer(container);

// Create a test cell
const cell = editor.graph.insertVertex({
value: 'test',
position: [10, 10],
size: [100, 100],
});

// Fire the DOUBLE_CLICK event with proper EventObject
const eventObj = new EventObject(InternalEvent.DOUBLE_CLICK, { cell, event: {} });
editor.graph.fireEvent(eventObj);

// Verify that execute was called on the editor instance with the correct action and cell
expect(mockExecute).toHaveBeenCalledWith('testAction', cell);

// Clean up
container.remove();
});
});
5 changes: 3 additions & 2 deletions packages/core/src/editor/Editor.ts
Show comments Show annotations View file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1532,12 +1532,13 @@
* @param graph
*/
installDblClickHandler(graph: AbstractGraph): void {
const editor = this;

Check warning on line 1535 in packages/core/src/editor/Editor.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04)

Unexpected aliasing of 'this' to local variable

Check warning on line 1535 in packages/core/src/editor/Editor.ts

View workflow job for this annotation

GitHub Actions / build (macos-14)

Unexpected aliasing of 'this' to local variable

Check warning on line 1535 in packages/core/src/editor/Editor.ts

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Unexpected aliasing of 'this' to local variable
// Installs a listener for double click events
graph.addListener(InternalEvent.DOUBLE_CLICK, (sender: any, evt: EventObject) => {
const cell = evt.getProperty('cell');

if (cell != null && graph.isEnabled() && this.dblClickAction != null) {
this.execute(this.dblClickAction, cell);
if (cell != null && graph.isEnabled() && editor.dblClickAction != null) {
editor.execute(editor.dblClickAction, cell);
evt.consume();
}
});
Expand Down

Back | FazBrowse Home | New Git URL