Compare commits

...

5 Commits

Author SHA1 Message Date
Martín Capello 747858587b
Merge 1e556678ba into 6d89a6bc15 2025-07-24 20:35:58 -05:00
Cerallin 6d89a6bc15 fix entry
build-auto / build-auto (Debug, macos-latest) (push) Has been cancelled Details
build-auto / build-auto (Debug, ubuntu-latest) (push) Has been cancelled Details
build-auto / build-auto (Debug, windows-latest) (push) Has been cancelled Details
build-auto / build-auto (RelWithDebInfo, macos-latest) (push) Has been cancelled Details
build-auto / build-auto (RelWithDebInfo, ubuntu-latest) (push) Has been cancelled Details
build-auto / build-auto (RelWithDebInfo, windows-latest) (push) Has been cancelled Details
build / build (Debug, macos-latest, lua, cli) (push) Has been cancelled Details
build / build (Debug, macos-latest, noscripts, cli) (push) Has been cancelled Details
build / build (Debug, ubuntu-latest, lua, cli) (push) Has been cancelled Details
build / build (Debug, ubuntu-latest, noscripts, cli) (push) Has been cancelled Details
build / build (Debug, windows-latest, lua, cli) (push) Has been cancelled Details
build / build (Debug, windows-latest, noscripts, cli) (push) Has been cancelled Details
build / build (RelWithDebInfo, macos-latest, lua, gui) (push) Has been cancelled Details
build / build (RelWithDebInfo, ubuntu-latest, lua, gui) (push) Has been cancelled Details
build / build (RelWithDebInfo, windows-latest, lua, gui) (push) Has been cancelled Details
2025-07-24 12:50:32 -03:00
Cerallin d4e97b5a96 Add const method Entry::caretPosOnScreen()
This method is for Entry::setTextInput() and IME positioning.
2025-07-24 12:50:32 -03:00
Cerallin 205b18dc0f Make Entry::getCharBoxBounds() a const method 2025-07-24 12:50:32 -03:00
Martín Capello 1e556678ba Fix crash dropping file on timeline (fix #5289) 2025-07-23 17:56:07 -03:00
4 changed files with 42 additions and 6 deletions

View File

@ -168,6 +168,21 @@ SelectLayerBoundariesOp get_select_layer_in_canvas_op(ui::Message* msg)
return SelectLayerBoundariesOp::REPLACE;
}
bool get_layer_index(LayerGroup* parent, const Layer* layer, layer_t& index)
{
for (Layer* child : parent->layers()) {
if (child->isGroup() && get_layer_index(static_cast<LayerGroup*>(child), layer, index)) {
return index;
}
if (child == layer) {
return true;
}
index++;
}
return false;
}
} // anonymous namespace
Timeline::Hit::Hit(int part, layer_t layer, col_t frame, ObjectId tag, int band)
@ -4055,6 +4070,12 @@ layer_t Timeline::getLayerIndex(const Layer* layer) const
return -1;
}
layer_t Timeline::getLayerIndexFromSprite(const Layer* layer) const
{
layer_t index = 0;
return get_layer_index(m_sprite->root(), layer, index) ? index : -1;
}
bool Timeline::isLayerActive(const layer_t layerIndex) const
{
Layer* layer = getLayer(layerIndex);
@ -4576,7 +4597,7 @@ void Timeline::onDrop(ui::DragEvent& e)
// Determine at which frame and layer the content was dropped on.
frame_t frame = m_frame;
layer_t layerIndex = getLayerIndex(m_layer);
layer_t layerIndex = getLayerIndexFromSprite(m_layer);
InsertionPoint insert = InsertionPoint::BeforeLayer;
DroppedOn droppedOn = DroppedOn::Unspecified;
TRACE("m_dropRange.type() %d\n", m_dropRange.type());
@ -4602,7 +4623,7 @@ void Timeline::onDrop(ui::DragEvent& e)
break;
case Range::kLayers:
droppedOn = DroppedOn::Layer;
if (m_dropTarget.vhit != DropTarget::VeryBottom) {
if (m_dropTarget.vhit != DropTarget::VeryBottom && !m_dropRange.selectedLayers().empty()) {
auto* selectedLayer = *m_dropRange.selectedLayers().begin();
layerIndex = getLayerIndex(selectedLayer);
}

View File

@ -355,6 +355,8 @@ private:
gfx::Point getMaxScrollablePos() const;
doc::Layer* getLayer(int layerIndex) const;
layer_t getLayerIndex(const Layer* layer) const;
// Get layer index regardless of visibility in the UI.
layer_t getLayerIndexFromSprite(const Layer* layer) const;
bool isLayerActive(const layer_t layerIdx) const;
bool isFrameActive(const col_t frame) const;
bool isCelActive(const layer_t layerIdx, const col_t frame) const;

View File

@ -128,6 +128,15 @@ int Entry::lastCaretPos() const
return int(m_boxes.size() - 1);
}
gfx::Point Entry::caretPosOnScreen() const
{
const gfx::Point caretPos = getCharBoxBounds(m_caret).point2();
const os::Window* nativeWindow = display()->nativeWindow();
const gfx::Point pos = nativeWindow->pointToScreen(caretPos + bounds().origin());
return pos;
}
void Entry::setCaretPos(const int pos)
{
gfx::Size caretSize = theme()->getEntryCaretSize(this);
@ -160,6 +169,8 @@ void Entry::setCaretPos(const int pos)
startTimer();
m_state = true;
os::System::instance()->setTextInput(true, caretPosOnScreen());
invalidate();
}
@ -251,7 +262,7 @@ gfx::Rect Entry::getEntryTextBounds() const
return onGetEntryTextBounds();
}
gfx::Rect Entry::getCharBoxBounds(const int i)
gfx::Rect Entry::getCharBoxBounds(const int i) const
{
ASSERT(i >= 0 && i < int(m_boxes.size()));
if (i >= 0 && i < int(m_boxes.size()))
@ -288,8 +299,9 @@ bool Entry::onProcessMessage(Message* msg)
}
// Start processing dead keys
if (m_translate_dead_keys)
os::System::instance()->setTextInput(true);
if (m_translate_dead_keys) {
os::System::instance()->setTextInput(true, caretPosOnScreen());
}
break;
case kFocusLeaveMessage:

View File

@ -43,6 +43,7 @@ public:
int caretPos() const { return m_caret; }
int lastCaretPos() const;
gfx::Point caretPosOnScreen() const;
void setCaretPos(int pos);
void setCaretToEnd();
@ -76,7 +77,7 @@ public:
obs::signal<void()> Change;
protected:
gfx::Rect getCharBoxBounds(int i);
gfx::Rect getCharBoxBounds(int i) const;
// Events
bool onProcessMessage(Message* msg) override;