AppKit: Add CPTextAttachment and image support to CPTextView

AppKit lacked a public text attachment class, preventing rich text documents
from embedding or inserting images.

* AppKit/CPTextView/CPTextAttachment.j:
  - Implement CPTextAttachment (modelled on NSTextAttachment) supporting
    initialization via data and file type, contents, file types, images,
    bounds, and keyed archiving.
  - Adopt a TextKit 2-style view rendering architecture that scales images
    to fit text container width and triggers layout updates upon asynchronous loading.

* AppKit/CPTextView/CPTextStorage.j:
  - Update attributedStringWithAttachment: to accept CPTextAttachment instances
    alongside direct views, routing rendering through existing attachment pathways.

* AppKit/CPTextView/CPTextView.j:
  - Implement the insertImage: action (invoking browser file pickers) and
    Command-V paste handling for images.
  - Configure inserted attachments with responsive view instances scaled to
    text width, omitting live views during pasteboard archiving.

* AppKit/CPTextView/CPTextContainer.j:
  - Adjust attachment bounds to match updated container widths during layout invalidation.

* AppKit/AppKit.j:
  - Export CPTextAttachment.

* Tests/AppKit/CPTextAttachmentTest.j:
  - Add test coverage for data URLs, archiving, width scaling, insertion,
    and serialized text output.

* Tests/Manual/TextEditor/Resources/MainMenu.xib, MainMenu.cib:
  - Add Edit > Insert Image… menu item.

* Tests/Manual/TextEditor/WORKLIST.md:
  - Mark image insertion testing as completed; log remaining image tasks as open.

Rich text documents now support embedded images inserted via file selection or clipboard paste.
This commit is contained in:
David Richardson committed 2026-10-24 12:34:51 -06:00
1 parent 96cf42c763
commit df78974183
9 files changed
+760 -10

No files matched your search

