delete block

This commit is contained in:
Murod Khaydarov 2018-05-22 12:56:55 +03:00
commit eded07b984
No known key found for this signature in database
GPG key ID: C480BA53A8D274C5
5 changed files with 103 additions and 12 deletions

View file

@ -1549,6 +1549,24 @@ var BlockManager = function (_Module) {
this.Editor.Caret.setToBlock(block);
}
/**
* Remove block with passed index or remove last
* @param {Number|null} index
*/
}, {
key: 'removeBlock',
value: function removeBlock(index) {
this._blocks.remove(index);
// decrease current block index so that to know current actual
this.currentBlockIndex--;
// set caret to the block without offset at the end
this.Editor.Caret.setToBlock(this.currentBlock, 0, true);
this.Editor.Toolbar.close();
}
/**
* Split current Block
* 1. Extract content from Caret position to the Block`s end
@ -1875,6 +1893,24 @@ var Blocks = function () {
}
}
/**
* Remove block
* @param {Number|null} index
*/
}, {
key: 'remove',
value: function remove(index) {
if (!isNaN(index)) {
index = this.length - 1;
}
this.blocks[index].html.remove();
this.blocks.splice(index, 1);
}
/**
* Insert Block after passed target
*
@ -2639,6 +2675,7 @@ var Keyboard = function (_Module) {
case _.keyCodes.BACKSPACE:
_.log('Backspace key pressed');
this.backSpacePressed(event);
break;
case _.keyCodes.ENTER:
@ -2705,6 +2742,18 @@ var Keyboard = function (_Module) {
this.Editor.BlockManager.split();
}
/**
* Handle backspace keypress on block
* @param event
*/
}, {
key: 'backSpacePressed',
value: function backSpacePressed(event) {
this.Editor.BlockManager.removeBlock();
}
/**
* Handle right and down keyboard keys
*/
@ -4976,6 +5025,8 @@ var UI = function (_Module) {
value: function prepare() {
var _this2 = this;
// this.Editor.Toolbar.make();
return this.make()
/**
* Make toolbar
@ -5097,7 +5148,7 @@ var UI = function (_Module) {
/**
* @todo bind events with the Listeners module
*/
this.nodes.redactor.addEventListener('click', function (event) {
this.Editor.Listeners.on(this.nodes.redactor, 'click', function (event) {
return _this4.redactorClicked(event);
}, false);
}
@ -5139,12 +5190,11 @@ var UI = function (_Module) {
try {
this.Editor.BlockManager.setCurrentBlockByChildNode(clickedNode);
} catch (e) {
/**
* If clicked outside first-level Blocks, set Caret to the last empty Block
*/
} catch (e) {
this.Editor.Caret.setToTheLastBlock();
}

File diff suppressed because one or more lines are too long

View file

@ -185,6 +185,22 @@ export default class BlockManager extends Module {
}
/**
* Remove block with passed index or remove last
* @param {Number|null} index
*/
removeBlock(index) {
this._blocks.remove(index);
// decrease current block index so that to know current actual
this.currentBlockIndex--;
// set caret to the block without offset at the end
this.Editor.Caret.setToBlock(this.currentBlock, 0, true);
this.Editor.Toolbar.close();
}
/**
* Split current Block
* 1. Extract content from Caret position to the Block`s end
@ -484,6 +500,23 @@ class Blocks {
}
/**
* Remove block
* @param {Number|null} index
*/
remove(index) {
if (!isNaN(index)) {
index = this.length - 1;
}
this.blocks[index].html.remove();
this.blocks.splice(index, 1);
}
/**
* Insert Block after passed target
*

View file

@ -34,6 +34,7 @@ export default class Keyboard extends Module {
case _.keyCodes.BACKSPACE:
_.log('Backspace key pressed');
this.backSpacePressed(event);
break;
case _.keyCodes.ENTER:
@ -101,6 +102,16 @@ export default class Keyboard extends Module {
}
/**
* Handle backspace keypress on block
* @param event
*/
backSpacePressed(event) {
this.Editor.BlockManager.removeBlock();
}
/**
* Handle right and down keyboard keys
*/

View file

@ -75,7 +75,7 @@ export default class UI extends Module {
*/
prepare() {
this.Editor.Toolbar.make()
// this.Editor.Toolbar.make();
return this.make()
/**
@ -194,7 +194,7 @@ export default class UI extends Module {
/**
* @todo bind events with the Listeners module
*/
this.nodes.redactor.addEventListener('click', event => this.redactorClicked(event), false );
this.Editor.Listeners.on(this.nodes.redactor, 'click', event => this.redactorClicked(event), false );
}
@ -233,19 +233,16 @@ export default class UI extends Module {
this.Editor.BlockManager.setCurrentBlockByChildNode(clickedNode);
/**
* If clicked outside first-level Blocks, set Caret to the last empty Block
*/
} catch (e) {
/**
* If clicked outside first-level Blocks, set Caret to the last empty Block
*/
this.Editor.Caret.setToTheLastBlock();
}
/**
* @todo hide the Inline Toolbar
*/