Skip to content

Commit 43352bb

Browse files
committed
- Fixes search highlights removing in code blocks and tags
- Fixes missed undelete undo - Fixes images loading in first print - Adds toggle for cmd+L - Fixes russian localization
1 parent a32010a commit 43352bb

File tree

9 files changed

+56
-60
lines changed

9 files changed

+56
-60
lines changed

FSNotes.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4370,7 +4370,7 @@
43704370
CODE_SIGN_IDENTITY = "Apple Development";
43714371
CODE_SIGN_STYLE = Automatic;
43724372
COMBINE_HIDPI_IMAGES = YES;
4373-
CURRENT_PROJECT_VERSION = 482;
4373+
CURRENT_PROJECT_VERSION = 486;
43744374
DEVELOPMENT_TEAM = 866P6MTE92;
43754375
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
43764376
ENABLE_HARDENED_RUNTIME = YES;
@@ -4383,7 +4383,7 @@
43834383
INFOPLIST_FILE = "FSNotes Info (Notarized).plist";
43844384
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
43854385
MACOSX_DEPLOYMENT_TARGET = 10.13;
4386-
MARKETING_VERSION = 5beta5;
4386+
MARKETING_VERSION = 5beta6;
43874387
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
43884388
PRODUCT_NAME = FSNotes;
43894389
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -4405,7 +4405,7 @@
44054405
CODE_SIGN_IDENTITY = "Apple Development";
44064406
CODE_SIGN_STYLE = Automatic;
44074407
COMBINE_HIDPI_IMAGES = YES;
4408-
CURRENT_PROJECT_VERSION = 482;
4408+
CURRENT_PROJECT_VERSION = 486;
44094409
DEPLOYMENT_LOCATION = NO;
44104410
DEVELOPMENT_TEAM = 866P6MTE92;
44114411
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
@@ -4419,7 +4419,7 @@
44194419
INFOPLIST_FILE = "FSNotes Info (Notarized).plist";
44204420
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
44214421
MACOSX_DEPLOYMENT_TARGET = 10.13;
4422-
MARKETING_VERSION = 5beta5;
4422+
MARKETING_VERSION = 5beta6;
44234423
ONLY_ACTIVE_ARCH = YES;
44244424
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
44254425
PRODUCT_NAME = FSNotes;
@@ -4733,7 +4733,7 @@
47334733
CODE_SIGN_IDENTITY = "Developer ID Application";
47344734
CODE_SIGN_STYLE = Manual;
47354735
COMBINE_HIDPI_IMAGES = YES;
4736-
CURRENT_PROJECT_VERSION = 482;
4736+
CURRENT_PROJECT_VERSION = 486;
47374737
DEVELOPMENT_TEAM = 866P6MTE92;
47384738
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
47394739
ENABLE_NS_ASSERTIONS = NO;
@@ -4745,7 +4745,7 @@
47454745
INFOPLIST_FILE = FSNotes/Info.plist;
47464746
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
47474747
MACOSX_DEPLOYMENT_TARGET = 10.13;
4748-
MARKETING_VERSION = 5beta5;
4748+
MARKETING_VERSION = 5beta6;
47494749
OTHER_SWIFT_FLAGS = "$(inherited)";
47504750
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
47514751
PRODUCT_NAME = FSNotes;
@@ -4767,7 +4767,7 @@
47674767
CODE_SIGN_IDENTITY = "Apple Development";
47684768
CODE_SIGN_STYLE = Automatic;
47694769
COMBINE_HIDPI_IMAGES = YES;
4770-
CURRENT_PROJECT_VERSION = 482;
4770+
CURRENT_PROJECT_VERSION = 486;
47714771
DEPLOYMENT_LOCATION = NO;
47724772
DEVELOPMENT_TEAM = 866P6MTE92;
47734773
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
@@ -4780,7 +4780,7 @@
47804780
INFOPLIST_FILE = FSNotes/Info.plist;
47814781
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
47824782
MACOSX_DEPLOYMENT_TARGET = 10.13;
4783-
MARKETING_VERSION = 5beta5;
4783+
MARKETING_VERSION = 5beta6;
47844784
ONLY_ACTIVE_ARCH = YES;
47854785
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
47864786
PRODUCT_NAME = FSNotes;

