Tests: Add a help popover to TextEditor

Triggering Help > TextEdit by Cappuccino Help, pressing Command-?, or
selecting Help from the text view's context menu now displays a
transient popover using the default appearance. The popover anchors to
the active text selection or the clicked point and contains scrollable
help text exceeding the popover's height.

The document window controller implements showHelp: and injects the
Help item into the context menu via the text view delegate. Because
CPApplication does not implement showHelp:, the menu item disables
automatically when no document window is open.
This commit is contained in:
David Richardson committed 2026-11-18 17:45:56 -06:00
1 parent 57287c9354
commit 175fa1dcab
5 files changed
+252 -109

No files matched your search

@@ -26,6 +26,7 @@
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import "HelpViewController.j"
@import "LoremIpsum.j"
@import "TableExample.j"
@@ -56,6 +57,11 @@ function compareZoomLevels(aLevel, anotherLevel)
File's Owner in DocumentWindow.xib, so this controller is the window's
delegate. windowDidLoad assigns it again, so the delegate is set even if
the connection is missing from the xib.
The controller is also the text view's delegate (CPTextViewDelegate),
but the protocol list names only CPWindowDelegate. The parser rejects a
comma in the protocol list of an implementation. A protocol list is a
declaration, so leaving one out changes no behaviour.
*/
@implementation DocumentWindowController : CPWindowController <CPWindowDelegate>
{
@@ -64,6 +70,11 @@ function compareZoomLevels(aLevel, anotherLevel)
to the text view in DocumentWindow.xib.
*/
@outlet CPTextView textView;
/*
The help popover of this window. It is made on first use and kept.
*/
CPPopover _helpPopover;
}
- (id)init
@@ -93,6 +104,13 @@ function compareZoomLevels(aLevel, anotherLevel)
in code.
*/
[textView setRulerVisible:YES];
/*
Make this controller the text view's delegate, so that it can add a
Help item to the text view's context menu. See
textView:menu:forEvent:atIndex: below.
*/
[textView setDelegate:self];
}
/*!
@@ -134,6 +152,97 @@ function compareZoomLevels(aLevel, anotherLevel)
[textView insertText:[TableExample attributedString]];
}
/*!
Shows the help popover.
Help > TextEdit by Cappuccino Help in MainMenu.xib sends showHelp: to
First Responder, with the key equivalent Command-?. The Help item of the
text view's context menu sends the same action. The responder chain
delivers it to the controller of the active document's window, as it
does Insert Lorem Ipsum.
In Cocoa, NSApplication also implements showHelp:, and opens the
application's help book. CPApplication does not yet implement it. So
when no document window is open, no responder handles the action, and
AppKit disables the menu item.
The popover points at the place the help is about. From the context
menu, that is the point that was clicked, which the menu item carries in
its represented object. From the Help menu or the keyboard, it is the
selection. See helpAnchorRect.
The popover sets no appearance of its own. It takes the default, so it
follows the appearance of the text view: under a theme with a dark set,
it is dark when the text view is dark. A transient popover closes when
the user clicks outside it or presses Escape.
*/
- (@action)showHelp:(id)aSender
{
if (!_helpPopover)
{
_helpPopover = [[CPPopover alloc] init];
[_helpPopover setContentViewController:[[HelpViewController alloc] init]];
[_helpPopover setBehavior:CPPopoverBehaviorTransient];
}
var clickedPoint = [aSender isKindOfClass:[CPMenuItem class]] ? [aSender representedObject] : nil,
anchorRect = clickedPoint ? CGRectMake(clickedPoint.x, clickedPoint.y, 1.0, 1.0) : [self helpAnchorRect];
[_helpPopover showRelativeToRect:anchorRect ofView:textView preferredEdge:CPMaxYEdge];
}
/*!
Returns the rectangle, in the text view's coordinates, at which the help
popover points when it is shown from the Help menu or the keyboard.
This is the rectangle of the first character of the selection, or of the
character after the insertion point. At the end of the text, the layout
manager gives the last character instead, and in an empty document a
small rectangle at the start of the text. It gives the rectangle in the
coordinates of the text container, so it is moved by the container's
origin in the text view. When the selection is scrolled out of view, the
popover points at the top centre of the visible part of the text.
*/
- (CGRect)helpAnchorRect
{
var visibleRect = [textView visibleRect],
selection = [textView selectedRange],
rect = [[textView layoutManager] boundingRectForGlyphRange:CPMakeRange(selection.location, 1) inTextContainer:[textView textContainer]],
origin = [textView textContainerOrigin];
rect = CGRectOffset(rect, origin.x, origin.y);
if (CGRectIsEmpty(rect) || !CGRectIntersectsRect(rect, visibleRect))
rect = CGRectMake(CGRectGetMidX(visibleRect), CGRectGetMinY(visibleRect), 1.0, 1.0);
return rect;
}
/*!
Adds a Help item to the text view's context menu.
This is a CPTextViewDelegate method. The text view calls it each time it
shows its context menu, with the menu it is about to show, and shows the
menu that this method returns. The text view makes a new menu each time,
so the item is added to a fresh menu and does not accumulate.
The item sends showHelp: to First Responder, like the Help menu item.
Its represented object is the point that was clicked, in the text view's
coordinates, so that showHelp: can point the popover at it.
*/
- (CPMenu)textView:(CPTextView)aTextView menu:(CPMenu)aMenu forEvent:(CPEvent)anEvent atIndex:(unsigned)anIndex
{
var helpItem = [[CPMenuItem alloc] initWithTitle:@"Help" action:@selector(showHelp:) keyEquivalent:@""];
[helpItem setRepresentedObject:[aTextView convertPoint:[anEvent locationInWindow] fromView:nil]];
[aMenu addItem:[CPMenuItem separatorItem]];
[aMenu addItem:helpItem];
return aMenu;
}
/*!
Returns the scroll view that encloses the text view.
@@ -0,0 +1,139 @@
/*
* HelpViewController.j
* TextEditor
*
* Copyright (c) 2026 David Richardson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
@import <AppKit/AppKit.j>
/*
The text of the help popover: a title and paragraphs, shown in this order. There are more
paragraphs than fit in the popover, so its text scrolls.
*/
var HelpTitle = @"Help for 'TextEdit by Cappuccino'",
HelpParagraphs = [
@"Type in the window to edit the document. The ruler above the text sets the indents and the tab stops of the paragraph at the selection. Click the ruler to add a tab stop, and drag a tab stop off the ruler to remove it.",
@"Control-click a tab stop to change its type: left, centre, right or decimal. Format > Text > Copy Ruler and Paste Ruler apply the indents and tab stops of one paragraph to others.",
@"Format > Font changes the font, its size and the baseline. Bigger and Smaller, Command-+ and Command--, change the size step by step. Copy Style and Paste Style apply the style of one part of the text to another.",
@"Format > Text aligns and justifies paragraphs.",
@"Format > List makes bulleted and numbered lists. Press Return to start the next item, and press Return in an empty item to end the list. Press Tab at the start of an item to nest it, and Shift-Tab to return it.",
@"Edit > Insert Image… inserts a JPEG or PNG image. Edit > Insert Lorem Ipsum and Edit > Insert Table Example add sample text.",
@"Edit > Copy, Cut and Paste move plain text to and from other applications. Inside TextEdit by Cappuccino, copied text keeps its style, its images, its tables and its lists.",
@"View > Zoom Level, Zoom In, Zoom Out and Actual Size change the magnification of the text.",
@"TextEdit by Cappuccino > Settings… chooses a light or a dark appearance, or Auto, which follows the system.",
@"To show this help, choose Help > TextEdit by Cappuccino Help, press Command-?, or choose Help in the context menu of the text."
],
HelpWidth = 360.0,
HelpHeight = 300.0,
HelpMargin = 16.0,
HelpSpacing = 10.0;
/*!
Supplies the content of the help popover.
A popover shows the view of its content view controller, and takes its
size from that view. This controller makes its view in code, in
loadView, so it needs no cib. The view controller is made once for each
document window and kept, so the view is also made only once.
The view has a fixed size. The title stays at the top, and the
paragraphs are in a scroll view below it. The paragraphs are taller than
the scroll view, so the help scrolls, as long help does in AppKit.
The labels use the theme's colours and set none of their own. So the text
follows the popover's appearance: dark text in a light popover, light
text in a dark one.
*/
@implementation HelpViewController : CPViewController
- (void)loadView
{
var view = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, HelpWidth, HelpHeight)],
textWidth = HelpWidth - 2 * HelpMargin,
titleLabel = [self labelWithText:HelpTitle font:[CPFont boldSystemFontOfSize:15.0] width:textWidth];
[titleLabel setFrameOrigin:CGPointMake(HelpMargin, HelpMargin)];
[view addSubview:titleLabel];
/*
The scroll view fills the rest of the view and reaches its right
edge, so that the vertical scroller sits at the edge of the popover.
It has no border and no horizontal scroller, and its scroller hides
when the text is not scrolled.
*/
var scrollTop = CGRectGetMaxY([titleLabel frame]) + HelpSpacing,
scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(HelpMargin, scrollTop, HelpWidth - HelpMargin, HelpHeight - scrollTop - HelpMargin)];
[scrollView setBorderType:CPNoBorder];
[scrollView setHasHorizontalScroller:NO];
[scrollView setAutohidesScrollers:YES];
[scrollView setDocumentView:[self paragraphViewWithWidth:textWidth]];
[view addSubview:scrollView];
[self setView:view];
}
/*!
Returns a view that holds the paragraphs, one below the other, aWidth
wide and as tall as the paragraphs. The view's coordinates start at the
top left, so y grows downwards.
*/
- (CPView)paragraphViewWithWidth:(float)aWidth
{
var paragraphView = [[CPView alloc] initWithFrame:CGRectMakeZero()],
bodyFont = [CPFont systemFontOfSize:13.0],
y = 0.0;
for (var i = 0; i < HelpParagraphs.length; i++)
{
var label = [self labelWithText:HelpParagraphs[i] font:bodyFont width:aWidth];
[label setFrameOrigin:CGPointMake(0.0, y)];
[paragraphView addSubview:label];
y += CGRectGetHeight([label frame]) + HelpSpacing;
}
[paragraphView setFrameSize:CGSizeMake(aWidth, y - HelpSpacing)];
return paragraphView;
}
/*!
Returns a label that shows aText in aFont, wrapped to aWidth. The label
is as tall as the wrapped text. A few points are added to the measured
height, so that the last line is not clipped.
*/
- (CPTextField)labelWithText:(CPString)aText font:(CPFont)aFont width:(float)aWidth
{
var label = [CPTextField labelWithTitle:aText],
height = [aText sizeWithFont:aFont inWidth:aWidth].height + 4.0;
[label setFont:aFont];
[label setLineBreakMode:CPLineBreakByWordWrapping];
[label setFrameSize:CGSizeMake(aWidth, height)];
return label;
}
@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;D;K;6;CP$UIDd;2;15E;D;K;6;CP$UIDd;2;16E;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;D;K;6;CP$UIDd;2;17E;D;K;6;CP$UIDd;2;19E;D;K;6;CP$UIDd;2;21E;D;K;6;CP$UIDd;2;23E;D;K;6;CP$UIDd;2;25E;D;K;6;CP$UIDd;2;27E;D;K;6;CP$UIDd;2;29E;D;K;6;CP$UIDd;2;30E;D;K;6;CP$UIDd;2;32E;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;38E;D;K;6;CP$UIDd;2;40E;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;D;K;6;CP$UIDd;2;11E;D;K;6;CP$UIDd;2;11E;D;K;6;CP$UIDd;2;19E;D;K;6;CP$UIDd;2;21E;D;K;6;CP$UIDd;2;23E;D;K;6;CP$UIDd;2;25E;D;K;6;CP$UIDd;2;23E;D;K;6;CP$UIDd;2;23E;D;K;6;CP$UIDd;2;19E;D;K;6;CP$UIDd;2;32E;D;K;6;CP$UIDd;2;32E;D;K;6;CP$UIDd;2;32E;D;K;6;CP$UIDd;2;32E;D;K;6;CP$UIDd;2;32E;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;D;K;10;$classnameS;18;_CPCibCustomObjectK;8;$classesA;S;18;_CPCibCustomObjectS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;10E;K;27;_CPCibCustomObjectClassNameD;K;6;CP$UIDd;2;41E;E;D;K;10;$classnameS;5;CPSetK;8;$classesA;S;5;CPSetS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;12E;K;15;CPSetObjectsKeyD;K;6;CP$UIDd;2;42E;E;D;K;10;$classnameS;20;CPCibOutletConnectorK;8;$classesA;S;20;CPCibOutletConnectorS;14;CPCibConnectorS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;14E;K;24;_CPCibConnectorSourceKeyD;K;6;CP$UIDd;2;11E;K;29;_CPCibConnectorDestinationKeyD;K;6;CP$UIDd;2;27E;K;23;_CPCibConnectorLabelKeyD;K;6;CP$UIDd;2;43E;E;D;K;6;$classD;K;6;CP$UIDd;2;14E;K;24;_CPCibConnectorSourceKeyD;K;6;CP$UIDd;2;11E;K;29;_CPCibConnectorDestinationKeyD;K;6;CP$UIDd;2;19E;K;23;_CPCibConnectorLabelKeyD;K;6;CP$UIDd;2;44E;E;D;K;6;$classD;K;6;CP$UIDd;2;10E;K;27;_CPCibCustomObjectClassNameD;K;6;CP$UIDd;2;45E;E;D;K;10;$classnameS;20;_CPCibWindowTemplateK;8;$classesA;S;20;_CPCibWindowTemplateS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;18E;K;32;_CPCibWindowTemplateViewClassKeyD;K;6;CP$UIDd;2;32E;K;34;_CPCibWindowTemplateWindowClassKeyD;K;6;CP$UIDd;2;46E;K;30;_CPCibWindowTemplateWTFlagsKeyD;K;6;CP$UIDd;2;47E;K;33;_CPCibWindowTemplateWindowRectKeyD;K;6;CP$UIDd;2;48E;K;33;_CPCibWindowTemplateScreenRectKeyD;K;6;CP$UIDd;2;49E;K;30;_CPCibWindowTempatStyleMaskKeyD;K;6;CP$UIDd;2;50E;K;34;_CPCibWindowTemplateWindowTitleKeyD;K;6;CP$UIDd;2;51E;K;33;_CPCibWindowTemplateWindowViewKeyD;K;6;CP$UIDd;2;21E;E;D;K;10;$classnameS;6;CPViewK;8;$classesA;S;6;CPViewS;11;CPResponderS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;20E;K;18;CPResponderMenuKeyD;K;6;CP$UIDd;1;0E;K;12;CPViewTagKeyD;K;6;CP$UIDd;2;52E;K;14;CPViewFrameKeyD;K;6;CP$UIDd;2;53E;K;15;CPViewBoundsKeyD;K;6;CP$UIDd;2;53E;K;17;CPViewSubviewsKeyD;K;6;CP$UIDd;2;54E;K;22;CPViewAutoresizingMaskD;K;6;CP$UIDd;2;55E;K;19;CPViewThemeClassKeyD;K;6;CP$UIDd;2;56E;K;19;CPViewThemeStateKeyD;K;6;CP$UIDd;2;57E;K;14;CPViewScaleKeyD;K;6;CP$UIDd;2;58E;K;18;CPViewSizeScaleKeyD;K;6;CP$UIDd;2;58E;K;17;CPViewIsScaledKeyD;K;6;CP$UIDd;2;59E;K;19;CPViewAppearanceKeyD;K;6;CP$UIDd;1;0E;K;22;CPViewTrackingAreasKeyD;K;6;CP$UIDd;2;60E;E;D;K;10;$classnameS;12;CPScrollViewK;8;$classesA;S;12;CPScrollViewS;6;CPViewS;11;CPResponderS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;22E;K;27;CPResponderNextResponderKeyD;K;6;CP$UIDd;2;21E;K;18;CPResponderMenuKeyD;K;6;CP$UIDd;1;0E;K;12;CPViewTagKeyD;K;6;CP$UIDd;2;52E;K;14;CPViewFrameKeyD;K;6;CP$UIDd;2;53E;K;15;CPViewBoundsKeyD;K;6;CP$UIDd;2;53E;K;17;CPViewSubviewsKeyD;K;6;CP$UIDd;2;61E;K;18;CPViewSuperviewKeyD;K;6;CP$UIDd;2;21E;K;22;CPViewAutoresizingMaskD;K;6;CP$UIDd;2;55E;K;19;CPViewThemeClassKeyD;K;6;CP$UIDd;2;62E;K;19;CPViewThemeStateKeyD;K;6;CP$UIDd;2;57E;K;14;CPViewScaleKeyD;K;6;CP$UIDd;2;58E;K;18;CPViewSizeScaleKeyD;K;6;CP$UIDd;2;58E;K;17;CPViewIsScaledKeyD;K;6;CP$UIDd;2;59E;K;19;CPViewAppearanceKeyD;K;6;CP$UIDd;2;64E;K;22;CPViewTrackingAreasKeyD;K;6;CP$UIDd;2;65E;K;23;CPScrollViewContentViewD;K;6;CP$UIDd;2;25E;K;29;CPScrollViewHeaderClipViewKeyD;K;6;CP$UIDd;1;0E;K;21;CPScrollViewVScrollerD;K;6;CP$UIDd;2;30E;K;21;CPScrollViewHScrollerD;K;6Line 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;16E;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;D;K;6;CP$UIDd;2;17E;D;K;6;CP$UIDd;2;19E;D;K;6;CP$UIDd;2;21E;D;K;6;CP$UIDd;2;23E;D;K;6;CP$UIDd;2;25E;D;K;6;CP$UIDd;2;27E;D;K;6;CP$UIDd;2;29E;D;K;6;CP$UIDd;2;30E;D;K;6;CP$UIDd;2;32E;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;38E;D;K;6;CP$UIDd;2;40E;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;D;K;6;CP$UIDd;2;11E;D;K;6;CP$UIDd;2;11E;D;K;6;CP$UIDd;2;19E;D;K;6;CP$UIDd;2;21E;D;K;6;CP$UIDd;2;23E;D;K;6;CP$UIDd;2;25E;D;K;6;CP$UIDd;2;23E;D;K;6;CP$UIDd;2;23E;D;K;6;CP$UIDd;2;19E;D;K;6;CP$UIDd;2;32E;D;K;6;CP$UIDd;2;32E;D;K;6;CP$UIDd;2;32E;D;K;6;CP$UIDd;2;32E;D;K;6;CP$UIDd;2;32E;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;D;K;6;$classD;K;6;CP$UIDd;1;3E;K;10;CP.objectsA;E;E;D;K;10;$classnameS;18;_CPCibCustomObjectK;8;$classesA;S;18;_CPCibCustomObjectS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;10E;K;27;_CPCibCustomObjectClassNameD;K;6;CP$UIDd;2;41E;E;D;K;10;$classnameS;5;CPSetK;8;$classesA;S;5;CPSetS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;12E;K;15;CPSetObjectsKeyD;K;6;CP$UIDd;2;42E;E;D;K;10;$classnameS;20;CPCibOutletConnectorK;8;$classesA;S;20;CPCibOutletConnectorS;14;CPCibConnectorS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;14E;K;24;_CPCibConnectorSourceKeyD;K;6;CP$UIDd;2;11E;K;29;_CPCibConnectorDestinationKeyD;K;6;CP$UIDd;2;27E;K;23;_CPCibConnectorLabelKeyD;K;6;CP$UIDd;2;43E;E;D;K;6;$classD;K;6;CP$UIDd;2;14E;K;24;_CPCibConnectorSourceKeyD;K;6;CP$UIDd;2;11E;K;29;_CPCibConnectorDestinationKeyD;K;6;CP$UIDd;2;19E;K;23;_CPCibConnectorLabelKeyD;K;6;CP$UIDd;2;44E;E;D;K;6;$classD;K;6;CP$UIDd;2;10E;K;27;_CPCibCustomObjectClassNameD;K;6;CP$UIDd;2;45E;E;D;K;10;$classnameS;20;_CPCibWindowTemplateK;8;$classesA;S;20;_CPCibWindowTemplateS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;18E;K;32;_CPCibWindowTemplateViewClassKeyD;K;6;CP$UIDd;2;32E;K;34;_CPCibWindowTemplateWindowClassKeyD;K;6;CP$UIDd;2;46E;K;30;_CPCibWindowTemplateWTFlagsKeyD;K;6;CP$UIDd;2;47E;K;33;_CPCibWindowTemplateWindowRectKeyD;K;6;CP$UIDd;2;48E;K;33;_CPCibWindowTemplateScreenRectKeyD;K;6;CP$UIDd;2;49E;K;30;_CPCibWindowTempatStyleMaskKeyD;K;6;CP$UIDd;2;50E;K;34;_CPCibWindowTemplateWindowTitleKeyD;K;6;CP$UIDd;2;51E;K;33;_CPCibWindowTemplateWindowViewKeyD;K;6;CP$UIDd;2;21E;E;D;K;10;$classnameS;6;CPViewK;8;$classesA;S;6;CPViewS;11;CPResponderS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;20E;K;18;CPResponderMenuKeyD;K;6;CP$UIDd;1;0E;K;12;CPViewTagKeyD;K;6;CP$UIDd;2;52E;K;14;CPViewFrameKeyD;K;6;CP$UIDd;2;53E;K;15;CPViewBoundsKeyD;K;6;CP$UIDd;2;53E;K;17;CPViewSubviewsKeyD;K;6;CP$UIDd;2;54E;K;22;CPViewAutoresizingMaskD;K;6;CP$UIDd;2;55E;K;19;CPViewThemeClassKeyD;K;6;CP$UIDd;2;56E;K;19;CPViewThemeStateKeyD;K;6;CP$UIDd;2;57E;K;14;CPViewScaleKeyD;K;6;CP$UIDd;2;58E;K;18;CPViewSizeScaleKeyD;K;6;CP$UIDd;2;58E;K;17;CPViewIsScaledKeyD;K;6;CP$UIDd;2;59E;K;19;CPViewAppearanceKeyD;K;6;CP$UIDd;1;0E;K;22;CPViewTrackingAreasKeyD;K;6;CP$UIDd;2;60E;E;D;K;10;$classnameS;12;CPScrollViewK;8;$classesA;S;12;CPScrollViewS;6;CPViewS;11;CPResponderS;8;CPObjectE;E;D;K;6;$classD;K;6;CP$UIDd;2;22E;K;27;CPResponderNextResponderKeyD;K;6;CP$UIDd;2;21E;K;18;CPResponderMenuKeyD;K;6;CP$UIDd;1;0E;K;12;CPViewTagKeyD;K;6;CP$UIDd;2;52E;K;14;CPViewFrameKeyD;K;6;CP$UIDd;2;53E;K;15;CPViewBoundsKeyD;K;6;CP$UIDd;2;53E;K;17;CPViewSubviewsKeyD;K;6;CP$UIDd;2;61E;K;18;CPViewSuperviewKeyD;K;6;CP$UIDd;2;21E;K;22;CPViewAutoresizingMaskD;K;6;CP$UIDd;2;55E;K;19;CPViewThemeClassKeyD;K;6;CP$UIDd;2;62E;K;19;CPViewThemeStateKeyD;K;6;CP$UIDd;2;57E;K;14;CPViewScaleKeyD;K;6;CP$UIDd;2;58E;K;18;CPViewSizeScaleKeyD;K;6;CP$UIDd;2;58E;K;17;CPViewIsScaledKeyD;K;6;CP$UIDd;2;59E;K;19;CPViewAppearanceKeyD;K;6;CP$UIDd;1;0E;K;22;CPViewTrackingAreasKeyD;K;6;CP$UIDd;2;63E;K;23;CPScrollViewContentViewD;K;6;CP$UIDd;2;25E;K;29;CPScrollViewHeaderClipViewKeyD;K;6;CP$UIDd;1;0E;K;21;CPScrollViewVScrollerD;K;6;CP$UIDd;2;30E;K;21;CPScrollViewHScrollerD;K;6;Line truncated
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="25408" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="25507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="25408"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="25507"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@@ -22,7 +22,7 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView appearanceType="aqua" fixedFrame="YES" borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="H3c-yb-ZSJ">
<scrollView fixedFrame="YES" borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="H3c-yb-ZSJ">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" drawsBackground="NO" id="PKr-jd-g4l">
-105
View File
@@ -1,105 +0,0 @@
# TextEditor Work List
TextEditor is a document-based test application and a tutorial. When the app uses AppKit, it shows gaps in the framework. This list records those gaps and the planned additions to the app.
## AppKit gaps
### Windows and documents
- **The "save changes" alert is modal for the whole app.** `CPDocument` shows it with `runModal` (`CPDocument.j:903`). Cocoa attaches it as a sheet to the document window, so that only that document is blocked.
- **Save cannot work without a server.** With no file URL, Save uses `CPSavePanel`, which falls back to `window.prompt` (`CPSavePanel.j:79`). `CPDocument` then sends an HTTP POST. A storage facade is needed, with local (IndexedDB) and remote (HTTP) implementations.
### Toolbar
- **The Fonts and Print standard items are not implemented.** `_standardItemWithItemIdentifier:` returns `nil` for both (`_CPToolbarItem.j:641`). AppKit needs `_CPToolbarShowFontsItem` (sends `orderFrontFontPanel:`) and `_CPToolbarPrintItem` (sends `printDocument:`). nib2cib needs matching classes.
### Text features not yet supported
- **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, undoing an image change, 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.
- **Tables can only be inserted from Markdown, and are not yet tested interactively.** The only source of tables is CPMarkdownParser, which builds the private `_CPTableTextAttachment`, a view in the text whose cells are text views of their own. Edit > Insert Table Example inserts a sample through it. Not yet tested: what Tab does in a cell, deleting the table and undoing, narrowing the window, and Format menu commands while a cell is being edited. Known from the code: nothing calls its `resizeToWidth:`, so it keeps its width of 500 points; and in the sample its right edge and the last row's bottom border are not drawn. A command to insert a table, with a fixed default size and no options, waits on these results.
- **Rich text does not reach native applications.** The RTF producer and parser now handle lists (`\listtable`, `\listoverridetable`, `\ls`, `\ilvl`, and Cocoa's `\levelmarker`), Unicode (`\uN`) and the first line indent as an offset from the left indent, and the unit tests round-trip them. But browsers do not put `text/rtf` from a page's clipboard event on the system clipboard in a form native applications read: text copied from TextEditor with Command-C reaches native TextEdit as plain text. RTF on the clipboard works only between Cappuccino applications in the same browser. Rich text for native applications needs an HTML producer (`text/html`) for the subset the text view makes. Not yet tested: what arrives from native TextEdit with Command-V, in each browser. RTF `\pict` is not implemented. CPMarkdownParser also writes "- item" as the literal text " • item", with no list.
### Text view
How the text system works, for the entries below: `CPTextView` does not use CSS text layout. `CPSimpleTypesetter` measures text with the canvas `measureText` (`sizeWithFont:inWidth:` in `CPStringDrawing.j`), measuring growing substrings so that each character's advancement includes the browser's kerning. It then breaks lines, places tabs, and applies indents and alignment itself (`CPTypesetter.j`). `_CPLineFragment` (`CPLayoutManager.j`) draws each run of identical attributes as one absolutely positioned `<span>`, at the computed position, with `white-space: pre` and the run's font, colour and underline in CSS. Inside a span the browser shapes the glyphs, including its own kerning and ligatures.
- **Kerning and ligature settings are not implemented.** Format > Font > Kern sends `useStandardKerning:`, `turnOffKerning:`, `tightenKerning:` and `loosenKerning:`, and Format > Font > Ligatures sends `useStandardLigatures:`, `turnOffLigatures:` and `useAllLigatures:`. `CPTextView` implements none of them, so the items are disabled. `CPText.j` defines `CPKernAttributeName` and `CPLigatureAttributeName`, but only the RTF producer reads them. A complete implementation needs: the seven actions, changing the attributes over the selection or the typing attributes with undo, as the baseline actions do; the typesetter adding a run's `CPKernAttributeName` value to each character's advancement, and measuring with the same ligature setting it draws with; and `_CPLineFragment` setting CSS `letter-spacing` and `font-variant-ligatures` on each run's span to match.
- **The font panel needs polish.** Found during the Format menu review on 24 October: the panel works with the text view, but its appearance and behaviour need refinement. The specific problems are not yet recorded; list them here, compared with the native font panel, when the panel is reviewed. `CPFontPanel` is in `AppKit/CPTextView/CPFontPanel.j`.
### Ruler
- **Marker appearance and vertical alignment differ from TextEdit.** The marker images, and where markers sit across the ruler, are interim until Aristo3 supplies its own; adjust them to match TextEdit then. A tab stop dragged up off the ruler follows the pointer and is clipped by the ruler's edge, as in TextEdit. Dragged down off the ruler, it stays on its line and is drawn faded until release; TextEdit's behaviour in that direction has not been checked.
### Zoom and view scaling
View > Zoom Level, Zoom In, Zoom Out and Actual Size set the magnification of the document's scroll view, which scales its clip view's bounds. Zoom exercises CPView's scaling through the whole view hierarchy, so it is the test for scaling defects, below and above 100%. Found in the first test, under Aristo2:
- **The ruler ignores the magnification.** Its tab stop markers follow the scaled text, but its scale and labels stay at 100%, so markers and units disagree. In Cocoa the ruler scales its units with the scroll view's magnification.
- **Autoresizing uses frame sizes, not bounds sizes.** `-[CPView resizeWithOldSuperviewSize:]` resizes a subview by the change in its superview's frame size, but a subview lives in its superview's bounds coordinates. Cocoa uses the bounds size. Under magnification, an autoresized subview changes by the wrong amount: above 100%, the text became wider than the window after it was resized.
- **Below 100%, a few points are cut off at the left.** The first letter of some lines is missing.
- **Below 100%, a grey band shows below the text.** The text view is only as tall as its text, and the clip view's background shows below it. Cocoa draws the document's background there.
### nib2cib
- **nib2cib ignores the ruler settings.** The "Uses Ruler" setting in Interface Builder does not reach the cib. `CPTextView` and `CPRulerView` also need to archive their ruler settings.
- **The content view's resizing setting does not reach the cib.** Making the document window's content view resize with the window in `DocumentWindow.xib` produces a byte-identical `DocumentWindow.cib`. CPView omits the autoresizing mask from the archive only when it is `CPViewNotSizable` (`CPView.j:4016`), so the content view is archived as not sizable. Not yet determined whether `ibtool` or nib2cib drops the setting. The app still behaves correctly, because the window resizes its content view itself.
### Menus and key equivalents (needs discussion)
- **The key equivalent of a disabled menu item reaches the browser.** `-[CPMenu performKeyEquivalent:]` (`CPMenu.j:1059`) stops the browser's default action only when the matching item is enabled. For a disabled item it reports the key as handled, but the browser still acts on it: with File > Close disabled, Cmd-W closes the browser tab. Cocoa consumes the key equivalent of a disabled item with a beep. Stopping the browser's default for disabled items as well would match Cocoa for most keys, but not all: some browsers do not let a page block certain shortcuts, such as Cmd-W, Cmd-N and Cmd-T in Chrome, and Copy, Cut and Paste must keep reaching the browser for its clipboard events. This needs careful thought, and perhaps discussion, before any change.
### Platform
- **Key equivalents on platforms other than macOS.** Filed as an issue.
## Opportunities for improvement
- **Rich text through the asynchronous Clipboard API.** Edit > Copy, Cut and Paste chosen from the menu reach the system clipboard through `navigator.clipboard`, which carries plain text only. Rich text still moves between applications through the keyboard path, in the browser's clipboard events, and within the application through the internal pasteboard. Handling attributed text in general is an unbounded task, but a limited subset could be supported, for example through `text/html` in a `ClipboardItem`.
- **Justification is nominally functional, but its quality is limited.** `CPSimpleTypesetter` breaks lines greedily: it fills each line as far as it fits, as Cocoa does, and then spreads the spare width of each wrapped line evenly over that line's spaces. This naive algorithm does not and cannot produce the quality that modern typesetting expects. It decides each line alone, so word spacing varies widely from line to line, and loose lines are common. Quality needs paragraph-wide line breaking in the manner of Knuth-Plass, as Typst also uses, with language-aware hyphenation. Cappuccino measures and lays out text itself, so this belongs in the typesetter, as its only behaviour, with no setting for users or developers.
## Planned additions to the app
- Fonts through `CPFontManager` and `CPFontPanel`.
- RTF reading and writing.
- 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:`.
- Documents in separate browser windows with `CPPlatformWindow`.
- A Settings window. The first setting is the minimum size of document windows, now the constants `DocumentWindowMinimumWidth` and `DocumentWindowMinimumHeight` in `DocumentWindowController.j`.
## Tests done
- One window for each document, each loaded from its own cib.
- Insert Lorem Ipsum through the responder chain.
- Undo and redo over several levels, separate for each document.
- Text colour through `CPColorPanel`.
- Paragraph indents through the ruler markers.
- The "save changes" alert when a document closes.
- A minimum size for document windows, through the window delegate. The window stops at the minimum while the pointer keeps moving, as in macOS, and it can still be moved and resized afterwards.
- View > Show Toolbar and Hide Toolbar: the item's title follows the toolbar's visibility.
- The Window menu lists the open document windows, marks the main window with a check mark and brings a window to the front when chosen. Bring All to Front can be tested once documents open in separate browser windows.
- The About panel shows the display name from `CPBundleDisplayName`.
- Edit > Allow Undo turns undo on and off for the active document. With undo off, Undo and Redo stay disabled, and the check mark follows the document in front.
- The ruler: markers follow the paragraph at the selection; first line, head and right indents change the layout as shown; clicking adds a tab stop, and dragging moves or removes one; the Control-click menu changes a tab stop's type; the ruler's zero lines up with the start of the text, and markers at 0 are fully visible.
- Text stays inside the visible width, with Cocoa's 5-point line fragment padding.
- Tab characters: the Tab key inserts a tab in the text view, and left, centre, right and decimal tab stops align their columns.
- Format > Text > Copy Ruler and Paste Ruler apply one paragraph's indents and tab stops to others.
- Format > Font > Baseline: superscript, subscript, raised and lowered baselines lay out correctly, and Use Default restores the text, for an exact or a wider selection.
- Format > Text > Justify: wrapped lines fill the width between the indents, with the spare width spread over the spaces; the last line of a paragraph stays left aligned. Centred text is centred between the indents, and spaces at the end of a wrapped line hang outside the alignment.
- Format > Font > Copy Style and Paste Style: the style of the first character of the selection is applied to the whole target selection, which keeps its paragraph style.
- Format > List: bulleted and numbered lists, applied to one or several paragraphs and removed with None. Return starts the next item and keeps the item's text style; Return in an empty item ends the list. Tab at the start of an item nests it, and Shift-Tab returns it. Delete at the start of an item's text removes it from the list. The items are numbered again after each change.
- 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.
- A wide image fits the text width, and scales with the window without growing beyond its natural size. At the end of the text it is not clipped, and the scroll bars follow it.
- Format > Font > Bigger and Smaller (Command-+ and Command--) without a selection change the size of the text typed next, step by step, also in a blank document.
- Edit > Insert Table Example: the sample table appears between the surrounding sentences, with its header row and its bold and italic cells.
- Copy and paste within TextEditor with Command-C and Command-V, in one document and between documents: images, tables, including text edited in their cells, and lists are kept.
- Table cells can be edited, as a first pass.
- Pasting text with several images and a table: the table appears in place at once, and tables, images and text below a change move with their lines.
- A table wider than the text stays on its own line below the text before it when the window is narrowed, and is clipped at the right edge, without a horizontal scroll bar, as in Cocoa when text wraps to the window.
- View > Zoom Level, Zoom In, Zoom Out and Actual Size change the magnification below and above 100%, in the source app and in the build product; text, tables and images stay together at every level.
- Builds with both the legacy toolchain and capp-build.