diff options
| author | saturneric <[email protected]> | 2025-06-29 16:19:59 +0000 |
|---|---|---|
| committer | saturneric <[email protected]> | 2025-06-29 16:19:59 +0000 |
| commit | 5ca4a5455ab78f827d75ff51137f5f15f309ad9f (patch) | |
| tree | b657d6bc73a3a52231c460c863589272090a7c60 /src/ui/widgets | |
| parent | chore: update qt6 version to 6.8.3 in release workflow (diff) | |
| download | gpgfrontend-5ca4a5455ab78f827d75ff51137f5f15f309ad9f.tar.gz gpgfrontend-5ca4a5455ab78f827d75ff51137f5f15f309ad9f.zip | |
fix: simplify tab closing logic in TextEdit
- remove redundant focus setting after tab removal
- consolidate tab index selection logic
- ensure proper tab cleanup with deleteLater()
- remove commented-out empty tab handling code
Diffstat (limited to 'src/ui/widgets')
| -rw-r--r-- | src/ui/widgets/TextEdit.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index c70b1a83..f5941c8e 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -273,12 +273,7 @@ auto TextEdit::SlotSaveAsEML() -> bool { return saveEMLFile(QFileDialog::getSaveFileName(this, tr("Save file"), path)); } -void TextEdit::SlotCloseTab() { - slot_remove_tab(tab_widget_->currentIndex()); - if (tab_widget_->count() != 0) { - CurPageTextEdit()->GetTextPage()->setFocus(); - } -} +void TextEdit::SlotCloseTab() { slot_remove_tab(tab_widget_->currentIndex()); } void TextEdit::slot_remove_tab(int index) { // Do nothing, if no tab is opened @@ -296,19 +291,16 @@ void TextEdit::slot_remove_tab(int index) { auto* tab = tab_widget_->widget(index); tab_widget_->removeTab(index); - // close tab - if (tab != nullptr) tab->close(); + // if the tab was the last one, set the current index to the last tab + tab_widget_->setCurrentIndex(index >= last_index ? last_index + : last_index - 1); - if (index >= last_index) { - tab_widget_->setCurrentIndex(last_index); - } else { - tab_widget_->setCurrentIndex(last_index - 1); + // close and destroy tab + if (tab != nullptr) { + tab->close(); + tab->deleteLater(); } } - - if (tab_widget_->count() == 0) { - // enableAction(false); - } } /** |
