react-trix icon indicating copy to clipboard operation
react-trix copied to clipboard

MergeTags dropdown doesn't close on removing @

Open vinay0x opened this issue 5 years ago • 3 comments

If I type '@' the dropdown appears, and if I remove the '@', the dropdown is still there.

vinay0x avatar Nov 03 '19 16:11 vinay0x

Yes good catch, the popup should also dismiss if we press the Escape key.

dstpierre avatar Nov 22 '19 11:11 dstpierre

@dstpierre That's true. Let me know if you need any help with this.

vinay0x avatar Nov 22 '19 11:11 vinay0x

@vinay0x sure feel free to fork and try to implement this if you want. This would be in src/react-trix.tsx at line: 125:

// if we have a collapse selection
    if (text && range[0] == range[1]) {
      // if we have a merge tag mergeTagTrigger
      if (props.mergeTags) {
        // get the cursor position and compare the last character with our mergeTagTrigger
        const lastChar = range[0] - 1;
        if (lastChar >= 0 && lastChar < text.length) {
          const trigger = text[lastChar];
          for (let i = 0; i < props.mergeTags.length; i++) {
            if (trigger == props.mergeTags[i].trigger) {
              state.showMergeTags = true;
              state.tags = props.mergeTags[i].tags;
              this.setState(state);
              break;
            }
          }
        }
      }
    }

I would try to see if state.showMergeTags is already true and there's no trigger character anymore.

For the escape key, a new keypress event could be added setting the showMergeTags to false and that should be enough for that part.

Let me know how it goes.

dstpierre avatar Nov 22 '19 12:11 dstpierre