mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Let OakDocumentEditor update document’s ‘selection’ property
This commit is contained in:
@@ -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]];
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user