pxt-core 7.4.23 → 7.4.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9947,8 +9947,71 @@ var pxt;
9947
9947
  Blockly.utils.dom.removeClass(blockPath, 'blockly-ws-search-highlight-pxt');
9948
9948
  });
9949
9949
  }
9950
+ /**
9951
+ * https://github.com/google/blockly-samples/blob/master/plugins/workspace-search/src/WorkspaceSearch.js#L633
9952
+ *
9953
+ * Modified to center offscreen blocks.
9954
+ */
9955
+ scrollToVisible_(block) {
9956
+ if (!this.workspace_.isMovable()) {
9957
+ // Cannot scroll to block in a non-movable workspace.
9958
+ return;
9959
+ }
9960
+ // XY is in workspace coordinates.
9961
+ const xy = block.getRelativeToSurfaceXY();
9962
+ const scale = this.workspace_.scale;
9963
+ // Block bounds in pixels relative to the workspace origin (0,0 is centre).
9964
+ const width = block.width * scale;
9965
+ const height = block.height * scale;
9966
+ const top = xy.y * scale;
9967
+ const bottom = (xy.y + block.height) * scale;
9968
+ // In RTL the block's position is the top right of the block, not top left.
9969
+ const left = this.workspace_.RTL ? xy.x * scale - width : xy.x * scale;
9970
+ const right = this.workspace_.RTL ? xy.x * scale : xy.x * scale + width;
9971
+ const metrics = this.workspace_.getMetrics();
9972
+ let targetLeft = metrics.viewLeft;
9973
+ const overflowLeft = left < metrics.viewLeft;
9974
+ const overflowRight = right > metrics.viewLeft + metrics.viewWidth;
9975
+ const wideBlock = width > metrics.viewWidth;
9976
+ if ((!wideBlock && overflowLeft) || (wideBlock && !this.workspace_.RTL)) {
9977
+ // Scroll to show left side of block
9978
+ targetLeft = left;
9979
+ }
9980
+ else if ((!wideBlock && overflowRight) ||
9981
+ (wideBlock && this.workspace_.RTL)) {
9982
+ // Scroll to show right side of block
9983
+ targetLeft = right - metrics.viewWidth;
9984
+ }
9985
+ let targetTop = metrics.viewTop;
9986
+ const overflowTop = top < metrics.viewTop;
9987
+ const overflowBottom = bottom > metrics.viewTop + metrics.viewHeight;
9988
+ const tallBlock = height > metrics.viewHeight;
9989
+ if (overflowTop || (tallBlock && overflowBottom)) {
9990
+ // Scroll to show top of block
9991
+ targetTop = top;
9992
+ }
9993
+ else if (overflowBottom) {
9994
+ // Scroll to show bottom of block
9995
+ targetTop = bottom - metrics.viewHeight;
9996
+ }
9997
+ if (targetLeft !== metrics.viewLeft || targetTop !== metrics.viewTop) {
9998
+ const activeEl = document.activeElement;
9999
+ if (wideBlock || tallBlock) {
10000
+ this.workspace_.scroll(-targetLeft, -targetTop);
10001
+ }
10002
+ else {
10003
+ this.workspace_.centerOnBlock(block.id);
10004
+ }
10005
+ if (activeEl) {
10006
+ // Blockly.WidgetDiv.hide called in scroll is taking away focus.
10007
+ // TODO: Review setFocused call in Blockly.WidgetDiv.hide.
10008
+ activeEl.focus();
10009
+ }
10010
+ }
10011
+ }
9950
10012
  open() {
9951
10013
  super.open();
10014
+ this.inputElement_.select();
9952
10015
  Blockly.utils.dom.addClass(this.workspace_.getInjectionDiv(), 'blockly-ws-searching');
9953
10016
  }
