Skip to content

Commit 5b598b6

Browse files
authored
Merge pull request #45 from TH-coder/hotfix/issue44-inline-code
fix(inline-code): Fix the handling logic when the selection range is …
2 parents 31a086d + d88ebdb commit 5b598b6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/inline-code",
3-
"version": "1.5.1",
3+
"version": "1.5.2",
44
"keywords": [
55
"codex editor",
66
"inline",

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,19 @@ export default class InlineCode implements InlineTool {
8989
let termWrapper = this.api.selection.findParentTag(this.tag, InlineCode.CSS) as HTMLElement;
9090

9191
/**
92-
* If start or end of selection is in the highlighted block
92+
* If the start or end of the selection range is within a highlighted block
9393
*/
9494
if (termWrapper) {
9595
this.unwrap(termWrapper);
9696
} else {
97-
this.wrap(range);
97+
const existingCodeTag = range.commonAncestorContainer.parentElement?.querySelector(this.tag);
98+
if (!existingCodeTag) {
99+
this.wrap(range);
100+
}
98101
}
99102
}
100103

101-
/**
104+
/**
102105
* Wrap selection with term-tag
103106
*
104107
* @param {Range} range - selected fragment

0 commit comments

Comments
 (0)