Comments (14)
shouldUnregister
does include the filter string in manager.currentSession
when removing the prefix and string
from inputbaraccessoryview.
Use the properties passed by the delegates function, it explicitly passes the filter text
Sent with GitHawk
from inputbaraccessoryview.
func autocompleteManager(_ manager: AutocompleteManager, shouldComplete prefix: String, with text: String) -> Bool { print("shouldComplete") print(prefix) print(text) print(manager.currentSession as Any) return true }
Ya it's showing empty
from inputbaraccessoryview.
hey @nathantannar4
After more investigation, I found this worked with the autocomplete
method
guard delegate?.autocompleteManager(self, shouldComplete: session.prefix, with: (session.completion?.text)!) != false else { return }
session.filter is always empty, therefore passing on text as empty to the delegate.
I'm not a Swift expert, so maybe this is incorrect, but I can at least capture the text within the ExampleViewController.
from inputbaraccessoryview.
For better reference:
open func autocomplete(with session: AutocompleteSession) {
guard let textView = inputTextView else { return }
// Replace the attributedText with a modified version
let autocomplete = session.completion?.text ?? ""
guard delegate?.autocompleteManager(self, shouldComplete: session.prefix, with: autocomplete) != false else { return }
// Create a range that overlaps the prefix
let prefixLength = session.prefix.utf16.count
let insertionRange = NSRange(
location: session.range.location + (keepPrefixOnCompletion ? prefixLength : 0),
length: session.filter.utf16.count + (!keepPrefixOnCompletion ? prefixLength : 0)
)
// Transform range
guard let range = Range(insertionRange, in: textView.text) else { return }
let nsrange = NSRange(range, in: textView.text)
insertAutocomplete(autocomplete, at: session, for: nsrange)
// Move Cursor to the end of the inserted text
let selectedLocation = insertionRange.location + autocomplete.utf16.count + (appendSpaceOnCompletion ? 1 : 0)
textView.selectedRange = NSRange(
location: selectedLocation,
length: 0
)
// End the session
unregisterCurrentSession()
}
from inputbaraccessoryview.
@bribar I believe you misunderstand the function. Have you looked at the documentation for the method?
func autocompleteManager(_ manager: AutocompleteManager, shouldComplete prefix: String, with text: String) -> Bool
The text
is the String that the user has already typed, ie: the string to "autocomplete", so yes it can be empty if all they have entered is a prefix.
If you want the text that the user selected, look to AutocompleteCompletion
, each AutocompleteSession
has once as a completion
property. AutocompleteCompletion
can specify the text to autocomplete too and an optional displayText (useful for things like emojis or if you want to style a users name differently)
Your original question:
Shouldn't
text
be the autocomplete I selected?
No that is the text they have typed which filters available autocompletes
If you are still confused, please leave a more detailed reply as to what you are trying to do.
from inputbaraccessoryview.
I copy that... I'm just trying to add the completion text without the prefix to a collection, if they remove the text then I remove it from the collection.
var mentions : [String] = [String]()
Example, user types: "Hey @ninja and @avatar, lets jump on a conference call."
"Ninja" and "Avatar" get added to mentions
If user removes @ninja, I remove it from mentions
, so now mentions
has ["Avatar"]
In the autocomplete
method, if I print(session)
it shows this
AutocompleteSession(prefix: "@", range: {9, 3}, filter: "ni", completion: Optional(InputBarAccessoryView.AutocompleteCompletion(text: "Ninja", displayText: nil)))
but in shouldComplete
of ExampleViewController
manager.currentSession.completion
is nil
Do I need to build on what you have or is this functionality default?
from inputbaraccessoryview.
Hmm ok well the completion property is nil up until the point where a user taps the cell. Have you overridden the didSelectRowAt? It gets set there so it shouldn't be nil. It cant be nil if the autocomplete works because it uses that property in the session data
Sent with GitHawk
from inputbaraccessoryview.
In any case I haven't made a method that would alert you when someone has deleted an autocomplete, so while you could get the name to append to a string array, it would never be removed.
Sent with GitHawk
from inputbaraccessoryview.
I haven't overridden didSelectRowAt.
Yes autocomplete I can print(session) and its there.
open func autocomplete(with session: AutocompleteSession) {
print(session)
guard let textView = inputTextView else { return }
guard delegate?.autocompleteManager(self, shouldComplete: session.prefix, with: session.filter) != false else { return }
// Create a range that overlaps the prefix
let prefixLength = session.prefix.utf16.count
let insertionRange = NSRange(
location: session.range.location + (keepPrefixOnCompletion ? prefixLength : 0),
length: session.filter.utf16.count + (!keepPrefixOnCompletion ? prefixLength : 0)
)
// Transform range
guard let range = Range(insertionRange, in: textView.text) else { return }
let nsrange = NSRange(range, in: textView.text)
// Replace the attributedText with a modified version
let autocomplete = session.completion?.text ?? ""
insertAutocomplete(autocomplete, at: session, for: nsrange)
// Move Cursor to the end of the inserted text
let selectedLocation = insertionRange.location + autocomplete.utf16.count + (appendSpaceOnCompletion ? 1 : 0)
textView.selectedRange = NSRange(
location: selectedLocation,
length: 0
)
// End the session
unregisterCurrentSession()
}
But in
func autocompleteManager(_ manager: AutocompleteManager, shouldUnregister prefix: String) -> Bool {
print("shouldUnregister")
print(manager.currentSession as Any)
return true
}
it's nil
from inputbaraccessoryview.
Ok, I don't ever update the currentSession
which would be why it's still nil since it's a struct, I never made it with the intention of using the completion property.
- I will fix that in the next release, but I still would advise that you only check for all the @mentions when someone is done typing, rather than as they are typically because you won’t be able to remove it from your array without making some custom modifications to my code
Sent with GitHawk
from inputbaraccessoryview.
Sounds good @nathantannar4. Is v2.0.0 available on pods? It only installs v1.5.4.
from inputbaraccessoryview.
Hmm it should be available, try pod repo update
your local pods might be out of date
Sent with GitHawk
from inputbaraccessoryview.
This should be resolved in the latest version
from inputbaraccessoryview.
Related Issues (20)
- InputBarAccessoryView + SwiftUI incorrect offset HOT 1
- Library crashes app when adding an attachment when an AttachmentManager dataSource is defined HOT 9
- Layout issues on iPad when using pagesheets HOT 30
- SwiftUI Example Text Field too high, BottomStack too big HOT 2
- The height of input is changed even have set `maxTextViewHeight`
- Keyboard appearance issue!
- AutoCompleteManager Index out of bounds when using custom prefix
- KeyboardManager conflicts with system keyboard movement: How to resolve?
- Unable to build framework when including this via SPM HOT 4
- Xcode 14: custom inputAccessoryView appears prematurely, causing broken push animation HOT 3
- Update library with main and create tag
- The mentionTextAttributes is used for pasting new text.
- iOS 17 issue with selection HOT 1
- InputBarAccessoryView & inputTextView disappeared after searchbar has focused HOT 1
- Changing access modifier of requiredInputTextViewHeight from public to open? HOT 5
- scrollIndicatorInsets setter Recursion causes crashes HOT 1
- Privacy manifest HOT 2
- About paste monitoring HOT 3
- Why AttachmentManager extensions methods are 'finals'? HOT 2
- How inputTextView parses custom emoticons?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inputbaraccessoryview.