FSNotes/Helpers/UserDefaultsManagement.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ public class UserDefaultsManagement {
207207
}
208208

209209
if let fontName = self.fontName, let font = Font(name: fontName, size: CGFloat(self.fontSize)) {
210-
print(fontName)
211210
return font
212211
}
213212

FSNotes/MPreviewView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
453453
codeStyle = try! String.init(contentsOfFile: hgPath)
454454
}
455455

456-
let familyName = UserDefaultsManagement.noteFont.familyName
456+
var familyName = UserDefaultsManagement.noteFont.familyName
457457

458458
#if os(iOS)
459459
if !UserDefaultsManagement.dynamicTypeFont {
@@ -476,7 +476,11 @@ class MPreviewView: WKWebView, WKUIDelegate, WKNavigationDelegate {
476476
width = 0
477477
}
478478

479-
return "body {font: \(UserDefaultsManagement.fontSize)px '\(familyName)', '-apple-system'; margin: 0 \(width + 5)px; } code, pre {font: \(UserDefaultsManagement.codeFontSize)px '\(UserDefaultsManagement.codeFontName)', Courier, monospace, 'Liberation Mono', Menlo; line-height: 30px;} img {display: block; margin: 0 auto;} \(codeStyle) \(css)"
479+
if familyName!.starts(with: ".") {
480+
familyName = "Helvetica Neue";
481+
}
482+
483+
return "body {font: \(UserDefaultsManagement.fontSize)px '\(familyName!)', '-apple-system'; margin: 0 \(width + 5)px; } code, pre {font: \(UserDefaultsManagement.codeFontSize)px '\(UserDefaultsManagement.codeFontName)', Courier, monospace, 'Liberation Mono', Menlo; line-height: 30px;} img {display: block; margin: 0 auto;} \(codeStyle) \(css)"
480484
#endif
481485
}
482486
}

FSNotes/MainWindowController.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,4 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
9696
}
9797
}
9898
}
99-
100-
func windowDidUpdate(_ notification: Notification) {
101-
ViewController.shared()?.editArea.invalidateLayout()
102-
}
10399
}

FSNotes/View/EditTextView.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega
7171

7272
let tagAttributes = attributedString().attributes(at: range.location, effectiveRange: nil)
7373
let oneCharSize = ("a" as NSString).size(withAttributes: tagAttributes)
74-
let tagBorderRect = NSRect(origin: CGPoint(x: tagRect.origin.x-oneCharSize.width*0.25, y: tagRect.origin.y+1), size: CGSize(width: tagRect.size.width+oneCharSize.width*0.33, height: oneCharSize.height))
74+
75+
let height = oneCharSize.height > tagRect.size.height ? tagRect.size.height : oneCharSize.height
76+
let tagBorderRect = NSRect(origin: CGPoint(x: tagRect.origin.x-oneCharSize.width*0.25, y: tagRect.origin.y), size: CGSize(width: tagRect.size.width+oneCharSize.width*0.33, height: height))
7577

7678
NSGraphicsContext.saveGraphicsState()
7779

@@ -95,9 +97,10 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega
9597

9698
let resFont = NSFontManager.shared.convert(font, toSize: font.pointSize - 1)
9799
let dict = NSMutableDictionary(dictionary: tagAttributes)
100+
98101
dict.addEntries(from: [NSAttributedString.Key.font: resFont, NSAttributedString.Key.foregroundColor: textColor])
99102
dict.removeObject(forKey: NSAttributedString.Key.link)
100-
(tag as NSString).draw(in: tagRect, withAttributes: dict as! [NSAttributedString.Key : Any])
103+
(tag as NSString).draw(in: tagRect, withAttributes: (dict as! [NSAttributedString.Key : Any]))
101104

102105
NSGraphicsContext.restoreGraphicsState()
103106
}
@@ -746,7 +749,7 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega
746749
invalidateLayout()
747750
}
748751

749-
undoManager?.removeAllActions()
752+
undoManager?.removeAllActions(withTarget: self)
750753
registerHandoff(note: note)
751754

