Skip to content

Commit dfd5659

Browse files
authored
refactor: Ensure that the workspace cursor is never null. (#9210)
1 parent 97d0e45 commit dfd5659

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

core/marker_manager.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
// Former goog.module ID: Blockly.MarkerManager
1313

14-
import type {LineCursor} from './keyboard_nav/line_cursor.js';
14+
import {LineCursor} from './keyboard_nav/line_cursor.js';
1515
import type {Marker} from './keyboard_nav/marker.js';
1616
import type {WorkspaceSvg} from './workspace_svg.js';
1717

@@ -23,7 +23,7 @@ export class MarkerManager {
2323
static readonly LOCAL_MARKER = 'local_marker_1';
2424

2525
/** The cursor. */
26-
private cursor: LineCursor | null = null;
26+
private cursor: LineCursor;
2727

2828
/** The map of markers for the workspace. */
2929
private markers = new Map<string, Marker>();
@@ -32,7 +32,9 @@ export class MarkerManager {
3232
* @param workspace The workspace for the marker manager.
3333
* @internal
3434
*/
35-
constructor(private readonly workspace: WorkspaceSvg) {}
35+
constructor(private readonly workspace: WorkspaceSvg) {
36+
this.cursor = new LineCursor(this.workspace);
37+
}
3638

3739
/**
3840
* Register the marker by adding it to the map of markers.
@@ -72,7 +74,7 @@ export class MarkerManager {
7274
*
7375
* @returns The cursor for this workspace.
7476
*/
75-
getCursor(): LineCursor | null {
77+
getCursor(): LineCursor {
7678
return this.cursor;
7779
}
7880

@@ -109,9 +111,6 @@ export class MarkerManager {
109111
this.unregisterMarker(markerId);
110112
}
111113
this.markers.clear();
112-
if (this.cursor) {
113-
this.cursor.dispose();
114-
this.cursor = null;
115-
}
114+
this.cursor.dispose();
116115
}
117116
}

core/workspace_svg.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -480,22 +480,16 @@ export class WorkspaceSvg
480480
* @internal
481481
*/
482482
getMarker(id: string): Marker | null {
483-
if (this.markerManager) {
484-
return this.markerManager.getMarker(id);
485-
}
486-
return null;
483+
return this.markerManager.getMarker(id);
487484
}
488485

489486
/**
490487
* The cursor for this workspace.
491488
*
492489
* @returns The cursor for the workspace.
493490
*/
494-
getCursor(): LineCursor | null {
495-
if (this.markerManager) {
496-
return this.markerManager.getCursor();
497-
}
498-
return null;
491+
getCursor(): LineCursor {
492+
return this.markerManager.getCursor();
499493
}
500494

501495
/**
@@ -899,10 +893,7 @@ export class WorkspaceSvg
899893
}
900894

901895
this.renderer.dispose();
902-
903-
if (this.markerManager) {
904-
this.markerManager.dispose();
905-
}
896+
this.markerManager.dispose();
906897

907898
super.dispose();
908899

0 commit comments

Comments
 (0)