@@ -13,11 +13,8 @@ public class Note: NSObject {
13
13
var content : NSMutableAttributedString = NSMutableAttributedString ( )
14
14
var creationDate : Date ? = Date ( )
15
15
var sharedStorage = Storage . sharedInstance ( )
16
- var tagNames = [ String] ( )
17
16
let dateFormatter = DateFormatter ( )
18
17
let undoManager = UndoManager ( )
19
-
20
- public var tags = [ String] ( )
21
18
public var originalExtension : String ?
22
19
23
20
public var name : String = " "
@@ -61,7 +58,7 @@ public class Note: NSObject {
61
58
self . name = name
62
59
63
60
self . container = cont ?? UserDefaultsManagement . fileContainer
64
- self . type = type ?? UserDefaultsManagement . fileFormat
61
+ self . type = type ?? . Markdown
65
62
66
63
let ext = container == . none
67
64
? self . type. getExtension ( for: container)
@@ -103,14 +100,10 @@ public class Note: NSObject {
103
100
}
104
101
}
105
102
106
- func load( tags : Bool = true ) {
103
+ func load( ) {
107
104
if let attributedString = getContent ( ) {
108
105
content = NSMutableAttributedString ( attributedString: attributedString)
109
106
}
110
-
111
- if !isTrash( ) {
112
- loadTags ( )
113
- }
114
107
}
115
108
116
109
func reload( ) -> Bool {
@@ -344,12 +337,6 @@ public class Note: NSObject {
344
337
}
345
338
346
339
preview = preview. replacingOccurrences ( of: " \n " , with: " " )
347
- if (
348
- UserDefaultsManagement . horizontalOrientation
349
- && content. hasPrefix ( " – " ) == false
350
- ) {
351
- preview = " – " + preview
352
- }
353
340
354
341
preview = preview. condenseWhitespace ( )
355
342
@@ -369,8 +356,7 @@ public class Note: NSObject {
369
356
}
370
357
371
358
@objc func getDateForLabel( ) -> String {
372
- guard !UserDefaultsManagement. hideDate else { return String ( ) }
373
-
359
+
374
360
guard let date = ( project. sortBy == . creationDate || UserDefaultsManagement . sort == . creationDate)
375
361
? creationDate
376
362
: modifiedLocalAt
@@ -571,9 +557,8 @@ public class Note: NSObject {
571
557
if self . isMarkdown ( ) {
572
558
self . content = self . content. unLoadCheckboxes ( )
573
559
574
- if UserDefaultsManagement . liveImagesPreview {
575
- self . content = self . content. unLoadImages ( note: self )
576
- }
560
+ self . content = self . content. unLoadImages ( note: self )
561
+
577
562
}
578
563
579
564
self . save ( attributedString: self . content, globalStorage: globalStorage)
@@ -815,192 +800,7 @@ public class Note: NSObject {
815
800
return name. localizedStandardContains ( terms) || content. string. localizedStandardContains ( terms)
816
801
}
817
802
818
- public func getCommaSeparatedTags( ) -> String {
819
- return tagNames. map { String ( $0) } . joined ( separator: " , " )
820
- }
821
-
822
- public func saveTags( _ string: [ String ] ) -> ( [ String ] , [ String ] ) {
823
- let newTagsClean = string
824
- var new = [ String] ( )
825
- var removed = [ String] ( )
826
-
827
- for tag in tagNames {
828
- if !newTagsClean. contains ( tag) {
829
- removed. append ( tag)
830
- }
831
- }
832
-
833
- for newTagClean in newTagsClean {
834
- if !tagNames. contains ( newTagClean) {
835
- new. append ( newTagClean)
836
- }
837
- }
838
-
839
- for n in new { sharedStorage. addTag ( n) }
840
-
841
- var removedFromStorage = [ String] ( )
842
- for r in removed {
843
- if sharedStorage. removeTag ( r) {
844
- removedFromStorage. append ( r)
845
- }
846
- }
847
-
848
- tagNames = newTagsClean
849
-
850
- #if os(OSX)
851
- try ? ( url as NSURL ) . setResourceValue ( newTagsClean, forKey: . tagNamesKey)
852
- #else
853
- let data = NSKeyedArchiver . archivedData ( withRootObject: NSMutableArray ( array: newTagsClean) )
854
- do {
855
- try self . url. setExtendedAttribute ( data: data, forName: " com.apple.metadata:_kMDItemUserTags " )
856
- } catch {
857
- print ( error)
858
- }
859
- #endif
860
-
861
- return ( removedFromStorage, removed)
862
- }
863
-
864
- public func removeAllTags( ) -> [ String ] {
865
- let result = saveTags ( [ ] )
866
-
867
- return result. 0
868
- }
869
-
870
- public func addTag( _ name: String ) {
871
- guard !tagNames. contains ( name) else { return }
872
-
873
- tagNames. append ( name)
874
-
875
- #if os(OSX)
876
- try ? ( url as NSURL ) . setResourceValue ( tagNames, forKey: . tagNamesKey)
877
- #else
878
- let data = NSKeyedArchiver . archivedData ( withRootObject: NSMutableArray ( array: self . tagNames) )
879
- do {
880
- try url. setExtendedAttribute ( data: data, forName: " com.apple.metadata:_kMDItemUserTags " )
881
- } catch {
882
- print ( error)
883
- }
884
- #endif
885
- }
886
-
887
- public func removeTag( _ name: String ) {
888
- guard tagNames. contains ( name) else { return }
889
-
890
- if let i = tagNames. firstIndex ( of: name) {
891
- tagNames. remove ( at: i)
892
- }
893
-
894
- if sharedStorage. noteList. first ( where: { $0. tagNames. contains ( name) } ) == nil {
895
- if let i = sharedStorage. tagNames. firstIndex ( of: name) {
896
- sharedStorage. tagNames. remove ( at: i)
897
- }
898
- }
899
-
900
- _ = saveTags ( tagNames)
901
- }
902
-
903
- #if os(OSX)
904
- public func loadTags( ) {
905
- let tags = try ? url. resourceValues ( forKeys: [ . tagNamesKey] )
906
- if let tagNames = tags? . tagNames {
907
- for tag in tagNames {
908
- if !self . tagNames. contains ( tag) {
909
- self . tagNames. append ( tag)
910
- }
911
-
912
- if !project. isTrash {
913
- sharedStorage. addTag ( tag)
914
- }
915
- }
916
- }
917
-
918
- if UserDefaultsManagement . inlineTags {
919
- _ = scanContentTags ( )
920
- }
921
- }
922
- #else
923
- public func loadTags( ) -> Bool {
924
- if let data = try ? url. extendedAttribute ( forName: " com.apple.metadata:_kMDItemUserTags " ) ,
925
- let tags = NSKeyedUnarchiver . unarchiveObject ( with: data) as? NSMutableArray {
926
- self . tagNames. removeAll ( )
927
- for tag in tags {
928
- if let tagName = tag as? String {
929
- self . tagNames. append ( tagName)
930
-
931
- if !project. isTrash {
932
- sharedStorage. addTag ( tagName)
933
- }
934
- }
935
- }
936
- }
937
-
938
- if UserDefaultsManagement . inlineTags {
939
- let changes = scanContentTags ( )
940
- let qty = changes. 0 . count + changes. 1 . count
941
-
942
- if ( qty > 0 ) {
943
- return true
944
- }
945
- }
946
-
947
- return false
948
- }
949
- #endif
950
-
951
- public func scanContentTags( ) -> ( [ String ] , [ String ] ) {
952
- var added = [ String] ( )
953
- var removed = [ String] ( )
954
-
955
- let inlineTags = content. string. matchingStrings ( regex: " (?: \\ A| \\ s) \\ #([^ \\ s \\ ! \\ # \\ : \\ [ \\ \" \\ ( \\ ; \\ . \\ ,]+) " )
956
-
957
- var tags = [ String] ( )
958
- for tag in inlineTags {
959
- guard let tag = tag. last, isValid ( tag: tag) else { continue }
960
-
961
- if tag. last == " / " {
962
- tags. append ( String ( tag. dropLast ( ) ) )
963
- } else {
964
- tags. append ( tag)
965
- }
966
- }
967
-
968
- if tags. contains ( " notags " ) {
969
- removed = self . tags
970
-
971
- self . tags. removeAll ( )
972
- return ( added, removed)
973
- }
974
-
975
- for noteTag in self . tags {
976
- if !tags. contains ( noteTag) {
977
- removed. append ( noteTag)
978
- }
979
- }
980
-
981
- for tag in tags {
982
- if !self . tags. contains ( tag) {
983
- added. append ( tag)
984
- }
985
- }
986
-
987
-
988
- self . tags = tags
989
-
990
- return ( added, removed)
991
- }
992
-
993
803
private var excludeRanges = [ NSRange] ( )
994
-
995
- private func isValid( tag: String ) -> Bool {
996
- let isHEX = ( tag. matchingStrings ( regex: " ^[A-Fa-f0-9]{6}$ " ) . last != nil )
997
-
998
- if isHEX || tag. isNumber {
999
- return false
1000
- }
1001
-
1002
- return true
1003
- }
1004
804
1005
805
public func getImageUrl( imageName: String ) -> URL ? {
1006
806
if imageName. starts ( with: " http:// " ) || imageName. starts ( with: " https:// " ) {
0 commit comments