9954
10017
  close() {
@@ -264,6 +264,12 @@ declare namespace pxt.blocks {
264
264
  protected createDom_(): void;
265
265
  protected highlightSearchGroup_(blocks: Blockly.BlockSvg[]): void;
266
266
  protected unhighlightSearchGroup_(blocks: Blockly.BlockSvg[]): void;
267
+ /**
268
+ * https://github.com/google/blockly-samples/blob/master/plugins/workspace-search/src/WorkspaceSearch.js#L633
269
+ *
270
+ * Modified to center offscreen blocks.
271
+ */
272
+ protected scrollToVisible_(block: Blockly.BlockSvg): void;
267
273
  open(): void;
268
274
  close(): void;
269
275
  }
@@ -6324,8 +6324,71 @@ var pxt;
6324
6324
  Blockly.utils.dom.removeClass(blockPath, 'blockly-ws-search-highlight-pxt');
6325
6325
  });
6326
6326
  }
6327
+ /**
6328
+ * https://github.com/google/blockly-samples/blob/master/plugins/workspace-search/src/WorkspaceSearch.js#L633
6329
+ *
6330
+ * Modified to center offscreen blocks.
6331
+ */
6332
+ scrollToVisible_(block) {
6333
+ if (!this.workspace_.isMovable()) {
6334
+ // Cannot scroll to block in a non-movable workspace.
6335
+ return;
6336
+ }
6337
+ // XY is in workspace coordinates.
6338
+ const xy = block.getRelativeToSurfaceXY();
6339
+ const scale = this.workspace_.scale;
6340
+ // Block bounds in pixels relative to the workspace origin (0,0 is centre).
6341
+ const width = block.width * scale;
6342
+ const height = block.height * scale;
6343
+ const top = xy.y * scale;
6344
+ const bottom = (xy.y + block.height) * scale;
6345
+ // In RTL the block's position is the top right of the block, not top left.
6346
+ const left = this.workspace_.RTL ? xy.x * scale - width : xy.x * scale;
6347
+ const right = this.workspace_.RTL ? xy.x * scale : xy.x * scale + width;
6348
+ const metrics = this.workspace_.getMetrics();
6349
+ let targetLeft = metrics.viewLeft;
6350
+ const overflowLeft = left < metrics.viewLeft;
6351
+ const overflowRight = right > metrics.viewLeft + metrics.viewWidth;
6352
+ const wideBlock = width > metrics.viewWidth;
6353
+ if ((!wideBlock && overflowLeft) || (wideBlock && !this.workspace_.RTL)) {
6354
+ // Scroll to show left side of block
6355
+ targetLeft = left;
6356
+ }
6357
+ else if ((!wideBlock && overflowRight) ||
6358
+ (wideBlock && this.workspace_.RTL)) {
6359
+ // Scroll to show right side of block
6360
+ targetLeft = right - metrics.viewWidth;
6361
+ }
6362
+ let targetTop = metrics.viewTop;
6363
+ const overflowTop = top < metrics.viewTop;
6364
+ const overflowBottom = bottom > metrics.viewTop + metrics.viewHeight;
6365
+ const tallBlock = height > metrics.viewHeight;
6366
+ if (overflowTop || (tallBlock && overflowBottom)) {
6367
+ // Scroll to show top of block
6368
+ targetTop = top;
6369
+ }
6370
+ else if (overflowBottom) {
6371
+ // Scroll to show bottom of block
6372
+ targetTop = bottom - metrics.viewHeight;
6373
+ }
6374
+ if (targetLeft !== metrics.viewLeft || targetTop !== metrics.viewTop) {
6375
+ const activeEl = document.activeElement;
6376
+ if (wideBlock || tallBlock) {
6377
+ this.workspace_.scroll(-targetLeft, -targetTop);
6378
+ }
6379
+ else {
6380
+ this.workspace_.centerOnBlock(block.id);
6381
+ }
6382
+ if (activeEl) {
6383
+ // Blockly.WidgetDiv.hide called in scroll is taking away focus.
6384
+ // TODO: Review setFocused call in Blockly.WidgetDiv.hide.
6385
+ activeEl.focus();
6386
+ }
6387
+ }
6388
+ }
6327
6389
  open() {
6328
6390
  super.open();
6391
+ this.inputElement_.select();
6329
6392
  Blockly.utils.dom.addClass(this.workspace_.getInjectionDiv(), 'blockly-ws-searching');
6330
6393
  }
6331
6394
  close() {