public void OnContentChanged(string[] blockIds)
        {
            if (_editor == null)
            {
                ResetWidgets();
                return;
            }

            // The active block may have been removed then added again in which case
            // the old instance is invalid but can be restored by remapping the identifier
            if ((_activeBlock != null) && !_activeBlock.IsValid())
            {
                _activeBlock?.Dispose();
                _activeBlock = _editor.GetBlockById(_activeBlock.Id);

                if (_activeBlock == null)
                {
                    ResetWidgets();
                }
            }

            if (_activeBlock != null)
            {
                if ((blockIds != null) && blockIds.Contains(_activeBlock.Id))
                {
                    _currentBlock?.Dispose();
                    _currentBlock = _activeBlock?.ShallowCopy();

                    BackupData();
                    UpdateData();
                    UpdateWidgets(UpdateCause.Edit);
                }
            }
        }
        public void OnSelectionChanged(string[] blockIds)
        {
            _selectedBlock?.Dispose();
            _selectedBlock = null;

            if (blockIds != null)
            {
                foreach (var blockId in blockIds)
                {
                    using (var block_ = _editor.GetBlockById(blockId))
                    {
                        if ((block_ != null) && (block_.Type == "Text"))
                        {
                            _selectedBlock = block_?.ShallowCopy();
                            break;
                        }
                    }
                }
            }

            bool selectionChanged = false;

            if ((_selectedBlock != null) && (_currentBlock != null))
            {
                selectionChanged = (_currentBlock.Id != _selectedBlock.Id);
            }
            else
            {
                selectionChanged = (_selectedBlock != _currentBlock);
            }

            if (selectionChanged)
            {
                if (_selectedBlock != null)
                {
                    BackupData();

                    _currentBlock?.Dispose();
                    _currentBlock = _selectedBlock?.ShallowCopy();

                    UpdateData();
                    UpdateWidgets(UpdateCause.Selection);
                }
                else
                {
                    ResetWidgets();
                }
            }
        }
        public void OnActiveBlockChanged(string blockId)
        {
            _activeBlock?.Dispose();
            _activeBlock = _editor.GetBlockById(blockId);

            if ((_currentBlock != null) && (_activeBlock != null) && (_currentBlock.Id == _activeBlock.Id))
            {
                return; // selectionChanged already changed the active block
            }
            BackupData();
            _currentBlock?.Dispose();
            _currentBlock = _activeBlock?.ShallowCopy();
            UpdateData();

            if (_currentBlock != null)
            {
                UpdateWidgets(UpdateCause.Edit);
            }
            else
            {
                ResetWidgets();
            }
        }
 private void BackupData()
 {
     _previousBlock?.Dispose();
     _previousBlock = _currentBlock?.ShallowCopy();
     _previousWords = CloneWords(_currentWords);
 }