File tree Expand file tree Collapse file tree 5 files changed +39
-19
lines changed Expand file tree Collapse file tree 5 files changed +39
-19
lines changed Original file line number Diff line number Diff line change @@ -37,8 +37,14 @@ class Container extends React.Component {
37
37
this . unmount = this . unmount . bind ( this )
38
38
}
39
39
40
- componentWillMount ( ) {
41
- $ ( 'html' ) . on ( 'click' , this . unmountOnClickOutside )
40
+ componentDidMount ( ) {
41
+ // we add this event listener in a callback because
42
+ // without the jump to the back of the event loop, this
43
+ // listener picks up the "click" event when a user clicks
44
+ // the at.js dropdown to select a command
45
+ setTimeout ( ( ) => {
46
+ $ ( 'html' ) . on ( 'click' , this . unmountOnClickOutside )
47
+ } , 0 )
42
48
}
43
49
44
50
componentWillUnmount ( ) {
Original file line number Diff line number Diff line change @@ -3,27 +3,33 @@ import Field from './Field'
3
3
4
4
class ContentEditable extends Field {
5
5
getText ( ) {
6
- return this . $element [ 0 ] . innerHTML
6
+ return this . $element [ 0 ] . textContent
7
7
}
8
8
9
9
persistSelection ( ) {
10
- this . range = rangy . getSelection ( ) . getRangeAt ( 0 )
10
+ let selection = rangy . getSelection ( )
11
+ if ( selection . rangeCount > 0 ) {
12
+ this . range = rangy . getSelection ( ) . getRangeAt ( 0 )
13
+ } else {
14
+ let range = rangy . createRange ( )
15
+ range . selectNodeContents ( this . $element . get ( 0 ) )
16
+ range . collapse ( false )
17
+ this . range = range
18
+ }
11
19
}
12
20
13
21
removeCommand ( match ) {
14
22
super . removeCommand ( )
23
+
15
24
let range = this . range
16
- let container = range . startContainer
17
- if ( container && container . classList && container . classList . contains ( "atwho-query" ) ) {
18
- range . selectNode ( container )
19
- } else {
20
- range . setStart ( range . startContainer , range . startOffset - match . length )
21
- }
22
- range . deleteContents ( )
25
+ let container = range . startContainer . closest ? range . startContainer : range . startContainer . parentElement
26
+ let query = container . closest ( '.atwho-query' ) ||
27
+ container . querySelector ( '.atwho-query' ) ||
28
+ container . querySelector ( '.atwho-inserted' ) ||
29
+ container . querySelector ( '.atwho-inserted' )
23
30
24
- if ( range . startContainer . innerHTML == "" ) {
25
- range . selectNodeContents ( range . startContainer . parentNode )
26
- }
31
+ range . selectNode ( query )
32
+ range . deleteContents ( )
27
33
}
28
34
29
35
insertText ( text ) {
Original file line number Diff line number Diff line change @@ -20,10 +20,10 @@ class Field {
20
20
21
21
observe ( ) {
22
22
this . setupQuickSelect ( )
23
- this . $element . on ( 'keyup' , this . listen )
23
+ this . $element . on ( 'keyup inserted.atwho ' , this . listen )
24
24
}
25
25
26
- listen ( ) {
26
+ listen ( e ) {
27
27
let { command, match } = Commands . match ( this . getText ( ) )
28
28
if ( command ) {
29
29
this . mount ( command , match )
@@ -64,7 +64,9 @@ class Field {
64
64
this . focus ( )
65
65
}
66
66
67
- removeCommand ( ) { }
67
+ removeCommand ( ) {
68
+ this . $element . atwho ( 'hide' )
69
+ }
68
70
69
71
mount ( Component , match ) {
70
72
this . persistSelection ( )
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ export function setup($element) {
8
8
at : "/" ,
9
9
data : Commands . getAtData ( ) ,
10
10
displayTpl : "<li>${name}<img src='${icon}' /></li>" ,
11
- displayTimeout : 0
11
+ insertTpl : "/${name}" ,
12
+ displayTimeout : 300 ,
13
+ suffix : ""
12
14
} )
13
15
}
Original file line number Diff line number Diff line change @@ -805,6 +805,10 @@ EditableController = (function(superClass) {
805
805
} ;
806
806
807
807
EditableController . prototype . rect = function ( ) {
808
+ if ( this . query . el . length == 0 ) {
809
+ return
810
+ }
811
+
808
812
var $iframe , iframeOffset , rect ;
809
813
rect = this . query . el . offset ( ) ;
810
814
if ( this . app . iframe && ! this . app . iframeAsRoot ) {
@@ -824,7 +828,7 @@ EditableController = (function(superClass) {
824
828
if ( range = this . _getRange ( ) ) {
825
829
range . setEndAfter ( this . query . el [ 0 ] ) ;
826
830
range . collapse ( false ) ;
827
- range . insertNode ( suffixNode = this . app . document . createTextNode ( "\u200D" + suffix ) ) ;
831
+ range . insertNode ( suffixNode = this . app . document . createTextNode ( suffix ) ) ;
828
832
this . _setRange ( 'after' , suffixNode , range ) ;
829
833
}
830
834
if ( ! this . $inputor . is ( ':focus' ) ) {
You can’t perform that action at this time.
0 commit comments