Skip to content

Instantly share code, notes, and snippets.

@gtokman
Created June 28, 2021 22:20
Show Gist options
  • Save gtokman/af1ea26a8e43b6e0125d943832b2b947 to your computer and use it in GitHub Desktop.
Save gtokman/af1ea26a8e43b6e0125d943832b2b947 to your computer and use it in GitHub Desktop.
Get full context
// Grab everything before the cursor
var before = textDocumentProxy.documentContextBeforeInput
var completePriorString = ""
while let beforeInput = before, !beforeInput.isEmpty {
completePriorString = beforeInput
let length = beforeInput.lengthOfBytes(using: String.Encoding.utf8)
textDocumentProxy.adjustTextPosition(byCharacterOffset: -length)
Thread.sleep(forTimeInterval: 0.01)
before = textDocumentProxy.documentContextBeforeInput
}
// Move the cursor back to the original position
textDocumentProxy
.adjustTextPosition(byCharacterOffset: completePriorString.count)
Thread.sleep(forTimeInterval: 0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment