From a35cfeba439bc2280b6e0e3f98031e9cfc03a5b4 Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Fri, 2 Feb 2024 19:54:50 -0600 Subject: [PATCH 1/3] Alternate Cursor Locations --- .../StatusBarCursorLocationLabel.swift | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift b/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift index b7abfa1ff1..ca79d40964 100644 --- a/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift +++ b/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift @@ -9,8 +9,8 @@ import SwiftUI import CodeEditSourceEditor struct StatusBarCursorLocationLabel: View { - @Environment(\.controlActiveState) - private var controlActive + @Environment(\.controlActiveState) private var controlActive + @Environment(\.modifierKeys) private var modifierKeys @EnvironmentObject private var model: UtilityAreaViewModel @EnvironmentObject private var editorManager: EditorManager @@ -38,11 +38,18 @@ struct StatusBarCursorLocationLabel: View { return "" } + // More than one selection, display the number of selections. if cursorPositions.count > 1 { return "\(cursorPositions.count) selected ranges" } + // If the selection is more than just a cursor, return the length. if cursorPositions[0].range.length > 0 { + // When the option key is pressed display the character range. + if modifierKeys.contains(.option) { + return "Char: \(cursorPositions[0].range.location) Len: \(cursorPositions[0].range.length)" + } + let lineCount = getLines(cursorPositions[0].range) if lineCount > 1 { @@ -52,6 +59,12 @@ struct StatusBarCursorLocationLabel: View { return "\(cursorPositions[0].range.length) characters" } + // When the option key is pressed display the character offset. + if modifierKeys.contains(.option) { + return "Char: \(cursorPositions[0].range.location) Len: 0" + } + + // When there's a single cursor, display the line and column. return "Line: \(cursorPositions[0].line) Col: \(cursorPositions[0].column)" } @@ -77,6 +90,7 @@ struct StatusBarCursorLocationLabel: View { .fixedSize() .lineLimit(1) .onHover { isHovering($0) } + .onAppear { updateSource() } From 614eecd94684c9d0df003171416530ceda8bba22 Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Fri, 2 Feb 2024 19:57:00 -0600 Subject: [PATCH 2/3] linter! --- .../Views/StatusBarItems/StatusBarCursorLocationLabel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift b/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift index ca79d40964..6fe5094791 100644 --- a/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift +++ b/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift @@ -90,7 +90,7 @@ struct StatusBarCursorLocationLabel: View { .fixedSize() .lineLimit(1) .onHover { isHovering($0) } - + .onAppear { updateSource() } From 3ff43f4d54a00996aa14e039d5e1c533218c8512 Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Fri, 2 Feb 2024 20:34:12 -0600 Subject: [PATCH 3/3] Lint (part 2) --- .../StatusBarItems/StatusBarCursorLocationLabel.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift b/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift index 6fe5094791..af4ee347e7 100644 --- a/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift +++ b/CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift @@ -9,8 +9,10 @@ import SwiftUI import CodeEditSourceEditor struct StatusBarCursorLocationLabel: View { - @Environment(\.controlActiveState) private var controlActive - @Environment(\.modifierKeys) private var modifierKeys + @Environment(\.controlActiveState) + private var controlActive + @Environment(\.modifierKeys) + private var modifierKeys @EnvironmentObject private var model: UtilityAreaViewModel @EnvironmentObject private var editorManager: EditorManager @@ -90,7 +92,6 @@ struct StatusBarCursorLocationLabel: View { .fixedSize() .lineLimit(1) .onHover { isHovering($0) } - .onAppear { updateSource() }