From 043f102cf188fba500f3f08eca28667418048669 Mon Sep 17 00:00:00 2001 From: Shachar <34343793+ShaMan123@users.noreply.github.com> Date: Sat, 19 Feb 2022 01:01:00 +0200 Subject: [PATCH] MINOR: feat(fabric.Canvas): add `getTopContext` method to expose the internal contextTop (#7697) --- src/canvas.class.js | 8 ++++++++ test/unit/canvas.js | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/canvas.class.js b/src/canvas.class.js index 2b3a2c1857a..66e90451f2a 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -933,6 +933,14 @@ this.contextTop = upperCanvasEl.getContext('2d'); }, + /** + * Returns context of top canvas where interactions are drawn + * @returns {CanvasRenderingContext2D} + */ + getTopContext: function () { + return this.contextTop; + }, + /** * @private */ diff --git a/test/unit/canvas.js b/test/unit/canvas.js index 271f9ffaa5b..a2d09d6e676 100644 --- a/test/unit/canvas.js +++ b/test/unit/canvas.js @@ -2527,6 +2527,11 @@ assert.ok(typeof InheritedCanvasClass === 'function'); }); + + QUnit.test('canvas getTopContext', function(assert) { + assert.ok(typeof canvas.getTopContext === 'function'); + assert.equal(canvas.getTopContext(), canvas.contextTop, 'it jsut returns contextTop'); + }); QUnit.test('_shouldCenterTransform', function(assert) { assert.equal(