On macOS, fix tabGroup misuse

The property is marked as `Weak`, however we used strong `Id`.

Links: https://github.com/alacritty/alacritty/issues/7249
This commit is contained in:
Kirill Chibisov 2023-10-20 14:05:57 +04:00 committed by GitHub
parent 6a041f84ba
commit c346fb7e61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 10 deletions

View file

@ -23,7 +23,7 @@ extern_methods!(
pub fn selectPreviousTab(&self);
#[method_id(windows)]
pub fn tabbedWindows(&self) -> Id<NSArray<NSWindow>>;
pub fn tabbedWindows(&self) -> Option<Id<NSArray<NSWindow>>>;
#[method(setSelectedWindow:)]
pub fn setSelectedWindow(&self, window: &NSWindow);

View file

@ -218,7 +218,7 @@ extern_methods!(
pub(crate) fn tabbingIdentifier(&self) -> Id<NSString>;
#[method_id(tabGroup)]
pub(crate) fn tabGroup(&self) -> Id<NSWindowTabGroup>;
pub(crate) fn tabGroup(&self) -> Option<Id<NSWindowTabGroup>>;
#[method(isDocumentEdited)]
pub(crate) fn isDocumentEdited(&self) -> bool;

View file

@ -1525,27 +1525,35 @@ impl WindowExtMacOS for WinitWindow {
#[inline]
fn select_next_tab(&self) {
self.tabGroup().selectNextTab();
if let Some(group) = self.tabGroup() {
group.selectNextTab();
}
}
#[inline]
fn select_previous_tab(&self) {
self.tabGroup().selectPreviousTab();
if let Some(group) = self.tabGroup() {
group.selectPreviousTab()
}
}
#[inline]
fn select_tab_at_index(&self, index: usize) {
let tab_group = self.tabGroup();
let windows = tab_group.tabbedWindows();
if index < windows.len() {
tab_group.setSelectedWindow(&windows[index]);
if let Some(group) = self.tabGroup() {
if let Some(windows) = group.tabbedWindows() {
if index < windows.len() {
group.setSelectedWindow(&windows[index]);
}
}
}
}
#[inline]
fn num_tabs(&self) -> usize {
let tab_group = self.tabGroup();
tab_group.tabbedWindows().len()
self.tabGroup()
.and_then(|group| group.tabbedWindows())
.map(|windows| windows.len())
.unwrap_or(1)
}
fn is_document_edited(&self) -> bool {