@@ -79,9 +79,7 @@ ko.bindingHandlers.liveEdit = {
79
79
/**
80
80
* Key down event on element
81
81
*
82
- * Prevent styling such as bold, italic, and underline using keyboard commands
83
- * Prevent multi-line entries
84
- * Debounce the saving of the state to 1 second to ensure that on save without first unfocus will succeed
82
+ * Prevent styling such as bold, italic, and underline using keyboard commands, and prevent multi-line entries
85
83
*
86
84
* @param {any } event
87
85
*/
@@ -102,32 +100,37 @@ ko.bindingHandlers.liveEdit = {
102
100
event . stopPropagation ( ) ;
103
101
}
104
102
105
- _ . debounce ( ( ) => {
106
- const selection = window . getSelection ( ) ;
107
- const range = document . createRange ( ) ;
108
- const getCharPosition = ( editableDiv : HTMLElement ) : number => {
109
- let charPosition = 0 ;
110
-
111
- if ( window . getSelection ) {
112
- if ( selection . rangeCount ) {
113
- if ( selection . getRangeAt ( 0 ) . commonAncestorContainer . parentNode === editableDiv ) {
114
- charPosition = selection . getRangeAt ( 0 ) . endOffset ;
115
- }
103
+ debouncedUpdateHandler . call ( this ) ;
104
+ } ;
105
+
106
+ /**
107
+ * Debounce the saving of the state to ensure that on save without first unfocusing will succeed
108
+ */
109
+ const debouncedUpdateHandler = _ . debounce ( ( ) => {
110
+ const selection = window . getSelection ( ) ;
111
+ const range = document . createRange ( ) ;
112
+ const getCharPosition = ( editableDiv : HTMLElement ) : number => {
113
+ let charPosition = 0 ;
114
+
115
+ if ( window . getSelection ) {
116
+ if ( selection . rangeCount ) {
117
+ if ( selection . getRangeAt ( 0 ) . commonAncestorContainer . parentNode === editableDiv ) {
118
+ charPosition = selection . getRangeAt ( 0 ) . endOffset ;
116
119
}
117
120
}
118
- return charPosition ;
119
- } ;
120
- const pos : number = getCharPosition ( element ) ;
121
-
122
- if ( focusedValue !== stripHtml ( element . innerHTML ) ) {
123
- viewModel . updateData ( field , stripHtml ( element . innerHTML ) ) ;
124
121
}
125
- range . setStart ( element . childNodes [ 0 ] , pos ) ;
126
- range . collapse ( true ) ;
127
- selection . removeAllRanges ( ) ;
128
- selection . addRange ( range ) ;
129
- } , 300 ) . call ( this ) ;
130
- } ;
122
+ return charPosition ;
123
+ } ;
124
+ const pos : number = getCharPosition ( element ) ;
125
+
126
+ if ( focusedValue !== stripHtml ( element . innerHTML ) ) {
127
+ viewModel . updateData ( field , stripHtml ( element . innerHTML ) ) ;
128
+ }
129
+ range . setStart ( element . childNodes [ 0 ] , pos ) ;
130
+ range . collapse ( true ) ;
131
+ selection . removeAllRanges ( ) ;
132
+ selection . addRange ( range ) ;
133
+ } , 300 ) ;
131
134
132
135
/**
133
136
* Prevent content from being dropped inside of inline edit area
0 commit comments