mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-06 06:58:15 +00:00
Fix crash when pressing ESC while moving a selection (fix #2829)
This commit is contained in:
parent
0145458686
commit
fc79146c56
@ -12,6 +12,8 @@
|
|||||||
#include "app/ui/editor/moving_selection_state.h"
|
#include "app/ui/editor/moving_selection_state.h"
|
||||||
|
|
||||||
#include "app/cmd/set_mask_position.h"
|
#include "app/cmd/set_mask_position.h"
|
||||||
|
#include "app/commands/command.h"
|
||||||
|
#include "app/commands/commands.h"
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/tx.h"
|
#include "app/tx.h"
|
||||||
#include "app/ui/editor/editor.h"
|
#include "app/ui/editor/editor.h"
|
||||||
@ -31,6 +33,7 @@ MovingSelectionState::MovingSelectionState(Editor* editor, MouseMessage* msg)
|
|||||||
: m_editor(editor)
|
: m_editor(editor)
|
||||||
, m_cursorStart(editor->screenToEditor(msg->position()))
|
, m_cursorStart(editor->screenToEditor(msg->position()))
|
||||||
, m_selOrigin(editor->document()->mask()->bounds().origin())
|
, m_selOrigin(editor->document()->mask()->bounds().origin())
|
||||||
|
, m_selectionCanceled(false)
|
||||||
{
|
{
|
||||||
editor->captureMouse();
|
editor->captureMouse();
|
||||||
|
|
||||||
@ -42,6 +45,12 @@ MovingSelectionState::MovingSelectionState(Editor* editor, MouseMessage* msg)
|
|||||||
|
|
||||||
void MovingSelectionState::onBeforeCommandExecution(CommandExecutionEvent& ev)
|
void MovingSelectionState::onBeforeCommandExecution(CommandExecutionEvent& ev)
|
||||||
{
|
{
|
||||||
|
if (ev.command()->id() == CommandId::Cancel()) {
|
||||||
|
// We cancel the cancel command to avoid calling the inputChain()->cancel(), which
|
||||||
|
// deselects the selection.
|
||||||
|
ev.cancel();
|
||||||
|
m_selectionCanceled = true;
|
||||||
|
}
|
||||||
m_editor->backToPreviousState();
|
m_editor->backToPreviousState();
|
||||||
m_editor->releaseMouse();
|
m_editor->releaseMouse();
|
||||||
}
|
}
|
||||||
@ -66,18 +75,29 @@ EditorState::LeaveAction MovingSelectionState::onLeaveState(Editor* editor, Edit
|
|||||||
m_selOrigin.y);
|
m_selOrigin.y);
|
||||||
mask->unfreeze();
|
mask->unfreeze();
|
||||||
|
|
||||||
{
|
if (m_selectionCanceled) {
|
||||||
ContextWriter writer(UIContext::instance(), 1000);
|
doc->resetTransformation();
|
||||||
Tx tx(writer.context(), "Move Selection Edges", DoesntModifyDocument);
|
doc->generateMaskBoundaries();
|
||||||
tx(new cmd::SetMaskPosition(doc, newOrigin));
|
}
|
||||||
tx.commit();
|
else {
|
||||||
|
{
|
||||||
|
ContextWriter writer(UIContext::instance(), 1000);
|
||||||
|
Tx tx(writer.context(), "Move Selection Edges", DoesntModifyDocument);
|
||||||
|
tx(new cmd::SetMaskPosition(doc, newOrigin));
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
doc->resetTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
doc->resetTransformation();
|
|
||||||
doc->notifyGeneralUpdate();
|
doc->notifyGeneralUpdate();
|
||||||
return StandbyState::onLeaveState(editor, newState);
|
return StandbyState::onLeaveState(editor, newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MovingSelectionState::onBeforePopState(Editor* editor)
|
||||||
|
{
|
||||||
|
m_ctxConn.disconnect();
|
||||||
|
StandbyState::onBeforePopState(editor);
|
||||||
|
}
|
||||||
|
|
||||||
bool MovingSelectionState::onMouseDown(Editor* editor, MouseMessage* msg)
|
bool MovingSelectionState::onMouseDown(Editor* editor, MouseMessage* msg)
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
@ -26,6 +26,7 @@ namespace app {
|
|||||||
virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;
|
virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;
|
||||||
virtual bool onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos) override;
|
virtual bool onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos) override;
|
||||||
virtual bool onUpdateStatusBar(Editor* editor) override;
|
virtual bool onUpdateStatusBar(Editor* editor) override;
|
||||||
|
virtual void onBeforePopState(Editor* editor) override;
|
||||||
virtual bool requireBrushPreview() override { return false; }
|
virtual bool requireBrushPreview() override { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -37,6 +38,7 @@ namespace app {
|
|||||||
gfx::Point m_selOrigin;
|
gfx::Point m_selOrigin;
|
||||||
gfx::Point m_delta;
|
gfx::Point m_delta;
|
||||||
obs::scoped_connection m_ctxConn;
|
obs::scoped_connection m_ctxConn;
|
||||||
|
bool m_selectionCanceled;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
Loading…
Reference in New Issue
Block a user