Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Fix pasteboard incorrectly being overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
hisaac committed Sep 8, 2020
1 parent 5d7070a commit 3a2c8ca
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import AppKit

extension NSPasteboardItem {

open override var debugDescription: String {
var debugDescription = "Pasteboard Content:\n"
for type in self.types {
debugDescription += "\n\(type): \(self.string(forType: type) ?? "Cannot be represented as a String")"
}
return "\(debugDescription)\n"
}

/// A copy of the pasteboard item with all styled text removed
var plaintextifiedCopy: NSPasteboardItem {

Expand Down
12 changes: 6 additions & 6 deletions PlainPasta.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
4A4E59272176AE7A002CF83D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A4E59262176AE7A002CF83D /* AppDelegate.swift */; };
4A4E592B2176AE7A002CF83D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4A4E592A2176AE7A002CF83D /* Assets.xcassets */; };
4A4E592E2176AE7A002CF83D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A4E592C2176AE7A002CF83D /* Main.storyboard */; };
4AA7338B25073CBE00C9E7FC /* NSPasteboardItem+Filtered.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA7338A25073CBE00C9E7FC /* NSPasteboardItem+Filtered.swift */; };
4AA7338B25073CBE00C9E7FC /* NSPasteboardItem+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA7338A25073CBE00C9E7FC /* NSPasteboardItem+Extras.swift */; };
4AA984F42178DF6500B64A3F /* PasteboardMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AA984F32178DF6500B64A3F /* PasteboardMonitor.swift */; };
4ADE040D24ECC23F0045181C /* Localizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ADE040C24ECC23F0045181C /* Localizable.swift */; };
/* End PBXBuildFile section */
Expand All @@ -26,7 +26,7 @@
4A8A68192176C5F500A4F1D8 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
4A8A681A2176C5F500A4F1D8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
4A9998E325040BE700141546 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/Main.storyboard; sourceTree = "<group>"; };
4AA7338A25073CBE00C9E7FC /* NSPasteboardItem+Filtered.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSPasteboardItem+Filtered.swift"; sourceTree = SOURCE_ROOT; };
4AA7338A25073CBE00C9E7FC /* NSPasteboardItem+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSPasteboardItem+Extras.swift"; sourceTree = SOURCE_ROOT; };
4AA7338C2507431400C9E7FC /* Assets */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Assets; sourceTree = "<group>"; };
4AA7338D2507431400C9E7FC /* docs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = docs; sourceTree = "<group>"; };
4AA984F32178DF6500B64A3F /* PasteboardMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasteboardMonitor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -82,7 +82,7 @@
children = (
4A4E59262176AE7A002CF83D /* AppDelegate.swift */,
4AA984F32178DF6500B64A3F /* PasteboardMonitor.swift */,
4AA7338A25073CBE00C9E7FC /* NSPasteboardItem+Filtered.swift */,
4AA7338A25073CBE00C9E7FC /* NSPasteboardItem+Extras.swift */,
4ADE040C24ECC23F0045181C /* Localizable.swift */,
4A4E592A2176AE7A002CF83D /* Assets.xcassets */,
4A4E592C2176AE7A002CF83D /* Main.storyboard */,
Expand Down Expand Up @@ -193,7 +193,7 @@
buildActionMask = 2147483647;
files = (
4A4E59272176AE7A002CF83D /* AppDelegate.swift in Sources */,
4AA7338B25073CBE00C9E7FC /* NSPasteboardItem+Filtered.swift in Sources */,
4AA7338B25073CBE00C9E7FC /* NSPasteboardItem+Extras.swift in Sources */,
4ADE040D24ECC23F0045181C /* Localizable.swift in Sources */,
4AA984F42178DF6500B64A3F /* PasteboardMonitor.swift in Sources */,
);
Expand Down Expand Up @@ -346,7 +346,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1.1;
MARKETING_VERSION = 1.1.2;
PRODUCT_BUNDLE_IDENTIFIER = software.level.PlainPasta;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -370,7 +370,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.1.1;
MARKETING_VERSION = 1.1.2;
PRODUCT_BUNDLE_IDENTIFIER = software.level.PlainPasta;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
12 changes: 2 additions & 10 deletions PlainPasta/PasteboardMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ class PasteboardMonitor {
return
}

