Commit 9788b218 authored by Tom Hudson's avatar Tom Hudson
Browse files

Fixed bug where the default triggerChar always triggered mention behaviour...

Fixed bug where the default triggerChar always triggered mention behaviour when a triggerCharKeyCode was specified. Updated docs to reflect change.
parent 18275424
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -49,12 +49,14 @@ The following optional configuration items can be used.
| Option             | Default  | Description |
| ---                | ---      | ---         |
| triggerChar        | @        | The character that will trigger the menu behavior. |
| triggerCharKeyCode | 192      | The keycode that will also trigger the menu behaviour - defaults to '@' keycode |
| triggerCharKeyCode |          | The key code that can trigger the menu behavior - use [keycode.info](http://keycode.info/) to help you find the correct key code |
| maxItems           |          | Limit the number of items shown in the pop-up menu. The default is no limit. |
| mentionSelect      |          | An optional function to format the selected item before inserting the text. |
| labelKey           | label    | The field to be used as the item label (when the items are objects). |
| disableSearch      | false    | Disable internal filtering (only useful if async search is used). |

> If you specify a triggerCharKeyCode, the triggerChar value will be ignored

For Example: 

    <input type="text" [mention]="items" [mentionConfig]="{triggerChar:'#',maxItems:10,labelKey:'name'}">
+3 −3
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ export class MentionDirective implements OnInit, OnChanges {

  @Input() set mentionConfig(config:any) {
    this.triggerChar = config.triggerChar || this.triggerChar;
    this.triggerCharKeyCode = config.triggerCharKeyCode || this.triggerCharKeyCode;
    this.triggerCharKeyCode = config.triggerCharKeyCode;
    this.labelKey = config.labelKey || this.labelKey;
    this.disableSearch = config.disableSearch || this.disableSearch;
    this.maxItems = config.maxItems || this.maxItems;
@@ -54,7 +54,7 @@ export class MentionDirective implements OnInit, OnChanges {
  private triggerChar: string = "@";

  // the character keycode which can also trigger the menu behavior
  private triggerCharKeyCode: number = 192;
  private triggerCharKeyCode: string;

  // option to specify the field in the objects to be used as the item label
  private labelKey:string = 'label';
@@ -155,7 +155,7 @@ export class MentionDirective implements OnInit, OnChanges {
      setCaretPosition(this.startNode, pos, this.iframe);
    }
    //console.log("keyHandler", this.startPos, pos, val, charPressed, event);
    if (charPressed == this.triggerChar || charPressedKeyCode == this.triggerCharKeyCode) {
    if ((!this.triggerCharKeyCode && charPressed == this.triggerChar) || charPressedKeyCode == this.triggerCharKeyCode) {
      this.startPos = pos;
      this.startNode = (this.iframe ? this.iframe.contentWindow.getSelection() : window.getSelection()).anchorNode;
      this.stopSearch = false;