Skip to content

Commit d0d70a9

Browse files
fix: delete MarkerSvg (marker drawer)
1 parent acdad98 commit d0d70a9

File tree

12 files changed

+2
-1205
lines changed

12 files changed

+2
-1205
lines changed

core/block_svg.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,6 @@ export class BlockSvg
16791679
this.tightenChildrenEfficiently();
16801680

16811681
dom.stopTextWidthCache();
1682-
this.updateMarkers_();
16831682
}
16841683

16851684
/**
@@ -1699,22 +1698,6 @@ export class BlockSvg
16991698
if (this.nextConnection) this.nextConnection.tightenEfficiently();
17001699
}
17011700

1702-
/** Redraw any attached marker or cursor svgs if needed. */
1703-
protected updateMarkers_() {
1704-
if (this.workspace.keyboardAccessibilityMode && this.pathObject.cursorSvg) {
1705-
this.workspace.getCursor()!.draw();
1706-
}
1707-
if (this.workspace.keyboardAccessibilityMode && this.pathObject.markerSvg) {
1708-
// TODO(#4592): Update all markers on the block.
1709-
this.workspace.getMarker(MarkerManager.LOCAL_MARKER)!.draw();
1710-
}
1711-
for (const input of this.inputList) {
1712-
for (const field of input.fieldRow) {
1713-
field.updateMarkers_();
1714-
}
1715-
}
1716-
}
1717-
17181701
/**
17191702
* Add the cursor SVG to this block's SVG group.
17201703
*

core/field.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,26 +1396,6 @@ export abstract class Field<T = any>
13961396
this.markerSvg = markerSvg;
13971397
}
13981398

1399-
/**
1400-
* Redraw any attached marker or cursor svgs if needed.
1401-
*
1402-
* @internal
1403-
*/
1404-
updateMarkers_() {
1405-
const block = this.getSourceBlock();
1406-
if (!block) {
1407-
throw new UnattachedFieldError();
1408-
}
1409-
const workspace = block.workspace as WorkspaceSvg;
1410-
if (workspace.keyboardAccessibilityMode && this.cursorSvg) {
1411-
workspace.getCursor()!.draw();
1412-
}
1413-
if (workspace.keyboardAccessibilityMode && this.markerSvg) {
1414-
// TODO(#4592): Update all markers on the field.
1415-
workspace.getMarker(MarkerManager.LOCAL_MARKER)!.draw();
1416-
}
1417-
}
1418-
14191399
/** See IFocusableNode.getFocusableElement. */
14201400
getFocusableElement(): HTMLElement | SVGElement {
14211401
if (!this.fieldGroup_) {

core/keyboard_nav/line_cursor.ts

Lines changed: 1 addition & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {isFocusableNode} from '../interfaces/i_focusable_node.js';
3030
import type {INavigable} from '../interfaces/i_navigable.js';
3131
import * as registry from '../registry.js';
3232
import {RenderedConnection} from '../rendered_connection.js';
33-
import type {MarkerSvg} from '../renderers/common/marker_svg.js';
3433
import type {PathObject} from '../renderers/zelos/path_object.js';
3534
import {Renderer} from '../renderers/zelos/renderer.js';
3635
import * as dom from '../utils/dom.js';
@@ -574,40 +573,6 @@ export class LineCursor extends Marker {
574573
return super.getCurNode();
575574
}
576575

577-
/**
578-
* Sets the object in charge of drawing the marker.
579-
*
580-
* We want to customize drawing, so rather than directly setting the given
581-
* object, we instead set a wrapper proxy object that passes through all
582-
* method calls and property accesses except for draw(), which it delegates
583-
* to the drawMarker() method in this class.
584-
*
585-
* @param drawer The object ~in charge of drawing the marker.
586-
*/
587-
override setDrawer(drawer: MarkerSvg) {
588-
const altDraw = function (
589-
this: LineCursor,
590-
oldNode: ASTNode | null,
591-
curNode: ASTNode | null,
592-
) {
593-
// Pass the unproxied, raw drawer object so that drawMarker can call its
594-
// `draw()` method without triggering infinite recursion.
595-
this.drawMarker(oldNode, curNode, drawer);
596-
}.bind(this);
597-
598-
super.setDrawer(
599-
new Proxy(drawer, {
600-
get(target: typeof drawer, prop: keyof typeof drawer) {
601-
if (prop === 'draw') {
602-
return altDraw;
603-
}
604-
605-
return target[prop];
606-
},
607-
}),
608-
);
609-
}
610-
611576
/**
612577
* Set the location of the cursor and draw it.
613578
*
@@ -630,125 +595,7 @@ export class LineCursor extends Marker {
630595
);
631596
}
632597
}
633-
634-
/**
635-
* Draw this cursor's marker.
636-
*
637-
* This is a wrapper around this.drawer.draw (usually implemented by
638-
* MarkerSvg.prototype.draw) that will, if newNode is a BLOCK node,
639-
* instead call `setSelected` to select it (if it's a regular block)
640-
* or `addSelect` (if it's a shadow block, since shadow blocks can't
641-
* be selected) instead of using the normal drawer logic.
642-
*
643-
* TODO(#142): The selection and fake-selection code was originally
644-
* a hack added for testing on October 28 2024, because the default
645-
* drawer (MarkerSvg) behaviour in Zelos was to draw a box around
646-
* the block and all attached child blocks, which was confusing when
647-
* navigating stacks.
648-
*
649-
* Since then we have decided that we probably _do_ in most cases
650-
* want navigating to a block to select the block, but more
651-
* particularly that we want navigation to move _focus_. Replace
652-
* this selection hack with non-hacky changing of focus once that's
653-
* possible.
654-
*
655-
* @param oldNode The previous node.
656-
* @param curNode The current node.
657-
* @param realDrawer The object ~in charge of drawing the marker.
658-
*/
659-
private drawMarker(
660-
oldNode: ASTNode | null,
661-
curNode: ASTNode | null,
662-
realDrawer: MarkerSvg,
663-
) {
664-
// If old node was a block, unselect it or remove fake selection.
665-
if (oldNode?.getType() === ASTNode.types.BLOCK) {
666-
const block = oldNode.getLocation() as BlockSvg;
667-
if (!block.isShadow()) {
668-
// Selection should already be in sync.
669-
} else {
670-
block.removeSelect();
671-
}
672-
}
673-
674-
if (this.isZelos && oldNode && this.isValueInputConnection(oldNode)) {
675-
this.hideAtInput(oldNode);
676-
}
677-
678-
const curNodeType = curNode?.getType();
679-
const isZelosInputConnection =
680-
this.isZelos && curNode && this.isValueInputConnection(curNode);
681-
682-
// If drawing can't be handled locally, just use the drawer.
683-
if (curNodeType !== ASTNode.types.BLOCK && !isZelosInputConnection) {
684-
realDrawer.draw(oldNode, curNode);
685-
return;
686-
}
687-
688-
// Hide any visible marker SVG and instead do some manual rendering.
689-
realDrawer.hide();
690-
691-
if (isZelosInputConnection) {
692-
this.showAtInput(curNode);
693-
} else if (curNode && curNodeType === ASTNode.types.BLOCK) {
694-
const block = curNode.getLocation() as BlockSvg;
695-
if (!block.isShadow()) {
696-
// Selection should already be in sync.
697-
} else {
698-
block.addSelect();
699-
block.getParent()?.removeSelect();
700-
}
701-
}
702-
703-
// Call MarkerSvg.prototype.fireMarkerEvent like
704-
// MarkerSvg.prototype.draw would (even though it's private).
705-
(realDrawer as any)?.fireMarkerEvent?.(oldNode, curNode);
706-
}
707-
708-
/**
709-
* Check whether the node represents a value input connection.
710-
*
711-
* @param node The node to check
712-
* @returns True if the node represents a value input connection.
713-
*/
714-
private isValueInputConnection(node: ASTNode) {
715-
if (node?.getType() !== ASTNode.types.INPUT) return false;
716-
const connection = node.getLocation() as RenderedConnection;
717-
return connection.type === ConnectionType.INPUT_VALUE;
718-
}
719-
720-
/**
721-
* Hide the cursor rendering at the given input node.
722-
*
723-
* @param node The input node to hide.
724-
*/
725-
private hideAtInput(node: ASTNode) {
726-
const inputConnection = node.getLocation() as RenderedConnection;
727-
const sourceBlock = inputConnection.getSourceBlock() as BlockSvg;
728-
const input = inputConnection.getParentInput();
729-
if (input) {
730-
const pathObject = sourceBlock.pathObject as PathObject;
731-
const outlinePath = pathObject.getOutlinePath(input.name);
732-
dom.removeClass(outlinePath, 'inputActiveFocus');
733-
}
734-
}
735-
736-
/**
737-
* Show the cursor rendering at the given input node.
738-
*
739-
* @param node The input node to show.
740-
*/
741-
private showAtInput(node: ASTNode) {
742-
const inputConnection = node.getLocation() as RenderedConnection;
743-
const sourceBlock = inputConnection.getSourceBlock() as BlockSvg;
744-
const input = inputConnection.getParentInput();
745-
if (input) {
746-
const pathObject = sourceBlock.pathObject as PathObject;
747-
const outlinePath = pathObject.getOutlinePath(input.name);
748-
dom.addClass(outlinePath, 'inputActiveFocus');
749-
}
750-
}
751-
598+
752599
/**
753600
* Updates the current node to match the selection.
754601
*

core/keyboard_nav/marker.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {Field} from '../field.js';
1717
import {FlyoutButton} from '../flyout_button.js';
1818
import type {INavigable} from '../interfaces/i_navigable.js';
1919
import {RenderedConnection} from '../rendered_connection.js';
20-
import type {MarkerSvg} from '../renderers/common/marker_svg.js';
2120
import {Coordinate} from '../utils/coordinate.js';
2221
import {WorkspaceSvg} from '../workspace_svg.js';
2322
import {ASTNode} from './ast_node.js';
@@ -33,33 +32,9 @@ export class Marker {
3332
/** The current location of the marker. */
3433
protected curNode: INavigable<any> | null = null;
3534

36-
/**
37-
* The object in charge of drawing the visual representation of the current
38-
* node.
39-
*/
40-
private drawer: MarkerSvg | null = null;
41-
4235
/** The type of the marker. */
4336
type = 'marker';
4437

45-
/**
46-
* Sets the object in charge of drawing the marker.
47-
*
48-
* @param drawer The object in charge of drawing the marker.
49-
*/
50-
setDrawer(drawer: MarkerSvg) {
51-
this.drawer = drawer;
52-
}
53-
54-
/**
55-
* Get the current drawer for the marker.
56-
*
57-
* @returns The object in charge of drawing the marker.
58-
*/
59-
getDrawer(): MarkerSvg | null {
60-
return this.drawer;
61-
}
62-
6338
/**
6439
* Gets the current location of the marker.
6540
*
@@ -77,28 +52,10 @@ export class Marker {
7752
setCurNode(newNode: INavigable<any> | null) {
7853
const oldNode = this.curNode;
7954
this.curNode = newNode;
80-
this.drawer?.draw(this.toASTNode(oldNode), this.toASTNode(this.curNode));
81-
}
82-
83-
/**
84-
* Redraw the current marker.
85-
*
86-
* @internal
87-
*/
88-
draw() {
89-
const node = this.toASTNode(this.curNode);
90-
this.drawer?.draw(node, node);
91-
}
92-
93-
/** Hide the marker SVG. */
94-
hide() {
95-
this.drawer?.hide();
9655
}
9756

9857
/** Dispose of this marker. */
9958
dispose() {
100-
this.drawer?.dispose();
101-
this.drawer = null;
10259
this.curNode = null;
10360
}
10461

core/marker_manager.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ export class MarkerManager {
5050
if (this.markers.has(id)) {
5151
this.unregisterMarker(id);
5252
}
53-
const drawer = this.workspace
54-
.getRenderer()
55-
.makeMarkerDrawer(this.workspace, marker);
56-
marker.setDrawer(drawer);
57-
this.setMarkerSvg(drawer.createDom());
5853
this.markers.set(id, marker);
5954
}
6055

@@ -105,15 +100,7 @@ export class MarkerManager {
105100
* @param cursor The cursor used to move around this workspace.
106101
*/
107102
setCursor(cursor: LineCursor) {
108-
this.cursor?.getDrawer()?.dispose();
109103
this.cursor = cursor;
110-
if (this.cursor) {
111-
const drawer = this.workspace
112-
.getRenderer()
113-
.makeMarkerDrawer(this.workspace, this.cursor);
114-
this.cursor.setDrawer(drawer);
115-
this.setCursorSvg(drawer.createDom());
116-
}
117104
}
118105

119106
/**
@@ -157,17 +144,6 @@ export class MarkerManager {
157144
}
158145
}
159146

160-
/**
161-
* Redraw the attached cursor SVG if needed.
162-
*
163-
* @internal
164-
*/
165-
updateMarkers() {
166-
if (this.workspace.keyboardAccessibilityMode && this.cursorSvg) {
167-
this.workspace.getCursor()!.draw();
168-
}
169-
}
170-
171147
/**
172148
* Dispose of the marker manager.
173149
* Go through and delete all markers associated with this marker manager.

core/renderers/common/block_rendering.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {Types} from '../measurables/types.js';
3333
import {Drawer} from './drawer.js';
3434
import type {IPathObject} from './i_path_object.js';
3535
import {RenderInfo} from './info.js';
36-
import {MarkerSvg} from './marker_svg.js';
3736
import {PathObject} from './path_object.js';
3837
import {Renderer} from './renderer.js';
3938

@@ -94,7 +93,6 @@ export {
9493
InRowSpacer,
9594
IPathObject,
9695
JaggedEdge,
97-
MarkerSvg,
9896
Measurable,
9997
NextConnection,
10098
OutputConnection,

0 commit comments

Comments
 (0)