Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 15 additions & 10 deletions src/modes/direct_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,23 @@ DirectSelect.toDisplayFeatures = function(state, geojson, push) {
};

DirectSelect.onTrash = function(state) {
// Uses number-aware sorting to make sure '9' < '10'. Comparison is reversed because we want them
// in reverse order so that we can remove by index safely.
state.selectedCoordPaths
.sort((a, b) => b.localeCompare(a, 'en', { numeric: true }))
.forEach(id => state.feature.removeCoordinate(id));
this.fireUpdate();
state.selectedCoordPaths = [];
this.clearSelectedCoordinates();
this.fireActionable(state);
if (state.feature.isValid() === false) {
if (state.selectedCoordPaths.length === 0) {
this.deleteFeature([state.featureId]);
this.changeMode(Constants.modes.SIMPLE_SELECT, {});
} else {
// Uses number-aware sorting to make sure '9' < '10'. Comparison is reversed because we want them
// in reverse order so that we can remove by index safely.
state.selectedCoordPaths
.sort((a, b) => b.localeCompare(a, 'en', { numeric: true }))
.forEach(id => state.feature.removeCoordinate(id));
this.fireUpdate();
state.selectedCoordPaths = [];
this.clearSelectedCoordinates();
this.fireActionable(state);
if (state.feature.isValid() === false) {
this.deleteFeature([state.featureId]);
this.changeMode(Constants.modes.SIMPLE_SELECT, {});
}
}
};

Expand Down
13 changes: 13 additions & 0 deletions test/direct_select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ test('direct_select', (t) => {
});
});

t.test('direct_select - trashing with no vertices selected should delete the feature', (st) => {
const ids = Draw.add(getGeoJSON('polygon'));
Draw.changeMode(Constants.modes.DIRECT_SELECT, {
featureId: ids[0]
});
afterNextRender(() => {
Draw.trash();
const afterTrash = Draw.get(ids[0]);
st.equal(afterTrash, undefined);
cleanUp(() => st.end());
});
});

t.test('direct_select - a click on a vertex and than dragging the map shouldn\'t drag the vertex', (st) => {
const ids = Draw.add(getGeoJSON('polygon'));
Draw.changeMode(Constants.modes.DIRECT_SELECT, {
Expand Down