Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit aa32fff

Browse files
committed
Moved comments out of if() blocks and other minor refactoring.
1 parent 65e899f commit aa32fff

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

src/view/renderer.js

+28-21
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,31 @@ export default class Renderer {
8989
*/
9090
this.selection = selection;
9191

92-
/**
93-
* The text node in which the inline filler was rendered.
94-
*
95-
* @private
96-
* @member {Text}
97-
*/
98-
this._inlineFiller = null;
99-
10092
/**
10193
* Indicates whether the view document is focused and selection can be rendered. Selection will not be rendered if
10294
* this is set to `false`.
10395
*
96+
* @readonly
10497
* @member {Boolean}
10598
*/
10699
this.isFocused = false;
107100

108101
/**
109102
* Indicates whether text composition takes place in the document.
110103
*
104+
* @readonly
111105
* @member {Boolean}
112106
*/
113107
this.isComposing = false;
114108

109+
/**
110+
* The text node in which the inline filler was rendered.
111+
*
112+
* @private
113+
* @member {Text}
114+
*/
115+
this._inlineFiller = null;
116+
115117
/**
116118
* DOM element containing fake selection.
117119
*
@@ -188,25 +190,28 @@ export default class Renderer {
188190
let inlineFillerPosition;
189191

190192
if ( this._inlineFiller ) {
193+
// There was inline filler rendered in the DOM but it's not at the selection position any more, so we can remove
194+
// it if not during composition (cause even if it's needed, it must be placed in another location).
191195
if ( !this.isComposing && !this._isSelectionInInlineFiller( false ) ) {
192-
// There was inline filler rendered in the DOM but it's not at the selection position any more, so we can remove
193-
// it if not during composition (cause even if it's needed, it must be placed in another location).
194196
this._removeInlineFiller();
195197
} else if ( this.isComposing ) {
196198
// When selection has 0 ranges, `isCollapsed` returns false, but here
197199
// we are only interested in non-collapsed selection (so with at least 1 range).
198-
if ( !this.selection.isCollapsed && this.selection.rangeCount > 0 ) {
199-
// During composition selection may be extended and its start/end moved to a different text
200-
// node (using 'shift + up' in Chrome on Windows during composition). In such situations
201-
// filler should not be moved or deleted (because it is possible to continue composing).
200+
const isSelectionNotCollapsed = !this.selection.isCollapsed && this.selection.rangeCount > 0;
201+
202+
// During composition selection may be extended and its start/end moved to a different text
203+
// node (using 'shift + up' in Chrome on Windows during composition). In such situations
204+
// filler should not be moved or deleted (because it is possible to continue composing).
205+
if ( isSelectionNotCollapsed ) {
202206
inlineFillerPosition = this._getExistingInlineFillerPosition();
203-
} else if ( !this._isValidCompositionSelection() ) {
204-
// Check for situations like:
205-
//
206-
// <p>text{}</p><p>FILLERtext</p> or <p>{}</p><p>FILLERtext</p>
207-
//
208-
// when collapsed selection was moved to a different node (without inline filler) during composition.
209-
// It means `compositionend` event was not fired properly and inline filler should be removed.
207+
}
208+
// Check for situations like:
209+
//
210+
// <p>text{}</p><p>FILLERtext</p> or <p>{}</p><p>FILLERtext</p>
211+
//
212+
// when collapsed selection was moved to a different node (without inline filler) during composition.
213+
// It means `compositionend` event was not fired properly and inline filler should be removed.
214+
else if ( !this._isValidCompositionSelection() ) {
210215
this._removeInlineFiller();
211216
}
212217
}
@@ -239,13 +244,15 @@ export default class Renderer {
239244
this._updateText( node, { inlineFillerPosition } );
240245
}
241246
}
247+
242248
// Check whether the inline filler is required and where it really is in the DOM.
243249
// At this point in most cases it will be in the DOM, but there are exceptions.
244250
// For example, if the inline filler was deep in the created DOM structure, it will not be created.
245251
// Similarly, if it was removed at the beginning of this function and then neither text nor children were updated,
246252
// it will not be present.
247253
// Fix those and similar scenarios.
248254
this._inlineFiller = null; // Reset filler first.
255+
249256
if ( inlineFillerPosition ) {
250257
const fillerDomPosition = this.domConverter.viewPositionToDom( inlineFillerPosition );
251258

0 commit comments

Comments
 (0)