Skip to content

Commit

Permalink
Added deleting notes if empty from popout window
Browse files Browse the repository at this point in the history
  • Loading branch information
charliescheer committed Oct 19, 2024
1 parent 658a9a5 commit d249b6f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
19 changes: 19 additions & 0 deletions Simplenote/NoteEditorViewController+Swift.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import CoreSpotlight
import SimplenoteFoundation
import SimplenoteInterlinks
import SimplenoteSearch
Expand Down Expand Up @@ -74,6 +75,24 @@ extension NoteEditorViewController {
clipView.contentInsets.top = SplitItemMetrics.editorContentTopInset
scrollView.scrollerInsets.top = SplitItemMetrics.editorScrollerTopInset
}

public func deleteCurrentNoteIfEmpty() {
guard let note,
note.content == nil || note.content?.isEmpty == true else {
return
}

delete(note: note)
}

@objc(deleteNote:)
func delete(note noteToDelete: Note) {

SPTracker.trackEditorNoteDeleted()
noteToDelete.deleted = true
noteActionsDelegate?.editorController(self, deletedNoteWithSimperiumKey: noteToDelete.simperiumKey)
CSSearchableIndex.default().deleteSearchableNote(noteToDelete)
}
}

// MARK: - Public
Expand Down
7 changes: 2 additions & 5 deletions Simplenote/NoteEditorViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,8 @@ - (IBAction)deleteAction:(id)sender
if (noteToDelete.deleted) {
continue;
}

[SPTracker trackEditorNoteDeleted];
noteToDelete.deleted = YES;
[self.noteActionsDelegate editorController:self deletedNoteWithSimperiumKey:noteToDelete.simperiumKey];
[[CSSearchableIndex defaultSearchableIndex] deleteSearchableNote:noteToDelete];

[self deleteNote:noteToDelete];
}

[self save];
Expand Down
5 changes: 5 additions & 0 deletions Simplenote/NoteWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ class NoteWindow: NSWindow {
editor.displayNote(note)
title = note.titlePreview
}

override func close() {
super.close()
editor.deleteCurrentNoteIfEmpty()
}
}

0 comments on commit d249b6f

Please sign in to comment.