diff --git a/FSNotes.xcodeproj/project.pbxproj b/FSNotes.xcodeproj/project.pbxproj index 7cdef8d78..69ed7f9a9 100644 --- a/FSNotes.xcodeproj/project.pbxproj +++ b/FSNotes.xcodeproj/project.pbxproj @@ -4559,7 +4559,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 611; + CURRENT_PROJECT_VERSION = 614; DEVELOPMENT_TEAM = 866P6MTE92; EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES; ENABLE_HARDENED_RUNTIME = YES; @@ -4599,7 +4599,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 611; + CURRENT_PROJECT_VERSION = 614; DEPLOYMENT_LOCATION = NO; DEVELOPMENT_TEAM = 866P6MTE92; EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES; diff --git a/FSNotes/Business/Note.swift b/FSNotes/Business/Note.swift index 336cef847..1c581a200 100644 --- a/FSNotes/Business/Note.swift +++ b/FSNotes/Business/Note.swift @@ -152,10 +152,6 @@ public class Note: NSObject { lastSelectedRange = value } - public func getLastSelectedRange() -> NSRange? { - return lastSelectedRange - } - public func hasTitle() -> Bool { return !firstLineAsTitle } @@ -290,7 +286,7 @@ public class Note: NSObject { } public func getFileModifiedDate() -> Date? { - let url = getURL() + let url = getContentFileURL() ?? url do { let attr = try FileManager.default.attributesOfItem(atPath: url.path) @@ -885,6 +881,8 @@ public class Note: NSObject { } public func save(attributed: NSAttributedString) { + modifiedLocalAt = Date() + Storage.shared().plainWriter.cancelAllOperations() Storage.shared().plainWriter.addOperation { if let copy = attributed.copy() as? NSAttributedString { @@ -981,10 +979,7 @@ public class Note: NSObject { guard Storage.shared().ciphertextWriter.operationCount == 1 else { return } self.writeEncrypted() } - } else { - modifiedLocalAt = Date() } - } catch { NSLog("Write error \(error)") return @@ -1119,10 +1114,9 @@ public class Note: NSObject { } func getFileAttributes() -> [FileAttributeKey: Any] { + let url = getContentFileURL() ?? url var attributes: [FileAttributeKey: Any] = [:] - modifiedLocalAt = Date() - do { attributes = try FileManager.default.attributesOfItem(atPath: url.path) } catch {} diff --git a/FSNotes/EditorViewController.swift b/FSNotes/EditorViewController.swift index 5ef269f14..934e79ba2 100644 --- a/FSNotes/EditorViewController.swift +++ b/FSNotes/EditorViewController.swift @@ -650,12 +650,12 @@ class EditorViewController: NSViewController, NSTextViewDelegate, WebFrameLoadDe } @IBAction func removeNoteEncryption(_ sender: Any) { - guard var notes = getSelectedNotes() else { return } + guard var notes = getSelectedNotes(), + let vc = ViewController.shared() else { return } notes = decryptUnlocked(notes: notes) guard notes.count > 0 else { return } - UserDataService.instance.fsUpdatesDisabled = true getMasterPassword() { password in for note in notes { if note.container == .encryptedTextPack { @@ -668,9 +668,8 @@ class EditorViewController: NSViewController, NSTextViewDelegate, WebFrameLoadDe } } - ViewController.shared()?.notesTableView.reloadRow(note: note) + vc.notesTableView.reloadRow(note: note) } - UserDataService.instance.fsUpdatesDisabled = false } } @@ -1378,8 +1377,6 @@ class EditorViewController: NSViewController, NSTextViewDelegate, WebFrameLoadDe vc.prevCommit = nil - vc.blockFSUpdates() - if editor.isEditable { editor.removeHighlight() editor.saveImages() diff --git a/FSNotes/Helpers/FileSystemEventManager.swift b/FSNotes/Helpers/FileSystemEventManager.swift index 05669d9da..e7b768cb8 100644 --- a/FSNotes/Helpers/FileSystemEventManager.swift +++ b/FSNotes/Helpers/FileSystemEventManager.swift @@ -24,10 +24,6 @@ class FileSystemEventManager { public func start() { watcher = FileWatcher(self.observedFolders) watcher?.callback = { event in - if UserDataService.instance.fsUpdatesDisabled { - return - } - guard let path = event.path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else { return } @@ -242,7 +238,6 @@ class FileSystemEventManager { private func reloadNote(note: Note) { guard note.container != .encryptedTextPack else { return } - let memoryContent = note.content.attributedSubstring(from: NSRange(0.. note.modifiedLocalAt { + + note.modifiedLocalAt = modificationDate note.cacheHash = nil note.content = NSMutableAttributedString(attributedString: fsContent) @@ -287,17 +282,16 @@ class FileSystemEventManager { } } } - } else if let modificationDate = note.getFileModifiedDate(), let creationDate = note.getFileCreationDate() { - if modificationDate != note.modifiedLocalAt || creationDate != note.creationDate { - note.modifiedLocalAt = modificationDate - note.creationDate = creationDate + } + + if creationDate != note.creationDate { + note.creationDate = creationDate - delegate.notesTableView.reloadDate(note: note) - delegate.reSort(note: note) + delegate.notesTableView.reloadDate(note: note) + delegate.reSort(note: note) - // Reload images if note moved (cache invalidated) - note.loadPreviewInfo() - } + // Reload images if note moved (cache invalidated) + note.loadPreviewInfo() } } diff --git a/FSNotes/Helpers/NotesTextProcessor.swift b/FSNotes/Helpers/NotesTextProcessor.swift index e670b9eab..5a1fc6b25 100644 --- a/FSNotes/Helpers/NotesTextProcessor.swift +++ b/FSNotes/Helpers/NotesTextProcessor.swift @@ -628,7 +628,8 @@ public class NotesTextProcessor { FSParser.yamlBlockRegex.matches(string, range: NSRange(location: 0, length: attributedString.length)) { (result) -> Void in guard let range = result?.range(at: 1) else { return } - + attributedString.addAttribute(.foregroundColor, value: NotesTextProcessor.fontColor, range: range) + if range.location == 0 { let listOpeningRegex = MarklightRegex(pattern: "([a-zA-Z_]+):", options: [.allowCommentsAndWhitespace]) listOpeningRegex.matches(string, range: range) { (result) -> Void in diff --git a/FSNotes/View/EditTextView.swift b/FSNotes/View/EditTextView.swift index cd5354b5f..614164045 100644 --- a/FSNotes/View/EditTextView.swift +++ b/FSNotes/View/EditTextView.swift @@ -26,7 +26,6 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega public var timer: Timer? public var tagsTimer: Timer? public var markdownView: MPreviewView? - public var restoreRange: NSRange? = nil public var isLastEdited: Bool = false @IBOutlet weak var previewMathJax: NSMenuItem! @@ -1056,12 +1055,6 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega if UserDefaultsManagement.appearanceType == AppearanceType.Custom { backgroundColor = UserDefaultsManagement.bgColor } - - if let restoreRange = self.restoreRange { - NSApp.mainWindow?.makeFirstResponder(self) - setSelectedRange(restoreRange) - self.restoreRange = nil - } } private func loadMarkdownWebView(note: Note, force: Bool) { @@ -1583,6 +1576,7 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega let string = storage.attributedSubstring(from: NSRange(0.. Void = {}) { var sidebarItem: SidebarItem? = sidebarItem @@ -1992,14 +1979,6 @@ class ViewController: EditorViewController, note.previewState = state == "preview" - if let position = Int(position), - position > -1, - let textStorage = editor.textStorage, - textStorage.length >= position { - - editor.restoreRange = NSRange(location: position, length: 0) - } - notesTableView.selectRowAndSidebarItem(note: note) } diff --git a/FSNotesCore/Core macOS/Helpers/UserDataService.swift b/FSNotesCore/Core macOS/Helpers/UserDataService.swift index 794f51041..d0a8e1e9d 100644 --- a/FSNotesCore/Core macOS/Helpers/UserDataService.swift +++ b/FSNotesCore/Core macOS/Helpers/UserDataService.swift @@ -13,7 +13,6 @@ public class UserDataService { fileprivate var _searchTrigger = false fileprivate var _lastRenamed: URL? - fileprivate var _fsUpdates = false fileprivate var _isNotesTableEscape = false fileprivate var _isDark = false @@ -41,15 +40,6 @@ public class UserDataService { } } - public var fsUpdatesDisabled: Bool { - get { - return _fsUpdates - } - set { - _fsUpdates = newValue - } - } - public var isNotesTableEscape: Bool { get { return _isNotesTableEscape diff --git a/FSNotesCore/Shared/Extensions/String+.swift b/FSNotesCore/Shared/Extensions/String+.swift index 34371aa68..45adffced 100644 --- a/FSNotesCore/Shared/Extensions/String+.swift +++ b/FSNotesCore/Shared/Extensions/String+.swift @@ -135,7 +135,11 @@ public extension String { } func trunc(length: Int) -> String { - return (self.count > length) ? String(self.prefix(length)) : self + let result = self + .replacingOccurrences(of: ":", with: "-") + .replacingOccurrences(of: "/", with: ":") + + return (result.count > length) ? String(result.prefix(length)) : result } func startsWith(string: String) -> Bool { diff --git a/FSNotesCoreTests/macOSTests/Helpers/UserDataServiceTests.swift b/FSNotesCoreTests/macOSTests/Helpers/UserDataServiceTests.swift index f44142213..8c9831a3c 100644 --- a/FSNotesCoreTests/macOSTests/Helpers/UserDataServiceTests.swift +++ b/FSNotesCoreTests/macOSTests/Helpers/UserDataServiceTests.swift @@ -31,34 +31,4 @@ class UserDataServiceTests: XCTestCase { service.searchTrigger = false XCTAssertFalse(service.searchTrigger) } - - func testLastRenamed() { - XCTAssert(service.lastRenamed == nil) - - service.lastRenamed = URL(string: "file:///tmp/foo") - XCTAssertEqual(service.lastRenamed?.absoluteString, URL(string: "file:///tmp/foo")?.absoluteString) - - service.lastRenamed = nil - XCTAssertNil(service.lastRenamed) - } - - func testFsUpdatesDisabled() { - XCTAssertFalse(service.fsUpdatesDisabled) - - service.fsUpdatesDisabled = true - XCTAssertTrue(service.fsUpdatesDisabled) - - service.fsUpdatesDisabled = false - XCTAssertFalse(service.fsUpdatesDisabled) - } - - func testSkipListReload() { - XCTAssertFalse(service.skipListReload) - - service.skipListReload = true - XCTAssertTrue(service.skipListReload) - - service.skipListReload = false - XCTAssertFalse(service.skipListReload) - } }