summaryrefslogtreecommitdiffstats
path: root/src/verbs.cpp
diff options
context:
space:
mode:
authorNathan Lee <2431820-nathanal@users.noreply.gitlab.com>2019-02-22 08:52:32 +0000
committerPatrick Storz <eduard.braun2@gmx.de>2019-03-02 18:06:53 +0000
commit1efc84068bf8f91928fe8c653257f747f832f2dc (patch)
tree4b4ba6659ae158277f1b03089770fd355a53162b /src/verbs.cpp
parentUpdate Italian translation (diff)
downloadinkscape-1efc84068bf8f91928fe8c653257f747f832f2dc.tar.gz
inkscape-1efc84068bf8f91928fe8c653257f747f832f2dc.zip
After delete, next selected layer is sibling of equal depth, with preference for previous layer.
Also fix: prevents setting deleted layer as current.
Diffstat (limited to 'src/verbs.cpp')
-rw-r--r--src/verbs.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/verbs.cpp b/src/verbs.cpp
index 86b884b4d..c57b587eb 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -1407,7 +1407,7 @@ void LayerVerb::perform(SPAction *action, void *data)
case SP_VERB_LAYER_DUPLICATE: {
if ( dt->currentLayer() != dt->currentRoot() ) {
- dt->selection->duplicate(true,true);
+ dt->selection->duplicate(true, true);
DocumentUndo::done(dt->getDocument(), SP_VERB_LAYER_DUPLICATE,
_("Duplicate layer"));
@@ -1422,23 +1422,37 @@ void LayerVerb::perform(SPAction *action, void *data)
case SP_VERB_LAYER_DELETE: {
if ( dt->currentLayer() != dt->currentRoot() ) {
dt->getSelection()->clear();
- SPObject *old_layer=dt->currentLayer();
+ SPObject *old_layer = dt->currentLayer();
+ SPObject *old_parent = old_layer->parent;
+ SPObject *old_parent_parent = (old_parent != nullptr) ? old_parent->parent : nullptr;
+
+ SPObject *survivor = Inkscape::previous_layer(dt->currentRoot(), old_layer);
+ if (survivor != nullptr && survivor->parent == old_layer) {
+ while (survivor != nullptr &&
+ survivor->parent != old_parent &&
+ survivor->parent != old_parent_parent)
+ {
+ survivor = Inkscape::previous_layer(dt->currentRoot(), survivor);
+ }
+ }
- SPObject *survivor=Inkscape::next_layer(dt->currentRoot(), old_layer);
- if (!survivor) {
- survivor = Inkscape::previous_layer(dt->currentRoot(), old_layer);
+ if (survivor == nullptr || (survivor->parent != old_parent && survivor->parent != old_layer)) {
+ survivor = Inkscape::next_layer(dt->currentRoot(), old_layer);
+ while (survivor != nullptr &&
+ survivor != old_parent &&
+ survivor->parent != old_parent)
+ {
+ survivor = Inkscape::next_layer(dt->currentRoot(), survivor);
+ }
}
- if (survivor == old_layer->lastChild()) {
- //oops: layer_fns messed up. BADLY.
- survivor = nullptr;
- }
// Deleting the old layer before switching layers is a hack to trigger the
// listeners of the deletion event (as happens when old_layer is deleted using the
// xml editor). See
// http://sourceforge.net/tracker/index.php?func=detail&aid=1339397&group_id=93438&atid=604306
//
old_layer->deleteObject();
+
if (survivor) {
dt->setCurrentLayer(survivor);
}