let filteredPasteboardItem = pasteboardItem.plaintextifiedCopy
pasteboard.clearContents()
let wroteToPasteboard = pasteboard.writeObjects([pasteboardItem.plaintextifiedCopy])
let wroteToPasteboard = pasteboard.writeObjects([filteredPasteboardItem])
if wroteToPasteboard {
internalChangeCount = pasteboard.changeCount
logPlaintextStringToConsole(plaintextString)
Expand All @@ -83,13 +84,4 @@ class PasteboardMonitor {
}
}

/// Prints the string representation of the contents of the pasteboard
private func printPasteboardContentToConsole() {
print("Pasteboard Content:")
for type in pasteboard.types ?? [] {
print("\n\(type): \(pasteboard.string(forType: type) ?? "Cannot be represented as a String")")
}
print("\n")
}

}
32 changes: 22 additions & 10 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,37 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.1.1] - 2020-09-07
## [1.1.2] - 2020-09-08

### Fixed

- Fixes a regression where the pasteboard would sometimes get incorrectly overwritten to empty

### Changed

- Extracted pasteboard filtering to its own method as an extension on `NSPasteboardItem`
- Improved console debugging of `NSPasteboardItem` objects
- Changed changelog layout slightly to highlight fixes before changes

## [1.1.1] - 2020-09-07

### Fixed

- Fixed a bug in handling named URLs on the pasteboard by adding a few more types to the type filtered list:
- `public.url-name`
- `CorePasteboardFlavorType 0x75726C6E`
- `WebURLsWithTitlesPboardType`
- Dynamic pasteboard types, which are any type beginning with `dyn.` - I learned of these via [this blog post](https://camdez.com/blog/2010/07/21/nspasteboard-and-dynamic-utis/) by [@camdez](https://github.com/camdez)
- `public.url-name`
- `CorePasteboardFlavorType 0x75726C6E`
- `WebURLsWithTitlesPboardType`
- Dynamic pasteboard types, which are any type beginning with `dyn.` - I learned of these via [this blog post](https://camdez.com/blog/2010/07/21/nspasteboard-and-dynamic-utis/) by [@camdez](https://github.com/camdez)

### Changed

- Extracted pasteboard filtering to its own method as an extension on `NSPasteboardItem`

## [1.1.0] - 2020-09-07

### Fixed

- Fixed a bug that would cause images on the pasteboard to be removed ([reported](https://github.com/hisaac/PlainPasta/issues/3) by [@foigus](https://github.com/foigus). Thanks!)

### Changed

- Move to using GCD instead of `Timer` for repeat polling of the pasteboard. This provides a small increase in performance.
Expand All @@ -29,10 +44,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
- Enable hardened runtime
- Move Localizable.strings into Swift file

### Fixed

- Fixed a bug that would cause images on the pasteboard to be removed ([reported](https://github.com/hisaac/PlainPasta/issues/3) by [@foigus](https://github.com/foigus). Thanks!)

## [1.0.0] - 2018-11-04

Initial release! 🎉
Expand All @@ -41,3 +52,4 @@ Initial release! 🎉
[1.0.0]: https://github.com/hisaac/PlainPasta/compare/3f3479bf1b417790735aa6cfb8850eb73fe74a07...1.0.0
[1.1.0]: https://github.com/hisaac/PlainPasta/compare/1.0.0...1.1.0
[1.1.1]: https://github.com/hisaac/PlainPasta/compare/1.1.0...1.1.1
[1.1.2]: https://github.com/hisaac/PlainPasta/compare/1.1.1...1.1.2
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<h1>Plain Pasta</h1>

<figure>
<a href="https://github.com/hisaac/PlainPasta/releases/download/1.1.1/PlainPasta-1.1.1.zip" alt="Download the latest version of Plain Pasta">
<a href="https://github.com/hisaac/PlainPasta/releases/download/1.1.1/PlainPasta-1.1.2.zip" alt="Download the latest version of Plain Pasta">
<svg width="200px" height="200px" viewBox="0 0 1900 1900" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 52.2 (67145) - http://www.bohemiancoding.com/sketch -->
<title>vector-Artboard</title>
Expand All @@ -129,7 +129,7 @@ <h1>Plain Pasta</h1>
</g>
</svg>
</a>
<figcaption><a href="https://github.com/hisaac/PlainPasta/releases/download/1.1.1/PlainPasta-1.1.1.zip" alt="Download the latest version of Plain Pasta">Download App</a></figcaption>
<figcaption><a href="https://github.com/hisaac/PlainPasta/releases/download/1.1.1/PlainPasta-1.1.2.zip" alt="Download the latest version of Plain Pasta">Download App</a></figcaption>
</figure>
</header>

Expand Down

0 comments on commit 3a2c8ca

Please sign in to comment.