Skip to content

Commit

Permalink
Merge pull request #519 from UUDigitalHumanitieslab/feature/autoremove
Browse files Browse the repository at this point in the history
Autoremove the previous unsaved annotation when a new piece of text is selected
  • Loading branch information
jgonggrijp authored Mar 31, 2022
2 parents 57fc2e9 + cbb131b commit b217007
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions frontend/src/explorer/explorer-event-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import SourceListPanel from '../panel-source-list/source-list-panel';
import FilteredCollection from '../common-adapters/filtered-collection';
import {
isOntologyClass,
isBlank,
} from '../utilities/linked-data-utilities';
import { itemsForSourceQuery } from '../sparql/compile-query';
import SemanticQuery from '../semantic-search/model';
Expand Down Expand Up @@ -262,7 +263,9 @@ class ExplorerEventController {
}, 250));
}
// Nobody is listening for the following event, except when we are
// re-focusing as discussed above **and** the route ends in `/edit`.
// re-focusing as discussed above **and** the route ends in `/edit`,
// **or** we are creating a new annotation because the user selected
// text.
this.trigger('reopen-edit-annotation', newDetailView, model);
return newDetailView;
}
Expand Down Expand Up @@ -300,8 +303,19 @@ class ExplorerEventController {
);
collection.underlying.add(annotation);
const flat = collection.get(annotation.id);
const newAnnotationView = this.openSourceAnnotation(listPanel, flat, collection);
return this.editAnnotation(newAnnotationView, flat);
flat.once('blur', () => {
if (isBlank(annotation)) collection.underlying.remove(annotation);
});
let editPanel: AnnoEditView;
this.once('reopen-edit-annotation', annoView =>
editPanel = this.editAnnotation(annoView, flat)
);
// Through a cascade of synchronous events, the next trigger will invoke
// `this.openSourceAnnotation`, which in turn will trigger the event
// that causes `editPanel` to be set.
flat.trigger('focus', flat);
// Hence, `editPanel` is defined by the time this function returns.
return editPanel;
}

resetBrowsePanel(queryMode: string | Model, landing: boolean) {
Expand Down

0 comments on commit b217007

Please sign in to comment.