@@ -125,7 +125,7 @@ export class Inline<T extends JWPluginConfig = JWPluginConfig> extends JWPlugin<
125125 isAllFormat ( FormatClass : Constructor < Modifier > , range = this . editor . selection . range ) : boolean {
126126 if ( range . isCollapsed ( ) ) {
127127 if ( ! this . cache . modifiers ) {
128- return ! ! this . getCurrentModifiers ( range ) . find ( FormatClass ) ;
128+ return ! ! this . getCurrentModifiers ( range ) ? .find ( FormatClass ) ;
129129 }
130130 return ! ! this . cache . modifiers . find ( FormatClass ) ;
131131 } else {
@@ -139,30 +139,44 @@ export class Inline<T extends JWPluginConfig = JWPluginConfig> extends JWPlugin<
139139 /**
140140 * Get the modifiers for the next insertion.
141141 */
142- getCurrentModifiers ( range = this . editor . selection . range ) : Modifiers {
143- if ( this . cache . modifiers ) {
142+ getCurrentModifiers ( range = this . editor . selection . range ) : Modifiers | null {
143+ if ( this . cache . modifiers && range === this . editor . selection . range ) {
144144 return this . cache . modifiers ;
145+ } else {
146+ return this . _getCurrentModifiers ( range ) ;
145147 }
146-
148+ }
149+ /**
150+ * Get the current modifiers.
151+ */
152+ private _getCurrentModifiers ( range = this . editor . selection . range ) : Modifiers | null {
147153 let inlineToCopyModifiers : VNode ;
148154 if ( range . isCollapsed ( ) ) {
149155 // TODO: LineBreakNode should have the formats as well.
150156 inlineToCopyModifiers =
151- range . start . previousSibling ( node => ! node . test ( LineBreakNode ) ) ||
157+ range . start . previousSibling ( node => ! ( node instanceof LineBreakNode ) ) ||
152158 range . start . nextSibling ( ) ;
153159 } else {
154160 inlineToCopyModifiers = range . start . nextSibling ( ) ;
155161 }
156162 if ( inlineToCopyModifiers && inlineToCopyModifiers . is ( InlineNode ) ) {
157163 return inlineToCopyModifiers . modifiers . clone ( ) ;
158164 }
159-
160- return new Modifiers ( ) ;
161165 }
162166 /**
163167 * Get the styles for the next insertion.
164168 */
165- getCurrentStyle ( range = this . editor . selection . range ) : CssStyle {
169+ getCurrentStyle ( range = this . editor . selection . range ) : CssStyle | null {
170+ if ( this . cache . style && range === this . editor . selection . range ) {
171+ return this . cache . style ;
172+ } else {
173+ return this . _getCurrentStyle ( range ) ;
174+ }
175+ }
176+ /**
177+ * Get the current styles for the next insertion.
178+ */
179+ private _getCurrentStyle ( range = this . editor . selection . range ) : CssStyle | null {
166180 if ( this . cache . style ) {
167181 return this . cache . style ;
168182 }
@@ -176,15 +190,14 @@ export class Inline<T extends JWPluginConfig = JWPluginConfig> extends JWPlugin<
176190 if ( inlineToCopyStyle && inlineToCopyStyle . is ( InlineNode ) ) {
177191 return inlineToCopyStyle . modifiers . find ( Attributes ) ?. style . clone ( ) || new CssStyle ( ) ;
178192 }
179- return new CssStyle ( ) ;
180193 }
181194 /**
182195 * Each time the selection changes, we reset its format and style.
183196 */
184197 resetCache ( ) : void {
185198 this . cache = {
186- modifiers : null ,
187- style : null ,
199+ modifiers : this . _getCurrentModifiers ( ) ,
200+ style : this . _getCurrentStyle ( ) ,
188201 } ;
189202 }
190203 /**
0 commit comments