Skip to content

Commit

Permalink
added keybinds for iterating through annotation list
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj committed Sep 26, 2023
1 parent 974cd1a commit c32e054
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
59 changes: 49 additions & 10 deletions src/neuroglancer/ui/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,8 @@ export class AnnotationLayerView extends Tab {
newAttachedAnnotationStates.set(
state, {refCounted, annotations: [], idToIndex: new Map(), listOffset: 0});

console.log('waiting for visibleChunksChanged');
if (source instanceof MultiscaleAnnotationSource) {
refCounted.registerDisposer(source.chunkManager.chunkQueueManager.visibleChunksChanged.add(() => {
console.log('visibleChunksChanged!', source);
this.forceUpdateView();
}));
}
Expand Down Expand Up @@ -355,8 +353,33 @@ export class AnnotationLayerView extends Tab {
this.displayState.hoverState.value = undefined;
});

const changeSelectedIndex = (offset: number) => {
const selectedIndex = this.getSelectedAnnotationIndex();
if (selectedIndex === undefined) return;
const nextAnnotation = this.listElements[selectedIndex+offset];
if (nextAnnotation) {
const {state, annotation} = nextAnnotation;
this.layer.selectAnnotation(state, annotation.id, true);
this.moveToAnnotation(annotation, state);
}
};

this.virtualList.element.addEventListener('action:select-previous-annotation', event => {
event.stopPropagation();
event.preventDefault();
changeSelectedIndex(-1);
});

this.virtualList.element.addEventListener('action:select-next-annotation', event => {
event.stopPropagation();
event.preventDefault();
changeSelectedIndex(1);
});

const bindings = getDefaultAnnotationListBindings();
this.registerDisposer(new MouseEventBinder(this.virtualList.element, bindings));
this.registerDisposer(new KeyboardEventBinder(this.virtualList.element, bindings));
this.virtualList.element.tabIndex = -1;
this.virtualList.element.title = bindings.describe();
this.registerDisposer(this.displayState.hoverState.changed.add(() => this.updateHoverView()));
this.registerDisposer(
Expand All @@ -374,6 +397,17 @@ export class AnnotationLayerView extends Tab {
this.updateSelectionView();
}

private getSelectedAnnotationIndex() {
const {previousSelectedState: state} = this;
if (state === undefined) return;
const {annotationLayerState, annotationId} = state;
const attached = this.attachedAnnotationStates.get(annotationLayerState);
if (attached === undefined) return;
const index = attached.idToIndex.get(annotationId);
if (index === undefined) return;
return attached.listOffset + index;
}

private getRenderedAnnotationListElement(
state: AnnotationLayerState, id: AnnotationId, scrollIntoView: boolean = false): HTMLElement
|undefined {
Expand Down Expand Up @@ -665,6 +699,18 @@ export class AnnotationLayerView extends Tab {
this.updateSelectionView();
}

private moveToAnnotation(annotation: Annotation, state: AnnotationLayerState) {
const chunkTransform = state.chunkTransform.value as ChunkTransformParameters;
const {layerRank} = chunkTransform;
const chunkPosition = new Float32Array(layerRank);
const layerPosition = new Float32Array(layerRank);
getCenterPosition(chunkPosition, annotation);
matrix.transformPoint(
layerPosition, chunkTransform.chunkToLayerTransform, layerRank + 1, chunkPosition,
layerRank);
setLayerPosition(this.layer, chunkTransform, layerPosition);
}

private makeAnnotationListElement(annotation: Annotation, state: AnnotationLayerState) {
const chunkTransform = state.chunkTransform.value as ChunkTransformParameters;
const element = document.createElement('div');
Expand Down Expand Up @@ -761,14 +807,7 @@ export class AnnotationLayerView extends Tab {
element.addEventListener('action:move-to-annotation', event => {
event.stopPropagation();
event.preventDefault();
const {layerRank} = chunkTransform;
const chunkPosition = new Float32Array(layerRank);
const layerPosition = new Float32Array(layerRank);
getCenterPosition(chunkPosition, annotation);
matrix.transformPoint(
layerPosition, chunkTransform.chunkToLayerTransform, layerRank + 1, chunkPosition,
layerRank);
setLayerPosition(this.layer, chunkTransform, layerPosition);
this.moveToAnnotation(annotation, state);
});

const selectionState = this.selectedAnnotationState.value;
Expand Down
2 changes: 2 additions & 0 deletions src/neuroglancer/ui/default_input_event_bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export function getDefaultAnnotationListBindings() {
{
'click0': 'pin-annotation',
'mousedown2': 'move-to-annotation',
'arrowup': 'select-previous-annotation',
'arrowdown': 'select-next-annotation',
},
{parents: [[getDefaultSelectBindings(), 0]]});
}
Expand Down

0 comments on commit c32e054

Please sign in to comment.