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

Selection bugfix #970

Merged
merged 4 commits into from
Nov 30, 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
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