refactor: Ensure that the workspace cursor is never null. (#9210)

This commit is contained in:
Aaron Dodson
2025-07-07 13:55:40 -07:00
committed by GitHub
parent 97d0e45418
commit dfd565957b
2 changed files with 11 additions and 21 deletions

View File

@@ -11,7 +11,7 @@
*/
// Former goog.module ID: Blockly.MarkerManager
import type {LineCursor} from './keyboard_nav/line_cursor.js';
import {LineCursor} from './keyboard_nav/line_cursor.js';
import type {Marker} from './keyboard_nav/marker.js';
import type {WorkspaceSvg} from './workspace_svg.js';
@@ -23,7 +23,7 @@ export class MarkerManager {
static readonly LOCAL_MARKER = 'local_marker_1';
/** The cursor. */
private cursor: LineCursor | null = null;
private cursor: LineCursor;
/** The map of markers for the workspace. */
private markers = new Map<string, Marker>();
@@ -32,7 +32,9 @@ export class MarkerManager {
* @param workspace The workspace for the marker manager.
* @internal
*/
constructor(private readonly workspace: WorkspaceSvg) {}
constructor(private readonly workspace: WorkspaceSvg) {
this.cursor = new LineCursor(this.workspace);
}
/**
* Register the marker by adding it to the map of markers.
@@ -72,7 +74,7 @@ export class MarkerManager {
*
* @returns The cursor for this workspace.
*/
getCursor(): LineCursor | null {
getCursor(): LineCursor {
return this.cursor;
}
@@ -109,9 +111,6 @@ export class MarkerManager {
this.unregisterMarker(markerId);
}
this.markers.clear();
if (this.cursor) {
this.cursor.dispose();
this.cursor = null;
}
this.cursor.dispose();
}
}

View File

@@ -480,10 +480,7 @@ export class WorkspaceSvg
* @internal
*/
getMarker(id: string): Marker | null {
if (this.markerManager) {
return this.markerManager.getMarker(id);
}
return null;
return this.markerManager.getMarker(id);
}
/**
@@ -491,11 +488,8 @@ export class WorkspaceSvg
*
* @returns The cursor for the workspace.
*/
getCursor(): LineCursor | null {
if (this.markerManager) {
return this.markerManager.getCursor();
}
return null;
getCursor(): LineCursor {
return this.markerManager.getCursor();
}
/**
@@ -899,10 +893,7 @@ export class WorkspaceSvg
}
this.renderer.dispose();
if (this.markerManager) {
this.markerManager.dispose();
}
this.markerManager.dispose();
super.dispose();