diff options
| -rw-r--r-- | Map/Assets.xcassets/Colors/Border.colorset/Contents.json | 38 | ||||
| -rw-r--r-- | Map/Business/RenderableMap.swift | 12 | ||||
| -rw-r--r-- | Map/Business/WmapParser/Parser.swift | 2 | ||||
| -rw-r--r-- | Map/Business/WmapSyntaxHighlighter/SyntaxHighlighter.swift | 4 | ||||
| -rw-r--r-- | Map/Data/UserPreferencesJSON.swift | 0 | ||||
| -rw-r--r-- | Map/Presentation/Base Components/MapTextEditor/HoverView.swift | 40 | ||||
| -rw-r--r-- | Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift | 15 | ||||
| -rw-r--r-- | Map/Presentation/Theme/NSColor+theme.swift | 1 |
8 files changed, 90 insertions, 22 deletions
diff --git a/Map/Assets.xcassets/Colors/Border.colorset/Contents.json b/Map/Assets.xcassets/Colors/Border.colorset/Contents.json new file mode 100644 index 0000000..543819d --- /dev/null +++ b/Map/Assets.xcassets/Colors/Border.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xE3", + "green" : "0xE6", + "red" : "0xDA" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.488", + "green" : "0.500", + "red" : "0.434" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Map/Business/RenderableMap.swift b/Map/Business/RenderableMap.swift index c8ab776..d43b584 100644 --- a/Map/Business/RenderableMap.swift +++ b/Map/Business/RenderableMap.swift @@ -50,7 +50,7 @@ struct RenderableMap { shape: convertShape(vertex.shape) ) vertices.append(newVertex) - vertexMap[vertex.label] = newVertex + vertexMap[vertex.label.lowercased()] = newVertex vertexIdCounter += 1 case .note(let note): @@ -76,8 +76,8 @@ struct RenderableMap { for entity in entities { switch entity { case .edge(let edge): - if let fromVertex = vertexMap[edge.from], - let toVertex = vertexMap[edge.to] + if let fromVertex = vertexMap[edge.from.lowercased()], + let toVertex = vertexMap[edge.to.lowercased()] { edges.append( MapEdge( @@ -89,7 +89,7 @@ struct RenderableMap { } case .inertia(let inertia): - if let vertex = vertexMap[inertia.vertex] { + if let vertex = vertexMap[inertia.vertex.lowercased()] { inertias.append( Inertia( id: inertias.count, @@ -98,7 +98,7 @@ struct RenderableMap { } case .evolution(let evolution): - if let vertex = vertexMap[evolution.vertex] { + if let vertex = vertexMap[evolution.vertex.lowercased()] { let direction: CGFloat = evolution.isPositive ? 1.0 : -1.0 let destination = CGPoint( x: vertex.position.x + (direction * evolution.value), @@ -115,7 +115,7 @@ struct RenderableMap { case .group(let group): var groupVertices: [Vertex] = [] for vertexName in group.vertices { - if let vertex = vertexMap[vertexName] { + if let vertex = vertexMap[vertexName.lowercased()] { groupVertices.append(vertex) } } diff --git a/Map/Business/WmapParser/Parser.swift b/Map/Business/WmapParser/Parser.swift index 86c36ef..7c87150 100644 --- a/Map/Business/WmapParser/Parser.swift +++ b/Map/Business/WmapParser/Parser.swift @@ -46,7 +46,7 @@ extension Wmap { entities.append(entity) switch entity { case .vertex(let vertex): - vertexLabels.insert(vertex.label) + vertexLabels.insert(vertex.label.lowercased()) default: break } diff --git a/Map/Business/WmapSyntaxHighlighter/SyntaxHighlighter.swift b/Map/Business/WmapSyntaxHighlighter/SyntaxHighlighter.swift index d51a80f..8b31547 100644 --- a/Map/Business/WmapSyntaxHighlighter/SyntaxHighlighter.swift +++ b/Map/Business/WmapSyntaxHighlighter/SyntaxHighlighter.swift @@ -62,7 +62,9 @@ extension Wmap { ] if UserDefaults.standard.bool(forKey: "useSmartEditor") { - if element.type == .vertexLabel && !cachedVertexLabels.contains(element.value) { + if element.type == .vertexLabel + && !cachedVertexLabels.contains(element.value.lowercased()) + { if UserDefaults.standard.bool(forKey: "highlightMissingComponents") { attributes[.underlineStyle] = NSUnderlineStyle.thick.rawValue | NSUnderlineStyle.patternDot.rawValue diff --git a/Map/Data/UserPreferencesJSON.swift b/Map/Data/UserPreferencesJSON.swift new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Map/Data/UserPreferencesJSON.swift 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) } } diff --git a/Map/Presentation/Theme/NSColor+theme.swift b/Map/Presentation/Theme/NSColor+theme.swift index b2ff106..7e53717 100644 --- a/Map/Presentation/Theme/NSColor+theme.swift +++ b/Map/Presentation/Theme/NSColor+theme.swift @@ -33,6 +33,7 @@ extension NSColor { struct UI { static let background = NSColor(named: "Background") ?? .windowBackgroundColor + static let border = NSColor(named: "Border") ?? .separatorColor } } } |