+1
View File
@@ -101,6 +101,7 @@
@import "CPTableView.j"
@import "CPTabView.j"
@import "CPText.j"
@import "CPTextAttachment.j"
@import "CPTextField.j"
@import "CPTextList.j"
@import "CPTextView.j"
+367
View File
@@ -0,0 +1,367 @@
/*
* CPTextAttachment.j
* AppKit
*
* Created by David Richardson on 25/10/2026.
* Copyright David Richardson 2026.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/CPObject.j>
@import <Foundation/CPData.j>
@import <Foundation/CPNotificationCenter.j>
@import "CPImage.j"
@import "CPImageView.j"
/*
Posted when an attachment's displayed size changes, for example when its image has loaded.
A text view that contains the attachment lays its text out again.
*/
_CPTextAttachmentDidChangeSizeNotification = @"_CPTextAttachmentDidChangeSizeNotification";
/*!
@ingroup appkit
@class CPTextAttachment
A CPTextAttachment holds an image in rich text, as NSTextAttachment does in Cocoa. The text
holds the attachment as one attachment character (CPAttachmentCharacter), whose
CPAttachmentAttributeName attribute is the attachment. The attachment is edited, copied and
undone as that one character.
The attachment keeps the image's data and type, and shows the image in a view. As in TextKit
2, an attachment is drawn by a view, not by a cell. The text system lays the view out as the
character, at the view's size, with its bottom on the baseline. That size is the attachment's
bounds, or the image's natural size, scaled down to fit the width of the text, as in TextEdit.
*/
@implementation CPTextAttachment : CPObject
{
CPData _contents;
CPString _fileType;
CPImage _image;
CGRect _bounds;
CPImageView _imageView;
float _maximumWidth;
}
/*!
Initialises an attachment with image data.
@param contentData the image's data
@param aType the image's type, as a MIME type such as \c @"image/png", or a uniform type
identifier such as \c @"public.png"
*/
- (id)initWithData:(CPData)contentData ofType:(CPString)aType
{
if (self = [super init])
{
_contents = contentData;
_fileType = aType;
_bounds = CGRectMakeZero();
_maximumWidth = 0.0;
}
return self;
}
- (id)init
{
return [self initWithData:nil ofType:nil];
}
/* @ignore
Returns an attachment made from a data URL, such as the browser's FileReader produces.
*/
+ (CPTextAttachment)_attachmentWithDataURL:(CPString)aDataURL
{
var match = /^data:([^;,]+)(;base64)?,(.*)$/.exec(aDataURL || "");
if (!match)
return nil;
var data = match[2] ? [CPData dataWithBase64:match[3]] : [CPData dataWithRawString:decodeURIComponent(match[3])];
return [[self alloc] initWithData:data ofType:match[1]];
}
/*!
Returns the image's data.
*/
- (CPData)contents
{
return _contents;
}
/*!
Sets the image's data. The image is made again from the data.
*/
- (void)setContents:(CPData)contentData
{
_contents = contentData;
[self _setImage:nil];
}
/*!
Returns the image's type.
*/
- (CPString)fileType
{
return _fileType;
}
/*!
Sets the image's type.
*/
- (void)setFileType:(CPString)aType
{
_fileType = aType;
}
/*!
Returns the image. It is made from the attachment's data the first time it is needed.
*/
- (CPImage)image
{
if (!_image && _contents)
[self _setImage:[[CPImage alloc] initWithContentsOfFile:[self _dataURL]]];
return _image;
}
/*!
Sets the image. An image set this way has no data of its own unless it was made from a data
URL, so an attachment that must be archived or copied should be made with
-initWithData:ofType:.
*/
- (void)setImage:(CPImage)anImage
{
[self _setImage:anImage];
}
/*!
Returns the attachment's bounds in the text. With a zero size, the attachment takes the
image's natural size.
*/
- (CGRect)bounds
{
return CGRectMakeCopy(_bounds);
}
/*!
Sets the attachment's bounds in the text.
*/
- (void)setBounds:(CGRect)aRect
{
_bounds = CGRectMakeCopy(aRect);
[self _updateViewSize];
}
// MARK: Display
/* @ignore
Returns the view that shows the attachment in the text. The text system lays it out as the
attachment character.
*/
- (CPView)_attachmentView
{
if (!_imageView)
{
_imageView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
[_imageView setImageScaling:CPImageScaleAxesIndependently];
[_imageView setImage:[self image]];
[self _updateViewSize];
}
return _imageView;
}
/* @ignore
Sets the widest the attachment may be shown, which is the width of the text. Returns YES if
the displayed size changes.
*/
- (BOOL)_setMaximumWidth:(float)aWidth
{
if (_maximumWidth === aWidth)
return NO;
_maximumWidth = aWidth;
return [self _updateViewSize];
}
/* @ignore
Returns the size at which the attachment is shown: its bounds, or the image's natural size,
scaled down in proportion to fit the maximum width. The size is zero until the image has
loaded.
*/
- (CGSize)_displaySize
{
var size = CGSizeMakeCopy(_bounds.size);
if (!size.width || !size.height)
{
var image = [self image];
if (!image || [image loadStatus] !== CPImageLoadStatusCompleted)
return CGSizeMakeZero();
size = CGSizeMakeCopy([image size]);
}
if (_maximumWidth > 0.0 && size.width > _maximumWidth)
{
size.height = ROUND(size.height * _maximumWidth / size.width);
size.width = _maximumWidth;
}
return size;
}
/* @ignore
Gives the view the displayed size. Returns YES if the size changes.
*/
- (BOOL)_updateViewSize
{
if (!_imageView)
return NO;
var size = [self _displaySize];
if (CGSizeEqualToSize(size, [_imageView frameSize]))
return NO;
[_imageView setFrameSize:size];
return YES;
}
/* @ignore
Sets the image, and waits for it to load when it has not yet loaded.
*/
- (void)_setImage:(CPImage)anImage
{
if (_image)
[[CPNotificationCenter defaultCenter] removeObserver:self name:CPImageDidLoadNotification object:_image];
_image = anImage;
if (_image && [_image loadStatus] !== CPImageLoadStatusCompleted)
{
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_imageDidLoad:) name:CPImageDidLoadNotification object:_image];
[_image load];
}
if (_imageView)
{
[_imageView setImage:_image];
if ([self _updateViewSize])
[[CPNotificationCenter defaultCenter] postNotificationName:_CPTextAttachmentDidChangeSizeNotification object:self];
}
}
/* @ignore
The image's natural size is known once it has loaded, so the view takes its size, and the
text that contains the attachment is laid out again.
*/
- (void)_imageDidLoad:(CPNotification)aNotification
{
[[CPNotificationCenter defaultCenter] removeObserver:self name:CPImageDidLoadNotification object:_image];
if (_imageView)
[_imageView setImage:_image];
if ([self _updateViewSize])
[[CPNotificationCenter defaultCenter] postNotificationName:_CPTextAttachmentDidChangeSizeNotification object:self];
}
/* @ignore
Returns the attachment's data as a data URL, which the browser loads as an image.
*/
- (CPString)_dataURL
{
return "data:" + [self _MIMEType] + ";base64," + [_contents base64];
}
/* @ignore
Returns the image's MIME type. A uniform type identifier is mapped to its MIME type.
*/
- (CPString)_MIMEType
{
var type = _fileType || @"image/png";
if (type.indexOf("/") !== -1)
return type;
switch (type)
{
case @"public.jpeg":
return @"image/jpeg";
case @"com.compuserve.gif":
return @"image/gif";
case @"public.svg-image":
return @"image/svg+xml";
case @"org.webmproject.webp":
return @"image/webp";
default:
return @"image/png";
}
}
@end
var CPTextAttachmentContentsKey = @"CPTextAttachmentContents",
CPTextAttachmentFileTypeKey = @"CPTextAttachmentFileType",
CPTextAttachmentBoundsKey = @"CPTextAttachmentBounds";
@implementation CPTextAttachment (CPCoding)
/*!
Decodes the attachment. The image is made again from the archived data.
*/
- (id)initWithCoder:(CPCoder)aCoder
{
var contentsString = [aCoder decodeObjectForKey:CPTextAttachmentContentsKey];
self = [self initWithData:contentsString ? [CPData dataWithBase64:contentsString] : nil
ofType:[aCoder decodeObjectForKey:CPTextAttachmentFileTypeKey]];
if (self && [aCoder containsValueForKey:CPTextAttachmentBoundsKey])
_bounds = [aCoder decodeRectForKey:CPTextAttachmentBoundsKey];
return self;
}
/*!
Encodes the attachment's data, type and bounds. The view is not encoded.
*/
- (void)encodeWithCoder:(CPCoder)aCoder
{
if (_contents)
[aCoder encodeObject:[_contents base64] forKey:CPTextAttachmentContentsKey];
if (_fileType)
[aCoder encodeObject:_fileType forKey:CPTextAttachmentFileTypeKey];
if (!CGRectIsEmpty(_bounds))
[aCoder encodeRect:_bounds forKey:CPTextAttachmentBoundsKey];
}
@end
+3
View File
@@ -130,6 +130,9 @@ CPLineMovesUp = 4;
if (oldSize.width != _size.width)
{
// Image attachments fit the new width before the text is laid out again.
[_textView _setTextAttachmentsMaximumWidth:MAX(0.0, _size.width - 2.0 * _lineFragmentPadding)];
_inResizing = YES;
[_layoutManager invalidateLayoutForCharacterRange:CPMakeRange(0, [[_layoutManager textStorage] length])
isSoft:NO
+13 -5
View File
@@ -26,6 +26,7 @@
@import "CPText.j"
@import "CPFont.j"
@import "CPTextAttachment.j"
@class CPLayoutManager;
@@ -263,16 +264,23 @@ var CPTextStorageDelegate_textStorageWillProcessEditing_ = 1 << 1,
}
/*!
Returns an instance of CPTextStorage that contains the provided instance of CPView.
This can be used to insert arbitrary views into the text. These views are treated as individual characters during editing.
This works only with views that conform to the CPCoding protocol
Returns an instance of CPTextStorage that contains one attachment character for anAttachment.
The attachment is treated as an individual character during editing.
anAttachment is either a CPTextAttachment, as in Cocoa, or a view. A CPTextAttachment is
stored as the character's CPAttachmentAttributeName attribute, and its view is laid out as
the character. A view is inserted into the text directly; this works only with views that
conform to the CPCoding protocol.
*/
+ (id)attributedStringWithAttachment:(CPView)someView
+ (id)attributedStringWithAttachment:(id)anAttachment
{
var result = [[self alloc] initWithString:_CPAttachmentCharacterAsString];
[result setAttributes:@{_CPAttachmentView:someView} range:CPMakeRange(0, 1)];
if ([anAttachment isKindOfClass:[CPTextAttachment class]])
[result setAttributes:@{CPAttachmentAttributeName:anAttachment, _CPAttachmentView:[anAttachment _attachmentView]} range:CPMakeRange(0, 1)];
else
[result setAttributes:@{_CPAttachmentView:anAttachment} range:CPMakeRange(0, 1)];
return result;
}
+248 -2
View File
@@ -329,6 +329,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
[super _removeObservers];
[self _setObserveWindowKeyNotifications:NO];
[[CPNotificationCenter defaultCenter] removeObserver:self name:_CPTextAttachmentDidChangeSizeNotification object:nil];
[self _removeDelegateObservers];
}
@@ -339,6 +340,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
[super _addObservers];
[self _setObserveWindowKeyNotifications:YES];
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_textAttachmentDidChangeSize:) name:_CPTextAttachmentDidChangeSizeNotification object:nil];
[self _startObservingClipView];
[self _addDelegateObservers];
}
@@ -507,7 +509,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
[pasteboard setString:[stringForPasting._string stringByReplacingOccurrencesOfString:_CPAttachmentCharacterAsString withString:''] forType:CPStringPboardType];
[pasteboard setString:richData forType:CPRTFPboardType];
[pasteboard setString:_previousSelectionGranularity + '' forType:_CPSmartPboardType];
[pasteboard setString:[[CPKeyedArchiver archivedDataWithRootObject:stringForPasting] rawString] forType:_CPASPboardType];
[pasteboard setString:[[CPKeyedArchiver archivedDataWithRootObject:[self _attributedStringForArchiving:stringForPasting]] rawString] forType:_CPASPboardType];
}
else
{
@@ -829,6 +831,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
in a scroll view. \c -copyRuler: is enabled in rich text, and \c -pasteRuler: in editable
rich text when the ruler pasteboard holds a ruler. \c -changeTextList: is enabled in editable
rich text, and its item is checked when it shows the list style at the selection.
\c -insertImage: is enabled in editable rich text.
\c -copyFont: is enabled in rich text, and
\c -pasteFont: in editable rich text when the font pasteboard holds a style. The superscript,
subscript and baseline actions are enabled in editable rich text. Every other item is enabled.
@@ -857,6 +860,10 @@ var kDelegateRespondsTo_textShouldBeginEditing
if (action === @selector(pasteRuler:))
return [self isRichText] && [self isEditable] && !![[CPPasteboard pasteboardWithName:CPRulerPboard] availableTypeFromArray:[CPRulerPboardType]];
// Images can be inserted only in editable rich text.
if (action === @selector(insertImage:))
return [self isEditable] && [self isRichText];
// Lists apply only to editable rich text. The item for the list style at the selection is checked.
if (action === @selector(changeTextList:))
{
@@ -1042,6 +1049,8 @@ var kDelegateRespondsTo_textShouldBeginEditing
aString = [[CPAttributedString alloc] initWithString:aString attributes:_typingAttributes];
else if (![self isRichText])
aString = [[CPAttributedString alloc] initWithString:string attributes:_typingAttributes];
else
[self _prepareTextAttachmentsInAttributedString:aString];
var undoManager = [self _registeringUndoManager];
[undoManager setActionName:@"Replace/insert text"];
@@ -2649,7 +2658,6 @@ Sets the selection to a range of characters in response to user action.
maxSize = [self maxSize],
rect = CGRectUnion([_layoutManager boundingRectForGlyphRange:CPMakeRange(0, 1) inTextContainer:_textContainer],
[_layoutManager boundingRectForGlyphRange:CPMakeRange(MAX(0, [_layoutManager numberOfCharacters] - 2), 1) inTextContainer:_textContainer]);
if ([_layoutManager extraLineFragmentTextContainer] === _textContainer)
rect = CGRectUnion(rect, [_layoutManager extraLineFragmentRect]);
@@ -4338,6 +4346,235 @@ var CPTextViewTextListStyles = {
@end
/*!
Text attachment support. An image in rich text is a CPTextAttachment, held by one attachment
character. Its view is laid out as that character, at most as wide as the text. The user
inserts images with -insertImage:, or by pasting them.
*/
@implementation CPTextView (CPTextAttachmentSupport)
// MARK: Inserting Images
/*!
Lets the user choose image files with the browser's file picker, and inserts them as
attachments at the insertion point, or in place of the selection, in the order chosen.
@param aSender the object requesting this
*/
- (@action)insertImage:(id)aSender
{
if (!CPDOMAvailable || ![self isRichText] || ![self isEditable])
return;
var textView = self,
input = document.createElement("input");
input.type = "file";
input.accept = "image/*";
input.multiple = YES;
input.onchange = function()
{
[textView _insertImageFiles:input.files];
};
input.click();
}
/* @ignore
Reads image files from the browser, and inserts them as attachments in their original
order once all of them have been read. Files that are not images are skipped.
*/
- (void)_insertImageFiles:(FileList)someFiles
{
var files = [];
for (var i = 0; i < someFiles.length; i++)
if (someFiles[i].type.indexOf("image/") === 0)
files.push(someFiles[i]);
if (!files.length)
return;
var attachments = new Array(files.length);
for (var i = 0; i < files.length; i++)
[self _readImageFile:files[i] intoAttachments:attachments atIndex:i];
}
/* @ignore
Reads one image file as a data URL, and makes an attachment from it. When the last file has
been read, the attachments are inserted.
*/
- (void)_readImageFile:(File)aFile intoAttachments:(CPArray)someAttachments atIndex:(unsigned)anIndex
{
var textView = self,
reader = new FileReader();
reader.onload = function()
{
someAttachments[anIndex] = [CPTextAttachment _attachmentWithDataURL:reader.result] || [CPNull null];
[textView _insertAttachmentsIfComplete:someAttachments];
};
reader.onerror = function()
{
CPLog.warn("CPTextView: the image file " + aFile.name + " could not be read.");
someAttachments[anIndex] = [CPNull null];
[textView _insertAttachmentsIfComplete:someAttachments];
};
reader.readAsDataURL(aFile);
}
/* @ignore
Inserts the attachments once every file has been read. The files are read outside the run
loop, so the run loop is run afterwards, to close the undo group and display the change.
*/
- (void)_insertAttachmentsIfComplete:(CPArray)someAttachments
{
for (var i = 0; i < someAttachments.length; i++)
if (!someAttachments[i])
return;
var result = [[CPAttributedString alloc] initWithString:@""];
for (var i = 0; i < someAttachments.length; i++)
{
var attachment = someAttachments[i];
if (attachment === [CPNull null])
continue;
var attachmentString = [CPTextStorage attributedStringWithAttachment:attachment],
attributes = [_typingAttributes mutableCopy];
[attributes addEntriesFromDictionary:[attachmentString attributesAtIndex:0 effectiveRange:nil]];
[attachmentString setAttributes:attributes range:CPMakeRange(0, 1)];
[result appendAttributedString:attachmentString];
}
if ([result length])
[self insertText:result];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
}
// MARK: Attachment Layout
/* @ignore
Returns the widest an attachment may be shown: the width of the text container inside its
line fragment padding.
*/
- (float)_textAttachmentMaximumWidth
{
return MAX(0.0, [_textContainer containerSize].width - 2.0 * [_textContainer lineFragmentPadding]);
}
/* @ignore
Gives each CPTextAttachment in anAttributedString its view, which the text system lays out
as the attachment character, and fits it to the width of the text. Text decoded from an
archive, such as the internal pasteboard, holds the attachments without their views.
*/
- (void)_prepareTextAttachmentsInAttributedString:(CPAttributedString)anAttributedString
{
var string = [anAttributedString string],
maximumWidth = [self _textAttachmentMaximumWidth],
index = string.indexOf(_CPAttachmentCharacterAsString);
while (index !== -1)
{
var attachment = [anAttributedString attribute:CPAttachmentAttributeName atIndex:index effectiveRange:nil];
if ([attachment isKindOfClass:[CPTextAttachment class]])
{
[attachment _setMaximumWidth:maximumWidth];
[anAttributedString addAttribute:_CPAttachmentView value:[attachment _attachmentView] range:CPMakeRange(index, 1)];
}
index = string.indexOf(_CPAttachmentCharacterAsString, index + 1);
}
}
/* @ignore
Fits every CPTextAttachment in the text to aWidth. The text container calls this when its
width changes, before it lays the text out again.
*/
- (void)_setTextAttachmentsMaximumWidth:(float)aWidth
{
var string = [_textStorage string],
index = string.indexOf(_CPAttachmentCharacterAsString);
while (index !== -1)
{
var attachment = [_textStorage attribute:CPAttachmentAttributeName atIndex:index effectiveRange:nil];
if ([attachment isKindOfClass:[CPTextAttachment class]])
[attachment _setMaximumWidth:aWidth];
index = string.indexOf(_CPAttachmentCharacterAsString, index + 1);
}
}
/* @ignore
Returns the index of anAttachment's character in the text, or CPNotFound.
*/
- (unsigned)_indexOfTextAttachment:(CPTextAttachment)anAttachment
{
var string = [_textStorage string],
index = string.indexOf(_CPAttachmentCharacterAsString);
while (index !== -1)
{
if ([_textStorage attribute:CPAttachmentAttributeName atIndex:index effectiveRange:nil] === anAttachment)
return index;
index = string.indexOf(_CPAttachmentCharacterAsString, index + 1);
}
return CPNotFound;
}
/* @ignore
An attachment's displayed size has changed, for example because its image has loaded. If
the attachment is in this text view, the text is laid out again from it.
*/
- (void)_textAttachmentDidChangeSize:(CPNotification)aNotification
{
var index = [self _indexOfTextAttachment:[aNotification object]];
if (index === CPNotFound)
return;
[_layoutManager invalidateLayoutForCharacterRange:CPMakeRange(index, 1) isSoft:NO actualCharacterRange:nil];
[_layoutManager _validateLayoutAndGlyphs];
[self sizeToFit];
[self setNeedsDisplay:YES];
}
/* @ignore
Returns a copy of anAttributedString for archiving, without the views of its
CPTextAttachments. An attachment archives its image data, and gets a new view when the text
is decoded and inserted.
*/
- (CPAttributedString)_attributedStringForArchiving:(CPAttributedString)anAttributedString
{
var result = [[CPAttributedString alloc] initWithAttributedString:anAttributedString],
string = [result string],
index = string.indexOf(_CPAttachmentCharacterAsString);
while (index !== -1)
{
if ([[result attribute:CPAttachmentAttributeName atIndex:index effectiveRange:nil] isKindOfClass:[CPTextAttachment class]])
[result removeAttribute:_CPAttachmentView range:CPMakeRange(index, 1)];
index = string.indexOf(_CPAttachmentCharacterAsString, index + 1);
}
return result;
}
@end
@implementation CPTextView (CPTextViewDelegate)
- (BOOL)_delegateRespondsToShouldChangeTypingAttributesToAttributes
@@ -4778,6 +5015,15 @@ var _CPCopyPlaceholder = '-';
var pasteboard = [CPPasteboard generalPasteboard];
var nativePlainText = nativeClipboard.getData('text/plain');
// An image on the clipboard, such as a screenshot, is inserted as an attachment when the
// clipboard holds no text.
if (!nativePlainText && nativeClipboard.files && nativeClipboard.files.length &&
[currentFirstResponder respondsToSelector:@selector(_insertImageFiles:)] && [currentFirstResponder isRichText])
{
[currentFirstResponder _insertImageFiles:nativeClipboard.files];
return;
}
// The internal pasteboard holds what the application copied last. When the system
// clipboard holds other text, copied elsewhere, the internal pasteboard is out of date:
// it is replaced with that text, so that its rich text is not pasted in its place.
+118
View File
@@ -0,0 +1,118 @@
@import <AppKit/CPApplication.j>
@import <AppKit/CPTextAttachment.j>
@import <AppKit/CPTextView.j>
@implementation CPTextAttachmentTest : OJTestCase
{
CPWindow theWindow;
CPTextView textView;
}
- (void)setUp
{
[[CPApplication alloc] init];
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0) styleMask:CPWindowNotSizable];
textView = [[CPTextView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 300.0)];
[textView setRichText:YES];
[[theWindow contentView] addSubview:textView];
[theWindow makeFirstResponder:textView];
}
/*
Returns an attachment with a fixed size and no image, so that no image needs to load.
*/
- (CPTextAttachment)attachmentWithSize:(CGSize)aSize
{
var attachment = [[CPTextAttachment alloc] initWithData:nil ofType:@"image/png"];
[attachment setBounds:CGRectMake(0.0, 0.0, aSize.width, aSize.height)];
return attachment;
}
- (void)testAttachmentWithDataURL
{
var attachment = [CPTextAttachment _attachmentWithDataURL:@"data:image/gif;base64,R0lGODlhAQABAAAAACw="];
[self assert:@"image/gif" equals:[attachment fileType]];
[self assert:@"R0lGODlhAQABAAAAACw=" equals:[[attachment contents] base64]];
[self assertNull:[CPTextAttachment _attachmentWithDataURL:@"not a data URL"]];
}
- (void)testArchiving
{
var attachment = [[CPTextAttachment alloc] initWithData:[CPData dataWithBase64:@"R0lGODlhAQABAAAAACw="] ofType:@"public.png"];
[attachment setBounds:CGRectMake(0.0, 0.0, 40.0, 30.0)];
var decoded = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:attachment]];
[self assert:@"R0lGODlhAQABAAAAACw=" equals:[[decoded contents] base64]];
[self assert:@"public.png" equals:[decoded fileType]];
[self assert:40.0 equals:[decoded bounds].size.width];
[self assert:@"image/png" equals:[decoded _MIMEType]];
}
- (void)testDisplaySizeFitsTheMaximumWidth
{
var attachment = [self attachmentWithSize:CGSizeMake(400.0, 200.0)],
view = [attachment _attachmentView];
[self assert:400.0 equals:[view frameSize].width];
[self assertTrue:[attachment _setMaximumWidth:100.0]];
[self assert:100.0 equals:[view frameSize].width];
[self assert:50.0 equals:[view frameSize].height message:@"the image keeps its proportions"];
[self assertTrue:[attachment _setMaximumWidth:1000.0]];
[self assert:400.0 equals:[view frameSize].width message:@"an image is not enlarged beyond its size"];
}
- (void)testAttributedStringWithAttachment
{
var attachment = [self attachmentWithSize:CGSizeMake(20.0, 10.0)],
string = [CPTextStorage attributedStringWithAttachment:attachment],
view = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 10.0)],
viewString = [CPTextStorage attributedStringWithAttachment:view];
[self assert:_CPAttachmentCharacterAsString equals:[string string]];
[self assert:attachment equals:[string attribute:CPAttachmentAttributeName atIndex:0 effectiveRange:nil]];
[self assert:[attachment _attachmentView] equals:[string attribute:_CPAttachmentView atIndex:0 effectiveRange:nil]];
[self assert:view equals:[viewString attribute:_CPAttachmentView atIndex:0 effectiveRange:nil] message:@"a view is still inserted directly"];
[self assertNull:[viewString attribute:CPAttachmentAttributeName atIndex:0 effectiveRange:nil]];
}
- (void)testInsertedAttachmentFitsTheText
{
var attachment = [self attachmentWithSize:CGSizeMake(1000.0, 500.0)];
[textView setString:@"ab"];
[textView setSelectedRange:CPMakeRange(1, 0)];
[textView insertText:[CPTextStorage attributedStringWithAttachment:attachment]];
var maximumWidth = [textView _textAttachmentMaximumWidth];
[self assert:@"a" + _CPAttachmentCharacterAsString + @"b" equals:[textView string]];
[self assert:maximumWidth equals:[[attachment _attachmentView] frameSize].width];
[self assert:1 equals:[textView _indexOfTextAttachment:attachment]];
}
- (void)testArchivedTextHasNoAttachmentViews
{
var attachment = [self attachmentWithSize:CGSizeMake(20.0, 10.0)],
archived = [textView _attributedStringForArchiving:[CPTextStorage attributedStringWithAttachment:attachment]];
[self assert:attachment equals:[archived attribute:CPAttachmentAttributeName atIndex:0 effectiveRange:nil]];
[self assertNull:[archived attribute:_CPAttachmentView atIndex:0 effectiveRange:nil]];
// Inserting the text gives the attachment its view again.
[textView setString:@""];
[textView insertText:archived];
[self assert:[attachment _attachmentView] equals:[[textView textStorage] attribute:_CPAttachmentView atIndex:0 effectiveRange:nil]];
}
@end
@@ -1 +1 @@
280NPLIST;1.0;D;K;4;$topD;K;18;CPCibObjectDataKeyD;K;6;CP$UIDd;1;2E;E;K;8;$objectsA;S;5;$nullD;K;10;$classnameS;16;_CPCibObjectDataK;8;$classesA;S;16;_CPCibObjectDataS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;1;1E;K;28;_CPCibObjectDataNamesKeysKeyD;K;6;CP$UIDd;1;0E;K;30;_CPCibObjectDataNamesValuesKeyD;K;6;CP$UIDd;1;0E;K;30;_CPCibObjectDataClassesKeysKeyD;K;6;CP$UIDd;1;0E;K;32;_CPCibObjectDataClassesValuesKeyD;K;6;CP$UIDd;1;0E;K;30;_CPCibObjectDataConnectionsKeyD;K;6;CP$UIDd;1;4E;K;28;_CPCibObjectDataFrameworkKeyD;K;6;CP$UIDd;1;0E;K;26;_CPCibObjectDataNextOidKeyD;K;6;CP$UIDd;1;5E;K;30;_CPCibObjectDataObjectsKeysKeyD;K;6;CP$UIDd;1;6E;K;32;_CPCibObjectDataObjectsValuesKeyD;K;6;CP$UIDd;1;7E;K;26;_CPCibObjectDataOidKeysKeyD;K;6;CP$UIDd;1;8E;K;28;_CPCibObjectDataOidValuesKeyD;K;6;CP$UIDd;1;9E;K;28;_CPCibObjectDataFileOwnerKeyD;K;6;CP$UIDd;2;11E;K;33;_CPCibObjectDataVisibleWindowsKeyD;K;6;CP$UIDd;2;13E;E;D;K;10;$classnameS;7;CPArrayK;8;$classesA;S;7;CPArrayS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;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;CP$UIDd;3;121E;D;K;6;CP$UIDd;3;122E;D;K;6;CP$UIDd;3;123E;D;K;6;CP$UIDd;3;124E;D;K;6;CP$UIDd;3;125E;D;K;6;CP$UIDd;3;126E;D;K;6;CP$UIDd;3;127E;D;K;6;CP$UIDd;3;128E;D;K;6;CP$UIDd;3;129E;D;K;6;CP$UIDd;3;130E;D;K;6;CP$UIDd;3;131E;D;K;6;CP$UIDd;3;132E;D;K;6;CP$UIDd;3;133E;D;K;6;CP$UIDd;3;134E;D;K;6;CP$UIDd;3;135E;D;K;6;CP$UIDd;3;136E;D;K;6;CP$UIDd;3;137E;D;K;6;CP$UIDd;3;138E;D;K;6;CP$UIDd;3;139E;D;K;6;CP$UIDd;3;140E;D;K;6;CP$UIDd;3;141E;D;K;6;CP$UIDd;3;142E;D;K;6;CP$UIDd;3;143E;D;K;6;CP$UIDd;3;144E;D;K;6;CP$UIDd;3;145E;D;K;6;CP$UIDd;3;146E;D;K;6;CP$UIDd;3;147E;D;K;6;CP$UIDd;3;148E;D;K;6;CP$UIDd;3;149E;D;K;6;CP$UIDd;3;150E;D;K;6;CP$UIDd;3;151E;D;K;6;CP$UIDd;3;152E;D;K;6;CP$UIDd;3;153E;D;K;6;CP$UIDd;3;154E;D;K;6;CP$UIDd;3;155E;D;K;6;CP$UIDd;3;156E;D;K;6;CP$UIDd;3;157E;D;K;6;CP$UIDd;3;158E;D;K;6;CP$UIDd;3;159E;D;K;6;CP$UIDd;3;160E;D;K;6;CP$UIDd;3;161E;D;K;6;CP$UIDd;3;162E;D;K;6;CP$UIDd;3;163E;D;K;6;CP$UIDd;3;164E;D;K;6;CP$UIDd;3;165E;D;K;6;CP$UIDd;3;166E;D;K;6;CP$UIDd;3;167E;D;K;6;CP$UIDd;3;168E;D;K;6;CP$UIDd;3;169E;D;K;6;CP$UIDd;3;170E;D;K;6;CP$UIDd;3;171E;D;K;6;CP$UIDd;3;172E;D;K;6;CP$UIDd;3;173E;D;K;6;CP$UIDd;3;174E;D;K;6;CP$UIDd;3;175E;D;K;6;CP$UIDd;3;176E;D;K;6;CP$UIDd;3;177E;D;K;6;CP$UIDd;3;178E;D;K;6;CP$UIDd;3;179E;D;K;6;CP$UIDd;3;180E;D;K;6;CP$UIDd;3;181E;D;K;6;CP$UIDd;3;182E;D;K;6;CP$UIDd;3;183E;D;K;6;CP$UIDd;3;184E;D;K;6;CP$UIDd;3;185E;D;K;6;CP$UIDd;3;186E;D;K;6;CP$UIDd;3;187E;D;K;6;CP$UIDd;3;188E;D;K;6;CP$UIDd;3;189E;D;K;6;CP$UIDd;3;190E;D;K;6;CP$UIDd;3;191E;D;K;6;CP$UIDd;3;192E;D;K;6;CP$UIDd;3;193E;D;K;6;CP$UIDd;3;194E;D;K;6;CP$UIDd;3;195E;D;K;6;CP$UIDd;3;196E;D;K;6;CP$UIDd;3;197E;D;K;6;CP$UIDd;3;198E;D;K;6;CP$UIDd;3;199E;D;K;6;CP$UIDd;3;200E;D;K;6;CP$UIDd;3;201E;D;K;6;CP$UIDd;3;202E;D;K;6;CP$UIDd;3;203E;D;K;6;CP$UIDd;3;204E;D;K;6;CP$UIDd;3;205E;D;Line truncated
280NPLIST;1.0;D;K;4;$topD;K;18;CPCibObjectDataKeyD;K;6;CP$UIDd;1;2E;E;K;8;$objectsA;S;5;$nullD;K;10;$classnameS;16;_CPCibObjectDataK;8;$classesA;S;16;_CPCibObjectDataS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;1;1E;K;28;_CPCibObjectDataNamesKeysKeyD;K;6;CP$UIDd;1;0E;K;30;_CPCibObjectDataNamesValuesKeyD;K;6;CP$UIDd;1;0E;K;30;_CPCibObjectDataClassesKeysKeyD;K;6;CP$UIDd;1;0E;K;32;_CPCibObjectDataClassesValuesKeyD;K;6;CP$UIDd;1;0E;K;30;_CPCibObjectDataConnectionsKeyD;K;6;CP$UIDd;1;4E;K;28;_CPCibObjectDataFrameworkKeyD;K;6;CP$UIDd;1;0E;K;26;_CPCibObjectDataNextOidKeyD;K;6;CP$UIDd;1;5E;K;30;_CPCibObjectDataObjectsKeysKeyD;K;6;CP$UIDd;1;6E;K;32;_CPCibObjectDataObjectsValuesKeyD;K;6;CP$UIDd;1;7E;K;26;_CPCibObjectDataOidKeysKeyD;K;6;CP$UIDd;1;8E;K;28;_CPCibObjectDataOidValuesKeyD;K;6;CP$UIDd;1;9E;K;28;_CPCibObjectDataFileOwnerKeyD;K;6;CP$UIDd;2;11E;K;33;_CPCibObjectDataVisibleWindowsKeyD;K;6;CP$UIDd;2;13E;E;D;K;10;$classnameS;7;CPArrayK;8;$classesA;S;7;CPArrayS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;D;K;6;CP$UIDd;2;15E;D;K;6;CP$UIDd;2;17E;D;K;6;CP$UIDd;2;18E;D;K;6;CP$UIDd;2;19E;D;K;6;CP$UIDd;2;20E;D;K;6;CP$UIDd;2;21E;D;K;6;CP$UIDd;2;22E;D;K;6;CP$UIDd;2;23E;D;K;6;CP$UIDd;2;24E;D;K;6;CP$UIDd;2;25E;D;K;6;CP$UIDd;2;26E;D;K;6;CP$UIDd;2;27E;D;K;6;CP$UIDd;2;28E;D;K;6;CP$UIDd;2;29E;D;K;6;CP$UIDd;2;30E;D;K;6;CP$UIDd;2;31E;D;K;6;CP$UIDd;2;32E;D;K;6;CP$UIDd;2;33E;D;K;6;CP$UIDd;2;34E;D;K;6;CP$UIDd;2;35E;D;K;6;CP$UIDd;2;36E;D;K;6;CP$UIDd;2;37E;D;K;6;CP$UIDd;2;38E;D;K;6;CP$UIDd;2;39E;D;K;6;CP$UIDd;2;40E;D;K;6;CP$UIDd;2;41E;D;K;6;CP$UIDd;2;42E;D;K;6;CP$UIDd;2;43E;D;K;6;CP$UIDd;2;44E;D;K;6;CP$UIDd;2;45E;D;K;6;CP$UIDd;2;46E;D;K;6;CP$UIDd;2;47E;D;K;6;CP$UIDd;2;48E;D;K;6;CP$UIDd;2;49E;D;K;6;CP$UI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;D;K;6;CP$UIDd;3;102E;D;K;6;CP$UIDd;3;103E;D;K;6;CP$UIDd;3;104E;D;K;6;CP$UIDd;3;105E;D;K;6;CP$UIDd;3;106E;D;K;6;CP$UIDd;3;107E;D;K;6;CP$UIDd;3;108E;D;K;6;CP$UIDd;3;109E;D;K;6;CP$UIDd;3;110E;D;K;6;CP$UIDd;3;111E;D;K;6;CP$UIDd;3;112E;D;K;6;CP$UIDd;3;113E;D;K;6;CP$UIDd;3;114E;D;K;6;CP$UIDd;3;115E;D;K;6;CP$UIDd;3;116E;D;K;6;CP$UIDd;3;117E;D;K;6;CP$UIDd;3;118E;D;K;6;CP$UIDd;3;119E;D;K;6;CP$UIDd;3;120E;D;K;6;CP$UIDd;3;121E;D;K;6;CP$UIDd;3;122E;D;K;6;CP$UIDd;3;123E;D;K;6;CP$UIDd;3;124E;D;K;6;CP$UIDd;3;125E;D;K;6;CP$UIDd;3;126E;D;K;6;CP$UIDd;3;127E;D;K;6;CP$UIDd;3;128E;D;K;6;CP$UIDd;3;129E;D;K;6;CP$UIDd;3;130E;D;K;6;CP$UIDd;3;131E;D;K;6;CP$UIDd;3;132E;D;K;6;CP$UIDd;3;133E;D;K;6;CP$UIDd;3;134E;D;K;6;CP$UIDd;3;135E;D;K;6;CP$UIDd;3;136E;D;K;6;CP$UIDd;3;137E;D;K;6;CP$UIDd;3;138E;D;K;6;CP$UIDd;3;139E;D;K;6;CP$UIDd;3;140E;D;K;6;CP$UIDd;3;141E;D;K;6;CP$UIDd;3;142E;D;K;6;CP$UIDd;3;143E;D;K;6;CP$UIDd;3;144E;D;K;6;CP$UIDd;3;145E;D;K;6;CP$UIDd;3;146E;D;K;6;CP$UIDd;3;147E;D;K;6;CP$UIDd;3;148E;D;K;6;CP$UIDd;3;149E;D;K;6;CP$UIDd;3;150E;D;K;6;CP$UIDd;3;151E;D;K;6;CP$UIDd;3;152E;D;K;6;CP$UIDd;3;153E;D;K;6;CP$UIDd;3;154E;D;K;6;CP$UIDd;3;155E;D;K;6;CP$UIDd;3;156E;D;K;6;CP$UIDd;3;157E;D;K;6;CP$UIDd;3;158E;D;K;6;CP$UIDd;3;159E;D;K;6;CP$UIDd;3;160E;D;K;6;CP$UIDd;3;161E;D;K;6;CP$UIDd;3;162E;D;K;6;CP$UIDd;3;163E;D;K;6;CP$UIDd;3;164E;D;K;6;CP$UIDd;3;165E;D;K;6;CP$UIDd;3;166E;D;K;6;CP$UIDd;3;167E;D;K;6;CP$UIDd;3;168E;D;K;6;CP$UIDd;3;169E;D;K;6;CP$UIDd;3;170E;D;K;6;CP$UIDd;3;171E;D;K;6;CP$UIDd;3;172E;D;K;6;CP$UIDd;3;173E;D;K;6;CP$UIDd;3;174E;D;K;6;CP$UIDd;3;175E;D;K;6;CP$UIDd;3;176E;D;K;6;CP$UIDd;3;177E;D;K;6;CP$UIDd;3;178E;D;K;6;CP$UIDd;3;179E;D;K;6;CP$UIDd;3;180E;D;K;6;CP$UIDd;3;181E;D;K;6;CP$UIDd;3;182E;D;K;6;CP$UIDd;3;183E;D;K;6;CP$UIDd;3;184E;D;K;6;CP$UIDd;3;185E;D;K;6;CP$UIDd;3;186E;D;K;6;CP$UIDd;3;187E;D;K;6;CP$UIDd;3;188E;D;K;6;CP$UIDd;3;189E;D;K;6;CP$UIDd;3;190E;D;K;6;CP$UIDd;3;191E;D;K;6;CP$UIDd;3;192E;D;K;6;CP$UIDd;3;193E;D;K;6;CP$UIDd;3;194E;D;K;6;CP$UIDd;3;195E;D;K;6;CP$UIDd;3;196E;D;K;6;CP$UIDd;3;197E;D;K;6;CP$UIDd;3;198E;D;K;6;CP$UIDd;3;199E;D;K;6;CP$UIDd;3;200E;D;K;6;CP$UIDd;3;201E;D;K;6;CP$UIDd;3;202E;D;K;6;CP$UIDd;3;203E;D;K;6;CP$UIDd;3;204E;D;K;6;CP$UIDd;3;205E;D;KLine truncated
@@ -139,6 +139,12 @@
<action selector="insertLoremIpsum:" target="-1" id="KPb-XT-4QY"/>
</connections>
</menuItem>
<menuItem title="Insert Image…" id="Ew2-J6-C29">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="insertImage:" target="-1" id="DCs-g8-Xuw"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="214">
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</menuItem>
+3 -2
View File
@@ -15,7 +15,7 @@ TextEditor is a document-based test application and a tutorial. When the app use
### Text features not yet supported
- **Images in text.** AppKit has no general `CPTextAttachment` class, only the table attachment `_CPTableTextAttachment`. The RTF parser and producer do not handle `\pict`.
- **Images in text are not fully tested or complete.** `CPTextAttachment` holds an image as one attachment character, and Edit > Insert Image… and Command-V with an image on the clipboard insert images. Not yet tested: several images inserted at once, fitting a wide image to the text width when the window is resized, copying, pasting and undoing an image within the document, and pasting a screenshot. Not yet implemented: dropping image files on the text view, which needs file access in the drag pasteboard (`_CPDOMDataTransferPasteboard`); pasting images with Edit > Paste from the menu, which reads plain text only; and RTF `\pict` and Markdown `![]()`, so an image is lost when text is copied to another application as RTF.
- **Lists are not read from or written to RTF.** `CPTextList` and `textLists` in `CPParagraphStyle` now exist, but the RTF parser and producer do not handle `\listtable`, `\listoverridetable`, `\ls` and `\ilvl`. A list copied as RTF keeps its marker text and indents, but loses its list structure. CPMarkdownParser also writes "- item" as the literal text " • item", with no list.
### Text view
@@ -52,7 +52,7 @@ How the text system works, for the entries below: `CPTextView` does not use CSS
- Fonts through `CPFontManager` and `CPFontPanel`.
- RTF reading and writing.
- Images in text.
- Images in text: dropping image files, and the image formats in RTF and Markdown.
- A storage facade, with saving and opening in IndexedDB and through HTTP.
- An asynchronous fetch test: fetch the text of a page and show it for editing. The page must allow cross-origin requests.
- An inspector pane with `CPSplitViewController` and `CPViewController`, with a View menu item that sends `toggleInspector:`.
@@ -83,4 +83,5 @@ How the text system works, for the entries below: `CPTextView` does not use CSS
- Format > Text > Copy Ruler and Paste Ruler with lists: pasting adds or removes list markers, on one or several paragraphs, and a pasted item joins the neighbouring list.
- Typing at the end of styled text, and the font panel, use the style of the character before the insertion point.
- Edit > Copy, Cut and Paste from the menu: plain text moves to and from other applications through the system clipboard; text copied and pasted within the application keeps its style. Command-V pastes text copied in another application, not an earlier copy within the application.
- Edit > Insert Image…: a JPEG or PNG image is inserted inside the text and at the end of the text.
- Builds with both the legacy toolchain and capp-build.