Let OakDocumentEditor update document’s ‘selection’ property

This commit is contained in:
Allan Odgaard
2016-07-15 22:49:33 +02:00
parent 55c6f20b51
commit 07bb1ce28d
2 changed files with 20 additions and 8 deletions

View File

@@ -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]];

View File

@@ -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());
}