From a88ef64c13499fffb92dceedb45d287ae6502193 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Sat, 11 Jun 2016 14:54:50 +0200 Subject: [PATCH] Move the undo grouping nest counter to document_view_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a problem introduced by 3812a8d1fd3a5c4cf964f15ceeeca529238bc35b where we could end up not closing an undo group because the OakTextView’s document was changed before destruction of the refresh_helper_t. --- Frameworks/OakTextView/src/OakTextView.mm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Frameworks/OakTextView/src/OakTextView.mm b/Frameworks/OakTextView/src/OakTextView.mm index 543d3644..557e6087 100644 --- a/Frameworks/OakTextView/src/OakTextView.mm +++ b/Frameworks/OakTextView/src/OakTextView.mm @@ -259,6 +259,8 @@ struct document_view_t : ng::buffer_api_t ~document_view_t () { + if(nest_count != 0) + end_undo_group(ranges()); _document->close(); } @@ -269,6 +271,7 @@ struct document_view_t : ng::buffer_api_t return res; } + size_t nest_count = 0; std::string invisibles_map; // ========== @@ -404,7 +407,6 @@ private: std::string fontName; CGFloat fontSize; std::shared_ptr documentView; - NSUInteger refreshNestCount; ng::callback_t* callback; BOOL hideCaret; @@ -479,7 +481,6 @@ private: @property (nonatomic) BOOL showDragCursor; @property (nonatomic) BOOL showColumnSelectionCursor; @property (nonatomic) OakChoiceMenu* choiceMenu; -@property (nonatomic) NSUInteger refreshNestCount; @property (nonatomic) LiveSearchView* liveSearchView; @property (nonatomic, copy) NSString* liveSearchString; @property (nonatomic) ng::ranges_t const& liveSearchRanges; @@ -533,7 +534,7 @@ struct refresh_helper_t { refresh_helper_t (OakTextView* self, document::document_ptr const& document, std::shared_ptr const& documentView) : _self(self), _document(document), _document_view(documentView) { - if(++_self.refreshNestCount == 1) + if(++documentView->nest_count == 1) { _revision = documentView->revision(); _selection = documentView->ranges(); @@ -556,9 +557,9 @@ struct refresh_helper_t ~refresh_helper_t () { - if(--_self.refreshNestCount == 0) + if(auto documentView = _document_view.lock()) { - if(auto documentView = _document_view.lock()) + if(--documentView->nest_count == 0) { documentView->end_undo_group(documentView->ranges()); if(_revision == documentView->revision()) @@ -685,7 +686,6 @@ static std::string shell_quote (std::vector paths) @implementation OakTextView @synthesize initiateDragTimer, dragScrollTimer, showColumnSelectionCursor, showDragCursor, choiceMenu; @synthesize markedRanges; -@synthesize refreshNestCount; @synthesize liveSearchString, liveSearchRanges; // =================================