Skip to content

Commit

Permalink
Improve the text tool's behaviour when pasting without text in the cl…
Browse files Browse the repository at this point in the history
…ipboard

- Avoid an unhandled exception if the clipboard doesn't have text (e.g. an image). This should be treated as if the clipboard was empty
- When editing, consume the paste event so that it doesn't pull the user out of editing to attempt to paste as an image.

Bug: #2047495
  • Loading branch information
cameronwhite committed Dec 27, 2023
1 parent ee40874 commit e600d95
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Thanks to the following contributors who worked on this release:
- Fixed a bug where dragging a control point in the Curves dialog could unexpectedly erase other control points ([#1973602](https://bugs.launchpad.net/pinta/+bug/1973602))
- Improved error handling when loading incompatible add-ins ([#2047274](https://bugs.launchpad.net/pinta/+bug/2047274))
- The Clone Stamp tool no longer resets the destination offset after each stroke ([#2031257](https://bugs.launchpad.net/pinta/+bug/2031257))
- Fixed potential errors when pasting in the text tool if the clipboard didn't contain text ([#2047495](https://bugs.launchpad.net/pinta/+bug/2047495))

## [2.1.1](https://github.com/PintaProject/Pinta/releases/tag/2.1.1) - 2023/02/26

Expand Down
11 changes: 9 additions & 2 deletions Pinta.Core/Classes/Re-editable/Text/TextEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,15 @@ public void PerformCut (Gdk.Clipboard clipboard)
/// </summary>
public async Task<bool> PerformPaste (Gdk.Clipboard clipboard)
{
string? txt = await clipboard.ReadTextAsync ();
if (String.IsNullOrEmpty (txt))
string? txt;
try {
txt = await clipboard.ReadTextAsync ();
} catch (GLib.GException) {
// The clipboard probably contained an image.
return false;
}

if (string.IsNullOrEmpty (txt))
return false;

if (HasSelection ())
Expand Down
8 changes: 4 additions & 4 deletions Pinta.Tools/Tools/TextTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,12 +1082,12 @@ protected override async Task<bool> OnHandlePaste (Document document, Clipboard
if (!is_editing)
return false;

if (await CurrentTextEngine.PerformPaste (cb)) {
if (await CurrentTextEngine.PerformPaste (cb))
RedrawText (true, true);
return true;
}

return false;
// Always consume the paste event when editing, otherwise this will pull the user out
// of editing to attempt to paste an image.
return true;
}

protected override bool OnHandleCopy (Document document, Clipboard cb)
Expand Down

0 comments on commit e600d95

Please sign in to comment.