jeff-collins / ment.io

Mentions and Macros for Angular
http://jeff-collins.github.io/ment.io
MIT License
1.13k stars 221 forks source link

forcing new space when replacing? #62

Open falcon1kr opened 9 years ago

falcon1kr commented 9 years ago

Is there a reason why a space is force-appended when the trigger text is replaced? Seems like, even in the demo, force-append ends up leaving 2 consecutive spaces after the replaced text

jeff-collins commented 9 years ago

you mean in the content editable? or textarea. In the demo, for practical purposes, there is only one space. which browser are you seeing this behavior on?

nonplus commented 9 years ago

I don't see an extra space, but I would like to be able to control what is being appended in replaceTriggerText, if anything.

Specifically, I have usage scenario where, depending on the selection, I would like to append a period rather than a space. My usage scenario is for an Intellisense-like input where my user can enter a dotted item (e.g. $Sender.FirstName) and I want to provide typeahead for the components of the item ("$" -> ['Sender', 'Recipient', ...], and "$Sender." -> ["FirstName", "LastName", ...]).

Maybe the mention-select callback could return an object with a flag indicating not to append the space. My callback would then look something like this:

function select(item) {
    if(item.needsDot) {
        return {
            text: item.label + ".",
            appendSpace: false
        };
    } else {
        // default behavior
        return item.label;
    }
}
krzysieki commented 8 years ago

I would appreciate an option to skip adding space after selection. My use case is quite similar to the one provided by @nonplus