Skip to content

Fix first text edit being discarded after double-click - #5059

Open
ZainnQureshii wants to merge 1 commit into
flameshot-org:masterfrom
ZainnQureshii:fix/text-first-edit-undo
Open

ZainnQureshii wants to merge 1 commit into
flameshot-org:masterfrom
ZainnQureshii:fix/text-first-edit-undo

Conversation

@ZainnQureshii

Copy link
Copy Markdown

Fixes #4062

What was wrong

Following the steps in #4062 (type text, switch to a tool with a different size, double-click the text, edit it, click outside), the first edit is thrown away and the text goes back to its old content. A second edit works.

CaptureWidget::mouseDoubleClickEvent took the text tool pointer and turned on edit mode, and only then called updateLayersPanel(). That refresh rebuilds the layer list (UtilityPanel::fillCaptureTools), which emits layerChanged. CaptureWidget::updateActiveLayer then sees m_existingObjectIsChanged (set by onToolSizeChanged when selecting the text moves the size away from the previous tool's) and calls pushObjectsStateToUndoStack(). The pushed ModificationCommand::redo replaces the stored objects through setCaptureToolObjects, which deep-copies them. The editor was left attached to the old object, so the edit never reached the stored annotation.

This matches what borgmanJeremy found in the issue: the bug needs the second tool to have a different size, and it goes away if that size line is commented out.

The change

In mouseDoubleClickEvent, call updateLayersPanel() before setting up the edit, and fetch the text tool again from m_captureToolObjects after the refresh. Any pending size change is committed first, and the editor and its undo snapshot use the stored annotation. One call moved earlier and the text tool is fetched again after it; nothing else changed, and the size and color handlers are as on master.

How it was tested

Built master and this branch with CMake + Ninja (Qt 6, macOS, Debug); both build. CTest registers no tests in this repo, so I used an offscreen harness (QT_QPA_PLATFORM=offscreen) that links the app's own objects, creates real text and rectangle tools, and drives them through mouse events and the side panel's real hex color editor and size slider:

  • First edit after a tool with a different size, then undo/redo: fails on master, passes with this change.
  • Resize the text through the side panel, then double-click and edit: fails on master (edit lost), passes with this change; undo restores the old text at the new size, and a further undo restores the old size.
  • First edit after a tool with the same size: passes on both.
  • Color change on a selected text and a selected rectangle, then undo/redo: passes on both.
  • Rectangle size change with the mouse wheel, then undo/redo: passes on both.

Not covered here, and failing the same way on master and this branch: Escape closing the editor before undo, resizing while the editor is open, and an unchanged edit adding an undo entry. I did not run it in a visible GUI session.

The changed lines are unchanged by clang-format (checked with a current clang-format on the changed lines; CI's pinned clang-format 11 has no arm64 macOS build).

Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.

🤖 Generated with Claude Code

Double-clicking a text annotation took the edit pointer and turned on
edit mode before refreshing the layers panel. The refresh rebuilds the
layer list, which emits layerChanged; updateActiveLayer then pushes the
pending size change to the undo stack, and the redo replaces the stored
objects with copies. The editor was left pointing at the old object, so
the first edit was dropped when the user clicked outside.

Refresh the layers panel first and fetch the text tool again afterwards,
so the editor and its undo snapshot use the stored annotation.

Fixes flameshot-org#4062

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mmahmoudian

Copy link
Copy Markdown
Member

Thanks for the PR and clarification about AI.

It worked smoothly and code change makes sense to me. I'd wait for @borgmanJeremy review/merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text tool is ignoring first edit

2 participants