diff options
Diffstat (limited to 'Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift')
| -rw-r--r-- | Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift index 99fa684..2850c57 100644 --- a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift +++ b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift @@ -13,12 +13,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see https://map.tranquil.systems. import Cocoa -import SwiftUI -import WmapParser import SwiftTreeSitter import SwiftTreeSitterLayer +import SwiftUI import TreeSitterWmap - +import WmapParser class MapTextEditorController: NSViewController { @@ -63,7 +62,7 @@ class MapTextEditorController: NSViewController { self.highlightRanges = highlightRanges self.selectedRange = selectedRange super.init(nibName: nil, bundle: nil) - + if let wmapConfiguration = try? LanguageConfiguration(tree_sitter_wmap(), name: "wmap") { let languageConfiguration = LanguageLayer.Configuration(languageProvider: { name in switch name { @@ -71,7 +70,8 @@ class MapTextEditorController: NSViewController { default: return nil } }) - self.rootLayer = try? LanguageLayer(languageConfig: wmapConfiguration, configuration: languageConfiguration) + self.rootLayer = try? LanguageLayer( + languageConfig: wmapConfiguration, configuration: languageConfiguration) } } @@ -83,7 +83,7 @@ class MapTextEditorController: NSViewController { override func loadView() { let scrollView = NSTextView.scrollableTextView() let textView = scrollView.documentView as! NSTextView - + scrollView.translatesAutoresizingMaskIntoConstraints = false textView.backgroundColor = .Theme.UI.background @@ -105,14 +105,16 @@ class MapTextEditorController: NSViewController { textView.textContainer?.containerSize = NSSize( width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) // Allow text view to grow horizontally - textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) + textView.maxSize = NSSize( + width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) // Enable horizontal scrollbar when soft wrap is disabled scrollView.hasHorizontalScroller = true scrollView.horizontalScrollElasticity = .none } else { textView.textContainer?.widthTracksTextView = true // Reset max size for wrapping - textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) + textView.maxSize = NSSize( + width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) // Hide horizontal scrollbar when soft wrap is enabled scrollView.hasHorizontalScroller = false scrollView.horizontalScrollElasticity = .automatic @@ -291,7 +293,7 @@ class MapTextEditorController: NSViewController { NSLayoutConstraint.activate([ hoverView.leadingAnchor.constraint(equalTo: textView.leadingAnchor, constant: hoverX), - hoverView.topAnchor.constraint(equalTo: textView.topAnchor, constant: hoverY), + hoverView.topAnchor.constraint(equalTo: textView.topAnchor, constant: hoverY) ]) self.hoverView = hoverView @@ -356,7 +358,8 @@ class MapTextEditorController: NSViewController { } private func applyTreeSitterHighlighting(textStorage: NSTextStorage, range: NSRange) { - guard let highlights = try? rootLayer?.highlights(in: range, provider: text.predicateTextProvider) + guard + let highlights = try? rootLayer?.highlights(in: range, provider: text.predicateTextProvider) else { return } for highlight in highlights { @@ -367,11 +370,12 @@ class MapTextEditorController: NSViewController { // Check for missing components if UserDefaults.standard.bool(forKey: "useSmartEditor"), - let parsedMap, - highlight.name == "variable.component_label" { + let parsedMap, + highlight.name == "variable.component_label" { // Extract the component label text from the range - let componentText = (textStorage.string as NSString).substring(with: highlight.range).trimmingCharacters(in: .whitespacesAndNewlines) + let componentText = (textStorage.string as NSString).substring(with: highlight.range) + .trimmingCharacters(in: .whitespacesAndNewlines) // Check if this component exists in the parsed map let componentExists = parsedMap.components.contains(where: { @@ -408,8 +412,7 @@ extension MapTextEditorController: NSTextViewDelegate { } } - func textView(_ view: NSTextView, shouldChangeTextIn: NSRange, replacementString: String?) -> Bool - { + func textView(_ view: NSTextView, shouldChangeTextIn: NSRange, replacementString: String?) -> Bool { let range = Range(shouldChangeTextIn, in: view.string) let target = view.string[range!] @@ -458,7 +461,7 @@ extension MapTextEditorController: NSTextStorageDelegate { } private func colorizeText(textStorage: NSTextStorage) { - let range = NSMakeRange(0, textStorage.length) + let range = NSRange(location: 0, length: textStorage.length) colorizeTextRange(textStorage: textStorage, range: range) } |