aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation/Base Components
diff options
context:
space:
mode:
Diffstat (limited to 'Map/Presentation/Base Components')
-rw-r--r--Map/Presentation/Base Components/MapTextEditor/HoverView.swift40
-rw-r--r--Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift15
2 files changed, 41 insertions, 14 deletions
diff --git a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
index 4e42b99..bd6de42 100644
--- a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
+++ b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
@@ -37,21 +37,45 @@ class HoverView: NSView {
}
private func setupView(message: String, actionLabel: String) {
- wantsLayer = true
- layer?.backgroundColor = NSColor.controlBackgroundColor.cgColor
- layer?.borderColor = NSColor.separatorColor.cgColor
- layer?.borderWidth = 1
- layer?.cornerRadius = 8
+ let box = NSBox()
+ box.boxType = .custom
+ box.borderType = .lineBorder
+ box.cornerRadius = 8
+ box.borderColor = NSColor.separatorColor
+ box.fillColor = NSColor.controlBackgroundColor
+
+ addSubview(box)
+ box.translatesAutoresizingMaskIntoConstraints = false
+ NSLayoutConstraint.activate([
+ box.topAnchor.constraint(equalTo: topAnchor),
+ box.leadingAnchor.constraint(equalTo: leadingAnchor),
+ box.trailingAnchor.constraint(equalTo: trailingAnchor),
+ box.bottomAnchor.constraint(equalTo: bottomAnchor),
+ ])
let label = NSTextField(labelWithString: message)
label.font = NSFont.Theme.SmallControl.regular
label.textColor = NSColor.labelColor
+ label.backgroundColor = .clear
let button = NSButton(title: actionLabel, target: self, action: #selector(buttonClicked))
button.bezelStyle = .accessoryBarAction
button.font = NSFont.Theme.SmallControl.emphasized
button.controlSize = .mini
+ // Configure button for hover and active states
+ button.wantsLayer = true
+ button.layer?.cornerRadius = 4
+
+ // Set up tracking area for button hover effects
+ let buttonTrackingArea = NSTrackingArea(
+ rect: button.bounds,
+ options: [.mouseEnteredAndExited, .activeInKeyWindow, .inVisibleRect],
+ owner: button,
+ userInfo: nil
+ )
+ button.addTrackingArea(buttonTrackingArea)
+
addSubview(label)
addSubview(button)
@@ -59,14 +83,12 @@ class HoverView: NSView {
button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
- label.topAnchor.constraint(equalTo: topAnchor, constant: 8),
+ label.centerYAnchor.constraint(equalTo: centerYAnchor),
label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8),
- label.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8),
- button.topAnchor.constraint(equalTo: topAnchor, constant: 8),
+ button.firstBaselineAnchor.constraint(equalTo: label.firstBaselineAnchor),
button.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 8),
button.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8),
- button.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8),
heightAnchor.constraint(equalToConstant: 32),
])
diff --git a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift
index 6a1be83..c6ab483 100644
--- a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift
+++ b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift
@@ -85,6 +85,7 @@ class MapTextEditorController: NSViewController {
textView.string = self.text
textView.isEditable = true
textView.font = NSFont.Theme.Editor.regular
+ textView.textColor = NSColor.Theme.Syntax.text
textView.textContainerInset = NSSize(
width: Dimensions.Spacing.coziest, height: Dimensions.Spacing.coziest)
@@ -204,6 +205,7 @@ class MapTextEditorController: NSViewController {
private func handleMouseEvent(_ event: NSEvent) {
// Don't handle mouse events if we're already hovering over the hover view
if isHoveringHoverView {
+ NSCursor.arrow.set()
return
}
@@ -394,19 +396,22 @@ extension MapTextEditorController: NSTextStorageDelegate {
private func colorizeEditedText(textStorage: NSTextStorage, editedRange: NSRange) {
let string = textStorage.string as NSString
let lineRange = string.lineRange(for: editedRange)
-
- textStorage.removeAttribute(.foregroundColor, range: lineRange)
- textStorage.removeAttribute(.underlineStyle, range: lineRange)
- textStorage.removeAttribute(.underlineColor, range: lineRange)
- syntaxHighlighter.applySyntaxHighlighting(textStorage: textStorage, range: lineRange)
+ colorizeTextRange(textStorage: textStorage, range: lineRange)
}
private func colorizeText(textStorage: NSTextStorage) {
let range = NSMakeRange(0, textStorage.length)
+ colorizeTextRange(textStorage: textStorage, range: range)
+ }
+ private func colorizeTextRange(textStorage: NSTextStorage, range: NSRange) {
textStorage.removeAttribute(.foregroundColor, range: range)
textStorage.removeAttribute(.underlineStyle, range: range)
textStorage.removeAttribute(.underlineColor, range: range)
+
+ // Set default text color for the range
+ textStorage.addAttribute(.foregroundColor, value: NSColor.Theme.Syntax.text, range: range)
+
syntaxHighlighter.applySyntaxHighlighting(textStorage: textStorage, range: range)
}
}