Swift can't read the textDocumentProxy.documentContextBeforeInput after entering a newline

I am typing string text on textDocumentProxy in a custom keyboard app. The input text includes newlines and punctuation letters, but when I try to edit the textDocumentProxy field, the textDocumentProxy.documentContextBeforeInput in case a newline \n is included, it does not return full content before input.

I placed the cursor on after the good morning word center, I got only good string text. The remaining "hi folks", words do not return.

Here are some examples I have tried.

var inputText = "Hi folks,

Good morning to everyone "

var txtBeforeCursor = textDocumentProxy.documentContextBeforeInput ?? ""

print("Before Cursor text : ",txtBeforeCursor)

Output is:

Before Cursor text : Good