aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation/Base Components/MapTextEditor
diff options
context:
space:
mode:
authorRuben Beltran del Rio <jj@r.bdr.sh>2025-12-15 00:11:21 +0100
committerRuben Beltran del Rio <jj@r.bdr.sh>2025-12-15 00:19:39 +0100
commitfa681bfcf5cbfcc711fb0ab10f3fd74ac83bf18c (patch)
tree2dce2e95bab08f773246b450ac50227f8e8f57da /Map/Presentation/Base Components/MapTextEditor
parent0d5e6636405dbe332c33c0fb82c7ccccb20f96cb (diff)
Apply formatting rules
Diffstat (limited to 'Map/Presentation/Base Components/MapTextEditor')
-rw-r--r--Map/Presentation/Base Components/MapTextEditor/HoverView.swift4
-rw-r--r--Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift35
2 files changed, 21 insertions, 18 deletions
diff --git a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
index eeccec3..69ebfc0 100644
--- a/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
+++ b/Map/Presentation/Base Components/MapTextEditor/HoverView.swift
@@ -49,7 +49,7 @@ class HoverView: NSView {
box.topAnchor.constraint(equalTo: topAnchor),
box.leadingAnchor.constraint(equalTo: leadingAnchor),
box.trailingAnchor.constraint(equalTo: trailingAnchor),
- box.bottomAnchor.constraint(equalTo: bottomAnchor),
+ box.bottomAnchor.constraint(equalTo: bottomAnchor)
])
let label = NSTextField(labelWithString: message)
@@ -89,7 +89,7 @@ class HoverView: NSView {
button.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 8),
button.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -8),
- heightAnchor.constraint(equalToConstant: 32),
+ heightAnchor.constraint(equalToConstant: 32)
])
}
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)
}