Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

summernote / summernote / 3346

28 Nov 2018 - 5:05 First build on hotfix/last-focus-manager at 77.526%
3346

Pull #3049

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Merge branch 'hotfix/last-focus-manager' of https://github.com/summernote/summernote into hotfix/last-focus-manager
Pull Request #3049: Update last focus manager

966 of 1784 branches covered (54.15%)

58 of 103 new or added lines in 10 files covered. (56.31%)

4519 of 5829 relevant lines covered (77.53%)

104.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.77
/src/js/base/module/AutoReplace.js
1
import lists from '../core/lists';
1×
2
import dom from '../core/dom';
1×
3
import key from '../core/key';
1×
4

1×
5
export default class AutoReplace {
1×
6
  constructor(context) {
1×
7
    this.context = context;
2×
8
    this.options = context.options.replace || {};
94×
9

94×
10
    this.keys = [key.code.ENTER, key.code.SPACE, key.code.PERIOD, key.code.COMMA, key.code.SEMICOLON, key.code.SLASH];
94×
11
    this.previousKeydownCode = null;
94×
12

94×
13
    this.events = {
94×
14
      'summernote.keyup': (we, e) => {
NEW
15
        if (!e.isDefaultPrevented()) {
Branches [[2, 0], [2, 1]] missed. !
NEW
16
          this.handleKeyup(e);
!
17
        }
18
      },
19
      'summernote.keydown': (we, e) => {
NEW
20
        this.handleKeydown(e);
!
21
      }
22
    };
23
  }
24

1×
25
  shouldInitialize() {
96×
26
    return !!this.options.match;
27
  }
1×
NEW
28

!
29
  initialize() {
30
    this.lastWord = null;
1×
NEW
31
  }
!
32

33
  destroy() {
34
    this.lastWord = null;
35
  }
36

1×
NEW
37
  /**
Branches [[3, 0], [3, 1]] missed. !
NEW
38
   * options.replace.match = function(word, done){ if(word=='this') done('that') else done();
!
39
   */
NEW
40

!
NEW
41
  replace() {
!
NEW
42
    if (!this.lastWord) {
!
NEW
43
      return;
Branches [[4, 0], [4, 1]] missed. !
NEW
44
    }
!
NEW
45

Branches [[5, 0], [5, 1]] missed. !
NEW
46
    const self = this;
!
47
    const keyword = this.lastWord.toString();
NEW
48
    this.options.match(keyword, function(match) {
Branches [[6, 0], [6, 1]] missed. !
NEW
49
      if (match) {
!
50
        let node = '';
NEW
51

Branches [[7, 0], [7, 1]] missed. !
NEW
52
        if (typeof match === 'string') {
!
53
          node = dom.createText(match);
NEW
54
        } else if (match instanceof jQuery) {
Branches [[8, 0], [8, 1]] missed. !
NEW
55
          node = match[0];
!
NEW
56
        } else if (match instanceof Node) {
!
NEW
57
          node = match;
!
NEW
58
        }
!
59

60
        if (!node) return;
61
        self.lastWord.insertNode(node);
62
        self.lastWord = null;
1×
63
        self.context.invoke('editor.focus');
64
      }
NEW
65
    });
Branches [[9, 0], [9, 1], [10, 0], [10, 1]] missed. !
NEW
66
  }
!
NEW
67

!
68
  handleKeydown(e) {
NEW
69
    // this forces it to remember the last whole word, even if multiple termination keys are pressed
Branches [[11, 0], [11, 1]] missed. !
NEW
70
    // before the previous key is let go.
!
NEW
71
    if (this.previousKeydownCode && lists.contains(this.keys, this.previousKeydownCode)) {
!
72
      this.previousKeydownCode = e.keyCode;
NEW
73
      return;
!
74
    }
75

1×
NEW
76
    if (lists.contains(this.keys, e.keyCode)) {
Branches [[12, 0], [12, 1]] missed. !
NEW
77
      const wordRange = this.context.invoke('editor.createRange').getWordRange();
!
78
      this.lastWord = wordRange;
79
    }
80
    this.previousKeydownCode = e.keyCode;
1×
81
  }
82

1×
83
  handleKeyup(e) {
84
    if (lists.contains(this.keys, e.keyCode)) {
85
      this.replace();
86
    }
87
  }
88
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC