@@ -50,8 +50,11 @@ export default {
5050 } ,
5151 buttons ( ) {
5252 const getBtn = name => {
53- const btn = this . definitions [ name ] || buttons [ name ]
54- if ( btn . type === 'toggle' || btn . disable ) {
53+ const
54+ btn = this . definitions [ name ] || buttons [ name ] ,
55+ state = this . attrib [ btn . test || btn . cmd ]
56+
57+ if ( state === void 0 && ( btn . type === 'toggle' || btn . disable ) ) {
5558 this . attrib [ btn . test || btn . cmd ] = false
5659 }
5760 return btn
@@ -118,7 +121,7 @@ export default {
118121 const key = getEventKey ( e )
119122 this . updateAttributes ( )
120123
121- if ( ! e . ctrlKey || key === 17 || key === 65 ) {
124+ if ( ! e . ctrlKey || [ 17 , 65 , 67 , 86 ] . includes ( key ) ) {
122125 return
123126 }
124127
@@ -140,21 +143,29 @@ export default {
140143 }
141144 } ,
142145 updateAttributes ( ) {
143- console . log ( this . buttons )
144146 setTimeout ( ( ) => {
147+ let change = false
145148 Object . keys ( this . attrib ) . forEach ( cmd => {
146- this . attrib [ cmd ] = this . caret . is ( cmd )
149+ const state = this . caret . is ( cmd )
150+ if ( this . attrib [ cmd ] !== state ) {
151+ this . attrib [ cmd ] = state
152+ change = true
153+ }
147154 } )
148- this . $forceUpdate ( )
155+ if ( change ) {
156+ console . log ( 'forceUpdate' )
157+ this . $forceUpdate ( )
158+ }
149159 } , 1 )
150160 }
151161 } ,
152162 mounted ( ) {
153163 this . $refs . content . innerHTML = this . value
154164 this . caret = new Caret ( this . $refs . content )
155- this . runCmd ( 'defaultParagraphSeparator' , 'p ')
165+ document . execCommand ( 'defaultParagraphSeparator' , false , 'div ')
156166 } ,
157167 render ( h ) {
168+ const attr = this . attrib
158169 return h (
159170 'div' ,
160171 { staticClass : 'q-editor' } ,
@@ -173,10 +184,16 @@ export default {
173184 on : {
174185 input : this . onInput ,
175186 keydown : this . onKeydown ,
176- click : this . updateAttributes
187+ click : this . updateAttributes ,
188+ blur : ( ) => {
189+ this . caret . save ( )
190+ }
177191 }
178192 }
179- )
193+ ) ,
194+ h ( 'div' , { style : {
195+ wordWrap : 'break-word'
196+ } } , [ JSON . stringify ( attr ) ] )
180197 ]
181198 )
182199 }
0 commit comments