Skip to content

Commit c7b72b1

Browse files
committed
- Fixes tags autocompletion
- Fixes tags highlighter - Allows ' in tags glushchenko#1157
1 parent a426f91 commit c7b72b1

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

FSNotes/Helpers/NotesTextProcessor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ public class NotesTextProcessor {
13251325
[^
13261326
\s # no whitespace
13271327
\# # no hashes
1328-
,?!"`';:\. # no punctuation
1328+
,?!"`;:\. # no punctuation
13291329
\\ # no backslash
13301330
(){}\[\] # no bracket pairs
13311331
]+

FSNotes/View/EditTextView.swift

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega
7373
let oneCharSize = ("a" as NSString).size(withAttributes: tagAttributes)
7474

7575
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))
76+
let tagBorderRect = NSRect(origin: CGPoint(x: tagRect.origin.x-oneCharSize.width*0.1, y: tagRect.origin.y), size: CGSize(width: tagRect.size.width+oneCharSize.width*0.3, height: height))
7777

7878
NSGraphicsContext.saveGraphicsState()
7979

@@ -96,12 +96,17 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega
9696
// path.transform(using: transform as AffineTransform)
9797
// path.stroke()
9898

99-
let resFont = NSFontManager.shared.convert(font, toSize: font.pointSize - 1)
99+
let resFont = NSFontManager.shared.convert(font, toSize: font.pointSize)
100100
let dict = NSMutableDictionary(dictionary: tagAttributes)
101101

102-
dict.addEntries(from: [NSAttributedString.Key.font: resFont, NSAttributedString.Key.foregroundColor: textColor])
102+
dict.addEntries(from: [
103+
NSAttributedString.Key.font: resFont,
104+
NSAttributedString.Key.foregroundColor: textColor
105+
])
103106
dict.removeObject(forKey: NSAttributedString.Key.link)
104-
(tag as NSString).draw(in: tagRect, withAttributes: (dict as! [NSAttributedString.Key : Any]))
107+
108+
let newRect = tagRect.offsetBy(dx: 0, dy: -1)
109+
(tag as NSString).draw(in: newRect, withAttributes: (dict as! [NSAttributedString.Key : Any]))
105110

106111
NSGraphicsContext.restoreGraphicsState()
107112
}
@@ -446,6 +451,31 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega
446451
return replacementRange
447452
}
448453

454+
if UserDefaultsManagement.inlineTags {
455+
var location = distance
456+
var length = 0
457+
458+
while true {
459+
if location - 1 < 0 {
460+
break
461+
}
462+
463+
let scanRange = NSRange(location: location - 1, length: 1)
464+
let char = textStorage?.attributedSubstring(from: scanRange).string
465+
466+
if char?.isWhitespace != nil {
467+
break
468+
}
469+
470+
if char == "#" {
471+
return NSRange(location: location, length: length)
472+
}
473+
474+
length += 1
475+
location = location - 1
476+
}
477+
}
478+
449479
return super.rangeForUserCompletion
450480
}
451481

0 commit comments

Comments
 (0)