Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Block selection via CMD+A #829

Merged
merged 6 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dist/editor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `Refactoring` — Constants of tools settings separated by internal and external to correspond API
- `Refactoring` — Created universal Flipper class that responses for navigation by keyboard inside of any Toolbars
- `Fix` — First CMD+A on block with now uses default behaviour. Fixed problem with second CMD+A after selection clearing [#827](https://github.com/codex-team/editor.js/issues/827)

### 2.15

Expand Down
6 changes: 6 additions & 0 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ export default class BlockEvents extends Module {
* @param {MouseEvent} event
*/
public mouseDown(event: MouseEvent): void {
/**
* Each mouse down on Block must disable selectAll state
*/
if (!SelectionUtils.isCollapsed) {
this.Editor.BlockSelection.clearSelection(event);
}
this.Editor.CrossBlockSelection.watchSelection(event);
}

Expand Down
45 changes: 31 additions & 14 deletions src/components/modules/blockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ export default class BlockSelection extends Module {
this.Editor.RectangleSelection.clearSelection();

/** allow default selection on native inputs */
if ($.isNativeInput(event.target) && !this.nativeInputSelected) {
this.nativeInputSelected = true;
if ($.isNativeInput(event.target) && !this.readyToBlockSelection) {
this.readyToBlockSelection = true;
return;
}

Expand All @@ -280,30 +280,35 @@ export default class BlockSelection extends Module {
return;
}

if (this.needToSelectAll) {
/** Prevent default selection */
event.preventDefault();
if (inputs.length === 1 && !this.needToSelectAll) {
this.needToSelectAll = true;
return;
}

if (this.needToSelectAll) {
/**
* Save selection
* Will be restored when closeSelection fired
* Prevent default selection
*/
this.selection.save();
event.preventDefault();

this.selectAllBlocks();

/**
* Remove Ranges from Selection
* Disable any selection after all Blocks selected
*/
SelectionUtils.get()
.removeAllRanges();

this.selectAllBlocks();
this.needToSelectAll = false;
this.readyToBlockSelection = false;

/**
* Close ConversionToolbar when all Blocks selected
*/
this.Editor.ConversionToolbar.close();
} else {
} else if (this.readyToBlockSelection) {
this.selectBlockByIndex();

/**
* Enable all Blocks selection if current Block is selected
*/
this.needToSelectAll = true;
}
}
Expand All @@ -313,6 +318,18 @@ export default class BlockSelection extends Module {
* Each Block has selected setter that makes Block copyable
*/
private selectAllBlocks() {
/**
* Save selection
* Will be restored when closeSelection fired
*/
this.selection.save();

/**
* Remove Ranges from Selection
*/
SelectionUtils.get()
.removeAllRanges();

this.allBlocksSelected = true;
}
}