Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to position the cursor in the output string #23

Closed
jukben opened this issue Oct 17, 2017 · 12 comments
Closed

Ability to position the cursor in the output string #23

jukben opened this issue Oct 17, 2017 · 12 comments

Comments

@jukben
Copy link
Collaborator

jukben commented Oct 17, 2017

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:

type Output = (item: Object | string, trigger?: string) => 
    string | { text: string, caretPosition: "start" | "end" | number }

type triggerType = {
    [triggerChar: string]: {
        ?output: Output,
        dataProvider: (token: string) => Promise<Array<Object | string>> | Array<Object | string>,
        component: ReactClass<*>,
    },
}

Any thoughts?

@milosimr
Copy link

@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...

@jukben
Copy link
Collaborator Author

jukben commented Oct 17, 2017

Could you please give me some example?

@milosimr
Copy link

milosimr commented Oct 17, 2017

@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}')`
          }
        }
      },
  }}
/>

@jukben
Copy link
Collaborator Author

jukben commented Oct 17, 2017

@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?

@milosimr
Copy link

@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. that would jump to the next position. Again I understand its harder to implement that, and solution will probably require a hack of some sorts, given the nature of textarea.

@jukben
Copy link
Collaborator Author

jukben commented Oct 18, 2017

@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.

@milosimr
Copy link

@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.

@jukben
Copy link
Collaborator Author

jukben commented Oct 18, 2017

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.

@Olovorr
Copy link

Olovorr commented Oct 23, 2017

I am on it 🙂

@jukben
Copy link
Collaborator Author

jukben commented Oct 23, 2017

Cool! I can't wait to see your PR ❤️

@jukben
Copy link
Collaborator Author

jukben commented Oct 23, 2017

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

@Olovorr
Copy link

Olovorr commented Nov 29, 2017

Hey guys, in the end, it looks like I just cannot find time to do this 😞 If someone can pick it up, please do.

@Olovorr Olovorr removed their assignment Nov 29, 2017
@jukben jukben closed this as completed in #35 Dec 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants