From 69c37833a4476b5d640c3c68ff1fbe85f48158f9 Mon Sep 17 00:00:00 2001 From: Renan Greca Date: Fri, 17 Feb 2023 09:23:07 +0100 Subject: [PATCH] Make STTextView first responder when opening an empty file (CodeEdit #696) --- Sources/CodeEditTextView/STTextViewController.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/CodeEditTextView/STTextViewController.swift b/Sources/CodeEditTextView/STTextViewController.swift index 92a149952..a8a272824 100644 --- a/Sources/CodeEditTextView/STTextViewController.swift +++ b/Sources/CodeEditTextView/STTextViewController.swift @@ -321,6 +321,16 @@ public class STTextViewController: NSViewController, STTextViewDelegate, ThemeAt var (line, column) = position let string = textView.string if line > 0 { + if string.isEmpty { + // If the file is blank, automatically place the cursor in the first index. + let range = NSRange(string.startIndex..