Skip to content

Commit

Permalink
fix: naming and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Apr 10, 2024
1 parent 07e47e2 commit 9dd7da4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
4 changes: 2 additions & 2 deletions plugins/scroll-options/src/AutoScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as Blockly from 'blockly/core';
import {ScrollMetricsManager} from './ScrollMetricsManager';
import {getTranslation} from './utils';
import {ScrollDragger} from './ScrollDragger';
import {ScrollBlockDragger} from './ScrollBlockDragger';

/**
* AutoScroll is used to scroll/pan the workspace automatically. For example,
Expand All @@ -24,7 +24,7 @@ export class AutoScroll {
/**
* Creates an AutoScroll instance for a specified workspace.
* @param {!Blockly.WorkspaceSvg} workspace Workspace to scroll.
* @param {!ScrollDragger} dragger The dragger that's currently dragging.
* @param {!ScrollBlockDragger} dragger The dragger that's currently dragging.
* @constructor
*/
constructor(workspace, dragger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const defaultOptions = {
* A block dragger that adds the functionality for a block to be moved while
* someone is dragging it.
*/
export class ScrollDragger extends Blockly.Dragger {
export class ScrollBlockDragger extends Blockly.Dragger {
/** @override */
constructor(draggable, workspace) {
super(draggable, workspace);
Expand Down Expand Up @@ -131,8 +131,7 @@ export class ScrollDragger extends Blockly.Dragger {
super.onDrag(e, totalDelta);
this.dragDelta_ = dragDelta;

console.log('here', ScrollDragger.edgeScrollEnabled);
if (ScrollDragger.edgeScrollEnabled) {
if (ScrollBlockDragger.edgeScrollEnabled) {
this.scrollWorkspaceWhileDragging_(e);
}
}
Expand Down Expand Up @@ -215,7 +214,6 @@ export class ScrollDragger extends Blockly.Dragger {
// Update the autoscroll or start a new one.
this.activeAutoScroll_ =
this.activeAutoScroll_ || new AutoScroll(this.workspace, this);
console.log('autoscoll');
this.activeAutoScroll_.updateProperties(overallScrollVector);
}

Expand Down Expand Up @@ -276,11 +274,11 @@ export class ScrollDragger extends Blockly.Dragger {
const blockOverflows = this.getBlockBoundsOverflows_(viewMetrics, mouse);
for (const direction of this.scrollDirections_) {
const overflow = blockOverflows[direction];
if (overflow > ScrollDragger.options.slowBlockStartDistance) {
if (overflow > ScrollBlockDragger.options.slowBlockStartDistance) {
const speed =
overflow > ScrollDragger.options.fastBlockStartDistance
? ScrollDragger.options.fastBlockSpeed
: ScrollDragger.options.slowBlockSpeed;
overflow > ScrollBlockDragger.options.fastBlockStartDistance
? ScrollBlockDragger.options.fastBlockSpeed
: ScrollBlockDragger.options.slowBlockSpeed;
const scrollVector = this.SCROLL_DIRECTION_VECTORS_[direction]
.clone()
.scale(speed);
Expand All @@ -307,11 +305,11 @@ export class ScrollDragger extends Blockly.Dragger {
const mouseOverflows = this.getMouseOverflows_(viewMetrics, mouse);
for (const direction of this.scrollDirections_) {
const overflow = mouseOverflows[direction];
if (overflow > ScrollDragger.options.slowMouseStartDistance) {
if (overflow > ScrollBlockDragger.options.slowMouseStartDistance) {
const speed =
overflow > ScrollDragger.options.fastMouseStartDistance
? ScrollDragger.options.fastMouseSpeed
: ScrollDragger.options.slowMouseSpeed;
overflow > ScrollBlockDragger.options.fastMouseStartDistance
? ScrollBlockDragger.options.fastMouseSpeed
: ScrollBlockDragger.options.slowMouseSpeed;
const scrollVector = this.SCROLL_DIRECTION_VECTORS_[direction]
.clone()
.scale(speed);
Expand Down Expand Up @@ -349,31 +347,31 @@ export class ScrollDragger extends Blockly.Dragger {
const blockHeight = blockBounds.bottom - blockBounds.top;
if (
blockHeight >
viewMetrics.height * ScrollDragger.options.oversizeBlockThreshold
viewMetrics.height * ScrollBlockDragger.options.oversizeBlockThreshold
) {
blockBounds.top = Math.max(
blockBounds.top,
mouse.y - ScrollDragger.options.oversizeBlockMargin,
mouse.y - ScrollBlockDragger.options.oversizeBlockMargin,
);
blockBounds.bottom = Math.min(
blockBounds.bottom,
mouse.y + ScrollDragger.options.oversizeBlockMargin,
mouse.y + ScrollBlockDragger.options.oversizeBlockMargin,
);
}

// Same logic, but for block width.
const blockWidth = blockBounds.right - blockBounds.left;
if (
blockWidth >
viewMetrics.width * ScrollDragger.options.oversizeBlockThreshold
viewMetrics.width * ScrollBlockDragger.options.oversizeBlockThreshold
) {
blockBounds.left = Math.max(
blockBounds.left,
mouse.x - ScrollDragger.options.oversizeBlockMargin,
mouse.x - ScrollBlockDragger.options.oversizeBlockMargin,
);
blockBounds.right = Math.min(
blockBounds.right,
mouse.x + ScrollDragger.options.oversizeBlockMargin,
mouse.x + ScrollBlockDragger.options.oversizeBlockMargin,
);
}

Expand Down Expand Up @@ -433,13 +431,13 @@ export class ScrollDragger extends Blockly.Dragger {
* the edge is enabled.
* @type {boolean}
*/
ScrollDragger.edgeScrollEnabled = true;
ScrollBlockDragger.edgeScrollEnabled = true;

/**
* Configuration options for the scroll-options settings.
* @type {!EdgeScrollOptions}
*/
ScrollDragger.options = defaultOptions;
ScrollBlockDragger.options = defaultOptions;

/**
* Update the scroll options. Only the properties actually included in the
Expand All @@ -462,19 +460,19 @@ ScrollDragger.options = defaultOptions;
* the available options. Any properties not present will use the existing
* value.
*/
ScrollDragger.updateOptions = function (options) {
ScrollDragger.options = {...ScrollDragger.options, ...options};
ScrollBlockDragger.updateOptions = function (options) {
ScrollBlockDragger.options = {...ScrollBlockDragger.options, ...options};
};

/**
* Resets the options object to the default options.
*/
ScrollDragger.resetOptions = function () {
ScrollDragger.options = defaultOptions;
ScrollBlockDragger.resetOptions = function () {
ScrollBlockDragger.options = defaultOptions;
};

Blockly.registry.register(
Blockly.registry.Type.DRAGGER,
Blockly.registry.Type.BLOCK_DRAGGER,
'ScrollDragger',
ScrollDragger,
ScrollBlockDragger,
);
14 changes: 7 additions & 7 deletions plugins/scroll-options/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import Blockly from 'blockly/core';
import {EdgeScrollOptions, ScrollDragger} from './ScrollDragger';
import {EdgeScrollOptions, ScrollBlockDragger} from './ScrollBlockDragger';
import {getTranslation} from './utils';

/**
Expand Down Expand Up @@ -63,10 +63,10 @@ export class ScrollOptions {
this.disableWheelScroll();
}

ScrollDragger.edgeScrollEnabled = enableEdgeScroll;
ScrollBlockDragger.edgeScrollEnabled = enableEdgeScroll;

if (edgeScrollOptions) {
ScrollDragger.updateOptions(edgeScrollOptions);
ScrollBlockDragger.updateOptions(edgeScrollOptions);
}
}

Expand Down Expand Up @@ -104,14 +104,14 @@ export class ScrollOptions {
* Enables scrolling when block is dragged near edge.
*/
enableEdgeScroll() {
ScrollDragger.edgeScrollEnabled = true;
ScrollBlockDragger.edgeScrollEnabled = true;
}

/**
* Disables scrolling when block is dragged near edge.
*/
disableEdgeScroll() {
ScrollDragger.edgeScrollEnabled = false;
ScrollBlockDragger.edgeScrollEnabled = false;
}

/**
Expand All @@ -121,7 +121,7 @@ export class ScrollOptions {
* @param {!EdgeScrollOptions} options Edge scroll options.
*/
updateEdgeScrollOptions(options) {
ScrollDragger.updateOptions(options);
ScrollBlockDragger.updateOptions(options);
}

/**
Expand Down Expand Up @@ -177,5 +177,5 @@ export class ScrollOptions {
}
}

export * from './ScrollDragger';
export * from './ScrollBlockDragger';
export * from './ScrollMetricsManager';
8 changes: 6 additions & 2 deletions plugins/scroll-options/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import {createPlayground, toolboxCategories} from '@blockly/dev-tools';
import * as Blockly from 'blockly';

import {ScrollDragger, ScrollMetricsManager, ScrollOptions} from '../src/index';
import {
ScrollBlockDragger,
ScrollMetricsManager,
ScrollOptions,
} from '../src/index';

/**
* Create a workspace.
Expand All @@ -35,7 +39,7 @@ document.addEventListener('DOMContentLoaded', function () {
toolbox: toolboxCategories,
plugins: {
// These are both required, even if you turn off edge scrolling.
dragger: ScrollDragger,
blockDragger: ScrollBlockDragger,
metricsManager: ScrollMetricsManager,
},
move: {
Expand Down

0 comments on commit 9dd7da4

Please sign in to comment.