Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/interfaces/i_navigable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ export interface INavigable<T> {
*/
getClass(): new (...args: any) => T;
}

/**
* Determines whether the provided object fulfills the contract of INavigable.
*
* @param object The object to test.
* @returns Whether the provided object can be used as an INavigable.
*/
export function isNavigable(object: any | null): object is INavigable<any> {
return object && 'isNavigable' in object && 'getClass' in object;
}
11 changes: 5 additions & 6 deletions core/keyboard_nav/line_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {FlyoutButton} from '../flyout_button.js';
import {FlyoutSeparator} from '../flyout_separator.js';
import {getFocusManager} from '../focus_manager.js';
import {isFocusableNode} from '../interfaces/i_focusable_node.js';
import type {INavigable} from '../interfaces/i_navigable.js';
import {isNavigable, type INavigable} from '../interfaces/i_navigable.js';
import * as registry from '../registry.js';
import {RenderedConnection} from '../rendered_connection.js';
import {Renderer} from '../renderers/zelos/renderer.js';
Expand Down Expand Up @@ -593,11 +593,10 @@ export class LineCursor extends Marker {
private updateCurNodeFromFocus() {
const focused = getFocusManager().getFocusedNode();

if (focused instanceof BlockSvg) {
const block: BlockSvg | null = focused;
if (block && block.workspace === this.workspace) {
this.setCurNode(block);
}
if (isNavigable(focused)) {
const block = this.getSourceBlockFromNode(focused);
if (block && block.workspace !== this.workspace) return;
this.setCurNode(focused);
}
}

Expand Down