Closed jukben closed 6 years ago
@jukben Yeah giving integer position would work, and I can see that would be easy to implement, but my idea was to have a special character in the output string, and interpolate position from it...
Could you please give me some example?
@jukben Sure, let me know if this needs some clarification
<ReactTextareaAutocomplete
className="ant-select-auto-complete.ant-select ant-input"
loadingComponent={Loading}
minChar={0}
rows={1}
trigger={{
'#': {
dataProvider: (token) => {
if (!token || !token.length) {
return this.props.allProperties
}
return this.props.allProperties.filter(prop => {
if (prop.name.search(new RegExp(token, "i")) !== -1) {
return prop
}
return null
})
},
component: ItemComponent,
output: (item, trigger) => {
switch (item.type) {
case 'string':
return `${item.name} = ('${special_character_to_indicate_caret_position}')`
case 'number':
return `${item.name} in ('${special_character_to_indicate_caret_position}', '${maybe_have_multiple_positions}')`
case 'date':
return `${item.name} in ('${special_character_to_indicate_caret_position}', '${maybe_have_multiple_positions}')`
default:
return `${item.name} = ('${special_character_to_indicate_caret_position}')`
}
}
},
}}
/>
@milosimr Hey, to be honest, I don't really like the idea of interpolated
position based on some magic character. You could easily count on which position the caret should appear:
return {
text: `${item.name} = ('${special_character_to_indicate_caret_position}')`
caretPosition: `${item.name} = (`.length
}
How do you imagine that multiple positions should work?
@jukben That's true, that solution is simpler and much easier to implement...
As for multiple positions, there could be a special character e.g.
@milosimr I personally think that jumping functionality is out of the scope of this plugin. I could go for my proposal about caretPosition, that's reasonable.
Anyway, I could provide getters/setters for textarea's caret position, so you can implement it by yourself.
@jukben Ok, getters/setters would be nice, I understand that my proposals are out of the scope of this plugin, I have some other needs for customization, once I get to that point i'll fork the project and make them.
Thanks for all the help.
Good. I opened Issue for getters/setters and this could be implemented also as we discussed. So if someone is interested, please follow my proposal for implementing this.
I am on it 🙂
Cool! I can't wait to see your PR ❤️
Need to refactor getTextToReplace
props from List.jsx
(should be solved instead in onSelect
method inside of Textarea.jsx
)
See https://github.com/webscopeio/react-textarea-autocomplete/blob/master/src/List.jsx#L74
Hey guys, in the end, it looks like I just cannot find time to do this 😞 If someone can pick it up, please do.
A customizable final position of the cursor in the outputted string
Options could be
"start" | "end" | number
(position in the final string). Default should be "end"Proposal:
Any thoughts?