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

@ -39,6 +39,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- Make `WindowBuilder` `Send + Sync`. - Make `WindowBuilder` `Send + Sync`.
- On macOS, fix assertion when pressing `Globe` key. - On macOS, fix assertion when pressing `Globe` key.
- On Windows, updated `WM_MOUSEMOVE` to detect when cursor Enter or Leave window client area while captured and send the corresponding events. (#3153) - On Windows, updated `WM_MOUSEMOVE` to detect when cursor Enter or Leave window client area while captured and send the corresponding events. (#3153)
- On macOS, fix crash when accessing tabbing APIs.
# 0.29.1-beta # 0.29.1-beta

View file

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

View file

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

View file

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