From 7d2eb83a1b54b8149e4473b7b8b2ac839045d8f0 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Tue, 24 May 2016 10:56:19 +0200 Subject: [PATCH] fixed: undo support for fontpanel --- AppKit/CPTextView/CPTextView.j | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 093bbfcc5..a5d1fa650 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -1479,6 +1479,12 @@ var kDelegateRespondsTo_textShouldBeginEditing [_textStorage setFont:_font]; } + var currentAttributes = [_textStorage attributesAtIndex:range.location effectiveRange:nil] || _typingAttributes; + + [[[[self window] undoManager] prepareWithInvocationTarget:self] + setFont:[currentAttributes objectForKey:CPFontAttributeName] || _font + range:CPMakeRangeCopy(range)]; + [_textStorage addAttribute:CPFontAttributeName value:font range:CPMakeRangeCopy(range)]; [_layoutManager _validateLayoutAndGlyphs]; } @@ -1488,7 +1494,10 @@ var kDelegateRespondsTo_textShouldBeginEditing var currRange = CPMakeRange(_selectionRange.location, 0), oldFont, attributes, - scrollRange = CPMakeRange(CPMaxRange(_selectionRange), 0); + scrollRange = CPMakeRange(CPMaxRange(_selectionRange), 0), + undoManager = [[self window] undoManager]; + + [undoManager beginUndoGrouping]; if ([self isRichText]) { @@ -1518,6 +1527,8 @@ var kDelegateRespondsTo_textShouldBeginEditing scrollRange = CPMakeRange(length, 0); } + [undoManager endUndoGrouping]; + [_layoutManager _validateLayoutAndGlyphs]; [self sizeToFit]; [self setNeedsDisplay:YES];