Skip to content

Commit

Permalink
Selection bugfix (#970)
Browse files Browse the repository at this point in the history
* Selection bugfix

* fix cross block selection

* close inline toolbar when blocks selected via shift
  • Loading branch information
khaydarov authored Nov 30, 2019
1 parent 053e25e commit 2729f8f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
10 changes: 5 additions & 5 deletions dist/editor.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/components/modules/blockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ export default class BlockSelection extends Module {
.removeAllRanges();

block.selected = true;

/** close InlineToolbar when we selected any Block */
this.Editor.InlineToolbar.close();
}

/**
Expand Down Expand Up @@ -304,6 +307,14 @@ export default class BlockSelection extends Module {
*/
this.Editor.ConversionToolbar.close();
} else if (this.readyToBlockSelection) {
/**
* prevent default selection when we use custom selection
*/
event.preventDefault();

/**
* select working Block
*/
this.selectBlockByIndex();

/**
Expand Down Expand Up @@ -331,5 +342,8 @@ export default class BlockSelection extends Module {
.removeAllRanges();

this.allBlocksSelected = true;

/** close InlineToolbar if we selected all Blocks */
this.Editor.InlineToolbar.close();
}
}
14 changes: 14 additions & 0 deletions src/components/modules/crossBlockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export default class CrossBlockSelection extends Module {
Listeners.on(document, 'mouseup', this.onMouseUp);
}

/**
* return boolean is cross block selection started
*/
public get isCrossBlockSelectionStarted(): boolean {
return !!this.firstSelectedBlock
&& !!this.lastSelectedBlock;
}

/**
* Change selection state of the next Block
* Used for CBS via Shift + arrow keys
Expand Down Expand Up @@ -65,6 +73,9 @@ export default class CrossBlockSelection extends Module {
}

this.lastSelectedBlock = nextBlock;

/** close InlineToolbar when Blocks selected */
this.Editor.InlineToolbar.close();
}

/**
Expand Down Expand Up @@ -115,6 +126,9 @@ export default class CrossBlockSelection extends Module {

Listeners.off(document, 'mouseover', this.onMouseOver);
Listeners.off(document, 'mouseup', this.onMouseUp);

/** close InlineToolbar when Blocks selected */
this.Editor.InlineToolbar.close();
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ export default class InlineToolbar extends Module {

/** Check Tools state for selected fragment */
this.checkToolsState();

/** Clear selection */
this.Editor.BlockSelection.clearSelection();
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/components/modules/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ export default class UI extends Module {
this.Editor.BlockManager.dropPointer();
this.Editor.InlineToolbar.close();
this.Editor.Toolbar.close();
this.Editor.BlockSelection.clearSelection(event);
this.Editor.ConversionToolbar.close();
}

Expand All @@ -508,6 +507,13 @@ export default class UI extends Module {
this.Editor.BlockManager.setCurrentBlockByChildNode(Selection.anchorNode);
}
}

/**
* Clear Selection if user clicked somewhere
*/
if (!this.Editor.CrossBlockSelection.isCrossBlockSelectionStarted) {
this.Editor.BlockSelection.clearSelection(event);
}
}

/**
Expand Down

0 comments on commit 2729f8f

Please sign in to comment.