From 07bb1ce28db717db6b589da56d681b0b48607c57 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Fri, 15 Jul 2016 22:49:33 +0200 Subject: [PATCH] =?UTF-8?q?Let=20OakDocumentEditor=20update=20document?= =?UTF-8?q?=E2=80=99s=20=E2=80=98selection=E2=80=99=20property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/OakTextView/src/OakTextView.mm | 16 +++++++++------- Frameworks/document/src/OakDocumentEditor.mm | 12 +++++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Frameworks/OakTextView/src/OakTextView.mm b/Frameworks/OakTextView/src/OakTextView.mm index d15c8f50..5efa0f1f 100644 --- a/Frameworks/OakTextView/src/OakTextView.mm +++ b/Frameworks/OakTextView/src/OakTextView.mm @@ -3207,20 +3207,22 @@ static char const* kOakMenuItemTitle = "OakMenuItemTitle"; - (void)updateSelection { - text::selection_t ranges, withoutCarry; + text::selection_t withoutCarry; for(auto const& range : documentView->ranges()) { text::pos_t from = documentView->convert(range.first.index); text::pos_t to = documentView->convert(range.last.index); - if(!range.freehanded && !range.columnar) - withoutCarry.push_back(text::range_t(from, to, range.columnar)); - from.offset = range.first.carry; - to.offset = range.last.carry; if(range.freehanded || range.columnar) + { + from.offset = range.first.carry; + to.offset = range.last.carry; withoutCarry.push_back(text::range_t(from, to, range.columnar)); - ranges.push_back(text::range_t(from, to, range.columnar)); + } + else + { + withoutCarry.push_back(text::range_t(from, to, range.columnar)); + } } - document->set_selection(ranges); isUpdatingSelection = YES; [self setSelectionString:[NSString stringWithCxxString:withoutCarry]]; diff --git a/Frameworks/document/src/OakDocumentEditor.mm b/Frameworks/document/src/OakDocumentEditor.mm index e4216670..32118289 100644 --- a/Frameworks/document/src/OakDocumentEditor.mm +++ b/Frameworks/document/src/OakDocumentEditor.mm @@ -69,7 +69,7 @@ static int32_t const NSWrapColumnWindowWidth = 0; - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:OakDocumentContentDidChangeNotification object:_document]; - _document.folded = to_ns(_layout->folded_as_string()); + [self documentWillSave:_document]; _layout.reset(); _editor.reset(); [_document close]; @@ -93,6 +93,16 @@ static int32_t const NSWrapColumnWindowWidth = 0; - (void)documentWillSave:(OakDocument*)aDocument { + text::selection_t ranges; + for(auto const& range : _editor->ranges()) + { + text::pos_t from = [self buffer].convert(range.first.index); + text::pos_t to = [self buffer].convert(range.last.index); + from.offset = range.first.carry; + to.offset = range.last.carry; + ranges.push_back(text::range_t(from, to, range.columnar)); + } + aDocument.selection = to_ns(ranges); aDocument.folded = to_ns(_layout->folded_as_string()); }