Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit c370cf3

Browse files
Merge pull request #1158 from deckgo/fix/color-selection
fix: color selection
2 parents 3cd2c3c + 7168bc1 commit c370cf3

File tree

6 files changed

+32
-19
lines changed

6 files changed

+32
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- color: v4.0.0 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/color/CHANGELOG.md))
1616
- core: v8.1.6 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/core/CHANGELOG.md))
1717
- highlight-code: v2.6.0 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/highlight-code/CHANGELOG.md))
18-
- inline-editor: v4.0.0 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/inline-editor/CHANGELOG.md))
18+
- inline-editor: v4.0.2 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/inline-editor/CHANGELOG.md))
1919
- markdown: v2.0.2 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/markdown/CHANGELOG.md))
2020

2121
### Others

webcomponents/inline-editor/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# 4.0.0 (2021-05-09)
1+
# 4.0.2 (2021-05-09)
2+
3+
### Fix
4+
5+
- do not loose range selection focus on color input
6+
7+
# 4.0.1 (2021-05-09)
28

39
### Features
410

webcomponents/inline-editor/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webcomponents/inline-editor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deckdeckgo/inline-editor",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"description": "A WYSIWYG HTML Inline Editor Web Component",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.js",

webcomponents/inline-editor/src/components/actions/color-actions/color-actions.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {DeckdeckgoPalette} from '@deckdeckgo/color';
44

55
import {hexToRgb} from '@deckdeckgo/utils';
66

7-
import {clearTheSelection, getSelection} from '../../../utils/selection.utils';
7+
import {getSelection} from '../../../utils/selection.utils';
88
import {findStyleNode, getAnchorNode} from '../../../utils/node.utils';
99

1010
import {ExecCommandAction} from '../../../interfaces/interfaces';
@@ -33,12 +33,17 @@ export class ColorActions {
3333
@Event()
3434
private execCommand: EventEmitter<ExecCommandAction>;
3535

36+
private range: Range | undefined;
37+
3638
async componentWillLoad() {
3739
await this.initColor();
3840
}
3941

4042
private async initColor() {
4143
const selection: Selection | undefined = await getSelection();
44+
45+
this.range = selection?.getRangeAt(0);
46+
4247
const container: HTMLElement | undefined = getAnchorNode(selection);
4348

4449
if (!container) {
@@ -67,21 +72,19 @@ export class ColorActions {
6772
return;
6873
}
6974

70-
if (selection.rangeCount <= 0 || !document) {
71-
return;
72-
}
75+
selection?.removeAllRanges();
76+
selection?.addRange(this.range);
7377

74-
const range: Range | undefined = selection.getRangeAt(0);
78+
const observer: MutationObserver = new MutationObserver( (_mutations: MutationRecord[]) => {
79+
observer.disconnect();
7580

76-
const text: string = range?.toString();
77-
78-
if (!text || text.length <= 0) {
79-
return;
80-
}
81+
// No node were added so the style was modified
82+
this.range = selection?.getRangeAt(0);
83+
});
8184

82-
await clearTheSelection();
85+
const anchorNode: HTMLElement | undefined = getAnchorNode(selection);
8386

84-
selection?.addRange(range);
87+
observer.observe(anchorNode, {childList: true});
8588

8689
this.execCommand.emit({
8790
cmd: 'style',

webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ export class DeckdeckgoInlineEditor {
388388
}
389389

390390
private async handleSelectionChange(_$event: UIEvent) {
391+
if (this.toolbarActions === ToolbarActions.COLOR || this.toolbarActions === ToolbarActions.BACKGROUND_COLOR) {
392+
return;
393+
}
394+
391395
if (document && document.activeElement && !this.isContainer(document.activeElement)) {
392396
if (document.activeElement.nodeName.toLowerCase() !== 'deckgo-inline-editor') {
393397
await this.reset(false);
@@ -831,15 +835,15 @@ export class DeckdeckgoInlineEditor {
831835
}
832836

833837
private onAttributesChangesInitStyle() {
834-
const anchoreNode: HTMLElement | undefined = getAnchorNode(this.selection);
838+
const anchorNode: HTMLElement | undefined = getAnchorNode(this.selection);
835839

836840
const observer: MutationObserver = new MutationObserver(async () => {
837841
observer.disconnect();
838842

839-
await this.initStyleForNode(anchoreNode);
843+
await this.initStyleForNode(anchorNode);
840844
});
841845

842-
observer.observe(anchoreNode, {attributes: true});
846+
observer.observe(anchorNode, {attributes: true});
843847
}
844848

845849
render() {

0 commit comments

Comments
 (0)