752755
// resets timer if editor refilled
@@ -1547,6 +1550,11 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega
15471550
func getSearchText() -> String {
15481551
guard let search = ViewController.shared()?.search else { return String() }
15491552

1553+
let pb = NSPasteboard(name: NSPasteboard.Name.find)
1554+
if let string = pb.string(forType: NSPasteboard.PasteboardType.string) {
1555+
return string
1556+
}
1557+
15501558
if let editor = search.currentEditor(), editor.selectedRange.length > 0 {
15511559
return (search.stringValue as NSString).substring(with: NSRange(0..<editor.selectedRange.location))
15521560
}

FSNotes/ViewController+Print.swift

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,7 @@ import WebKit
1010

1111
extension ViewController {
1212

13-
@objc func allImagesLoaded(_ message: String) {}
14-
15-
override class func isSelectorExcluded(fromWebScript sel: Selector) -> Bool {
16-
if sel == #selector(ViewController.allImagesLoaded(_:)) {
17-
return false
18-
}
19-
return true
20-
}
21-
22-
override class func webScriptName(for sel: Selector) -> String? {
23-
if sel == #selector(ViewController.allImagesLoaded(_:)) {
24-
return "allImagesLoaded";
25-
}
26-
return nil
27-
}
28-
29-
public func printMarkdownPreview(webView: WebView?) {
13+
public func printMarkdownPreview() {
3014
guard let note = EditTextView.note else { return }
3115

3216
let classBundle = Bundle(for: MPreviewView.self)
@@ -49,13 +33,13 @@ extension ViewController {
4933
try? FileManager.default.removeItem(at: printDir)
5034

5135
copyInitialFiles(printDir: printDir)
52-
copyImages(note: note, dst: printDir)
36+
htmlString = assignBase64Images(note: note, html: htmlString)
5337

54-
webView?.frameLoadDelegate = self
55-
webView?.mainFrame.loadHTMLString(htmlString, baseURL: printDir)
38+
self.printWebView.frameLoadDelegate = self
39+
self.printWebView.mainFrame.loadHTMLString(htmlString, baseURL: printDir)
5640

5741
if UserDataService.instance.isDark {
58-
webView?.stringByEvaluatingJavaScript(from: "switchToDarkMode();")
42+
self.printWebView.stringByEvaluatingJavaScript(from: "switchToDarkMode();")
5943
}
6044
}
6145

@@ -91,30 +75,32 @@ extension ViewController {
9175
}
9276
}
9377

94-
public func copyImages(note: Note, dst: URL) {
78+
public func assignBase64Images(note: Note, html: String) -> String {
79+
var html = html
80+
9581
NotesTextProcessor.imageInlineRegex.regularExpression.enumerateMatches(in: note.content.string, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(0..<note.content.length), using:
9682
{(result, flags, stop) -> Void in
9783

9884
guard let range = result?.range(at: 3), note.content.length >= range.location else { return }
9985

100-
guard let imagePath = note.content.attributedSubstring(from: range).string.removingPercentEncoding else { return }
86+
let path = note.content.attributedSubstring(from: range).string
87+
guard let imagePath = path.removingPercentEncoding else { return }
10188

10289
if let url = note.getImageUrl(imageName: imagePath) {
10390
if url.isRemote() {
10491
return
10592
}
10693

10794
if FileManager.default.fileExists(atPath: url.path), url.isImage {
108-
let result = dst.appendingPathComponent(imagePath)
109-
let dstDir = result.deletingLastPathComponent()
110-
111-
try? FileManager.default.createDirectory(at:dstDir, withIntermediateDirectories: true, attributes: nil)
112-
113-
try? FileManager.default.copyItem(at: url, to: result)
95+
if let image = try? Data(contentsOf: url) {
96+
let base64 = image.base64EncodedString()
97+
html = html.replacingOccurrences(of: path, with: "data:image;base64," + base64)
98+
}
11499
}
115100
}
116101
})
117102

103+
return html
118104
}
119105

120106
func webView(_ sender: WebView!, didFinishLoadFor frame: WebFrame!) {

FSNotes/ViewController.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ViewController: NSViewController,
3333
var previewResizeTimer = Timer()
3434
var rowUpdaterTimer = Timer()
3535
let searchQueue = OperationQueue()
36-
var printWebView: WebView?
36+
var printWebView = WebView()
3737
var tagsScannerQueue = [Note]()
3838

3939
/* Git */
@@ -398,8 +398,7 @@ class ViewController: NSViewController,
398398
cell.searchButtonCell?.action = #selector(openRecentPopup(_:))
399399
}
400400

401-
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(onWakeNote(note:)),
402-
name: NSWorkspace.didWakeNotification, object: nil)
401+
DistributedNotificationCenter.default().addObserver(self, selector: #selector(onWakeNote(note:)), name: Notification.Name("com.apple.screenIsUnlocked"), object: nil)
403402

404403
NSWorkspace.shared.notificationCenter.addObserver(
405404
self, selector: #selector(onSleepNote(note:)),
@@ -547,11 +546,15 @@ class ViewController: NSViewController,
547546
if let view = NSApplication.shared.mainWindow?.firstResponder as? NSTextView, let textField = view.superview?.superview {
548547

549548
if textField.isKind(of: SearchTextField.self) {
550-
vc.search.searchesMenu = vc.search.generateRecentMenu()
551-
let general = vc.search.searchesMenu!.item(at: 0)
552-
vc.search.searchesMenu!.popUp(positioning: general, at: NSPoint(x: 5, y: vc.search.frame.height + 7), in: vc.search)
549+
if vc.search.searchesMenu != nil {
550+
vc.search.searchesMenu = nil
551+
} else {
552+
vc.search.searchesMenu = vc.search.generateRecentMenu()
553+
let general = vc.search.searchesMenu!.item(at: 0)
554+
vc.search.searchesMenu!.popUp(positioning: general, at: NSPoint(x: 5, y: vc.search.frame.height + 7), in: vc.search)
553555

554-
return
556+
return
557+
}
555558
}
556559
}
557560

@@ -899,7 +902,7 @@ class ViewController: NSViewController,
899902
}
900903

901904
@objc func onWakeNote(note: NSNotification) {
902-
editArea.invalidateLayout()
905+
refillEditArea()
903906
}
904907

905908
func cancelTextSearch() {
@@ -1373,8 +1376,7 @@ class ViewController: NSViewController,
13731376

13741377
@IBAction func printNotes(_ sender: NSMenuItem) {
13751378
if let note = EditTextView.note, note.isMarkdown() {
1376-
self.printWebView = WebView()
1377-
printMarkdownPreview(webView: self.printWebView)
1379+
printMarkdownPreview()
13781380
return
13791381
}
13801382

FSNotes/ru.lproj/Main.strings

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"63m-us-3j9.title" = "Шрифт кода:";
8787

8888
/* Class = "NSButtonCell"; title = "Hide images preview"; ObjectID = "6AI-tL-TDI"; */
89-
"6AI-tL-TDI.title" = "Спрять превью изображений";
89+
"6AI-tL-TDI.title" = "Спрятать превью изображений";
9090

9191
/* Class = "NSMenuItem"; title = "Redo"; ObjectID = "6dh-zS-Vam"; */
9292
"6dh-zS-Vam.title" = "Вперёд";
@@ -248,7 +248,7 @@
248248
"e0G-y0-N0C.title" = "Todo";
249249

250250
/* Class = "NSButtonCell"; title = "Hide date"; ObjectID = "e15-ps-th1"; */
251-
"e15-ps-th1.title" = "Спрять дату";
251+
"e15-ps-th1.title" = "Спрятать дату";
252252

253253
/* Class = "NSMenuItem"; title = "Duplicate"; ObjectID = "E6I-n5-dsi"; */
254254
"E6I-n5-dsi.title" = "Создать копию";

Resources/DownView.bundle/css/markdown-preview.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ img {
257257
width: auto !important;
258258
width: 100%;
259259
max-width: 678px;
260-
height: auto;
260+
height: auto !important;
261+
max-height: 900px;
261262
}
262263
canvas {
263264
border-radius: 3px;

0 commit comments

Comments
 (0)