Optimisation: dont fire isEmpty checking for not-initial Blocks (#529)

* Optimisation: dont fire isEmpty checking for not-initial Blocks

Because not-initial Tools can has maaany nodes and it will be slow to walk three.

* upd comment
This commit is contained in:
Peter Savchenko 2018-11-24 16:33:43 +03:00 committed by GitHub
parent 09df079509
commit ecfcfaa79f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 10 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "codex.editor",
"version": "2.5.1",
"version": "2.5.2",
"description": "Codex Editor. Native JS, based on API and Open Source",
"main": "build/codex-editor.js",
"types": "./types/index.d.ts",

View file

@ -331,11 +331,17 @@ export default class UI extends Module {
* - Block is an initial-block (Text)
* - Block is empty
*/
const isInitialBlock = this.Editor.Tools.isInitial(this.Editor.BlockManager.currentBlock.tool),
isEmptyBlock = this.Editor.BlockManager.currentBlock.isEmpty;
const isInitialBlock = this.Editor.Tools.isInitial(this.Editor.BlockManager.currentBlock.tool);
if (isInitialBlock && isEmptyBlock) {
this.Editor.Toolbar.plusButton.show();
if (isInitialBlock) {
/**
* Check isEmpty only for paragraphs to prevent unnecessary tree-walking on Tools with many nodes (for ex. Table)
*/
const isEmptyBlock = this.Editor.BlockManager.currentBlock.isEmpty;
if (isEmptyBlock) {
this.Editor.Toolbar.plusButton.show();
}
}
/** Clear selection */