Skip to content

Commit

Permalink
При перемещении по стрелочкам убирать выделение блока (#296)
Browse files Browse the repository at this point in the history
* При перемещении по стрелочкам убирать выделение блока

* Add comments

* update comments

* update comment
  • Loading branch information
talyguryn authored Jul 18, 2018
1 parent cbb4746 commit dc7afd1
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 39 deletions.
107 changes: 80 additions & 27 deletions build/codex-editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/codex-editor.js.map

Large diffs are not rendered by default.

46 changes: 36 additions & 10 deletions src/components/modules/block-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export default class BlockEvents extends Module {
* @param {KeyboardEvent} event - keydown
*/
public keydown(event: KeyboardEvent): void {
/**
* Run common method for all keydown events
*/
this.beforeKeydownProcessing();

/**
* Fire keydown processor by event.keyCode
*/
switch (event.keyCode) {
case _.keyCodes.BACKSPACE:
this.backspace(event);
Expand All @@ -43,6 +51,21 @@ export default class BlockEvents extends Module {
}
}

/**
* Fires on keydown before event processing
*/
public beforeKeydownProcessing(): void {
/**
* Clear all highlightings
*/
this.Editor.BlockManager.clearHighlightings();

/**
* Hide Toolbar
*/
this.Editor.Toolbar.close();
}

/**
* Key up on Block:
* - shows Inline Toolbar if something selected
Expand Down Expand Up @@ -93,9 +116,19 @@ export default class BlockEvents extends Module {
const newCurrent = this.Editor.BlockManager.currentBlock;

this.Editor.Toolbar.move();
this.Editor.Toolbar.open();

/**
* If new Block is empty
*/
if (this.Editor.Tools.isInitial(newCurrent.tool) && newCurrent.isEmpty) {
/**
* Show Toolbar
*/
this.Editor.Toolbar.open();

/**
* Show Plus Button
*/
this.Editor.Toolbar.plusButton.show();
}

Expand Down Expand Up @@ -142,6 +175,7 @@ export default class BlockEvents extends Module {
if (this.Editor.Caret.navigatePrevious()) {
this.Editor.Toolbar.close();
}

return;
}

Expand All @@ -160,25 +194,17 @@ export default class BlockEvents extends Module {
*/
private arrowRightAndDown(): void {
this.Editor.Caret.navigateNext();

this.Editor.Toolbar.close();
}

/**
* Handle left and up keyboard keys
*/
private arrowLeftAndUp(): void {
this.Editor.Caret.navigatePrevious();

this.Editor.Toolbar.close();
}

/**
* Default keydown handler
*/
private defaultHandler(): void {
this.Editor.BlockManager.currentBlock.selected = false;

this.Editor.Toolbar.close();
}
private defaultHandler(): void {}
}
14 changes: 13 additions & 1 deletion src/components/modules/blockManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,16 @@ export default class BlockManager extends Module {
* @type {number}
*/
this.currentBlockIndex = nodes.indexOf(firstLevelBlock);
}

/**
* Remove selection from all Blocks then highlight only Current Block
*/
highlightCurrentNode() {
/**
* Remove previous selected Block's state
*/
this.blocks.forEach( block => block.selected = false);
this.clearHighlightings();

/**
* Mark current Block as selected
Expand All @@ -307,6 +312,13 @@ export default class BlockManager extends Module {
this.currentBlock.selected = true;
}

/**
* Remove selection from all Blocks
*/
clearHighlightings() {
this.blocks.forEach( block => block.selected = false);
}

/**
* Get array of Block instances
*
Expand Down
8 changes: 8 additions & 0 deletions src/components/modules/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,15 @@ export default class UI extends Module {
* Select clicked Block as Current
*/
try {
/**
* Renew Current Block
*/
this.Editor.BlockManager.setCurrentBlockByChildNode(clickedNode);

/**
* Highlight Current Node
*/
this.Editor.BlockManager.highlightCurrentNode();
} catch (e) {
/**
* If clicked outside first-level Blocks, set Caret to the last empty Block
Expand Down

0 comments on commit dc7afd1

Please sign in to comment.