Skip to content

Commit 679ead2

Browse files
Alternate Cursor Location Description (#1582)
1 parent bc5aff9 commit 679ead2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

CodeEdit/Features/StatusBar/Views/StatusBarItems/StatusBarCursorLocationLabel.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import CodeEditSourceEditor
1111
struct StatusBarCursorLocationLabel: View {
1212
@Environment(\.controlActiveState)
1313
private var controlActive
14+
@Environment(\.modifierKeys)
15+
private var modifierKeys
1416

1517
@EnvironmentObject private var model: UtilityAreaViewModel
1618
@EnvironmentObject private var editorManager: EditorManager
@@ -38,11 +40,18 @@ struct StatusBarCursorLocationLabel: View {
3840
return ""
3941
}
4042

43+
// More than one selection, display the number of selections.
4144
if cursorPositions.count > 1 {
4245
return "\(cursorPositions.count) selected ranges"
4346
}
4447

48+
// If the selection is more than just a cursor, return the length.
4549
if cursorPositions[0].range.length > 0 {
50+
// When the option key is pressed display the character range.
51+
if modifierKeys.contains(.option) {
52+
return "Char: \(cursorPositions[0].range.location) Len: \(cursorPositions[0].range.length)"
53+
}
54+
4655
let lineCount = getLines(cursorPositions[0].range)
4756

4857
if lineCount > 1 {
@@ -52,6 +61,12 @@ struct StatusBarCursorLocationLabel: View {
5261
return "\(cursorPositions[0].range.length) characters"
5362
}
5463

64+
// When the option key is pressed display the character offset.
65+
if modifierKeys.contains(.option) {
66+
return "Char: \(cursorPositions[0].range.location) Len: 0"
67+
}
68+
69+
// When there's a single cursor, display the line and column.
5570
return "Line: \(cursorPositions[0].line) Col: \(cursorPositions[0].column)"
5671
}
5772

0 commit comments

Comments
 (0)