Skip to content

Commit 6c9c243

Browse files
committed
fix(inline-code): Fix the handling logic when the selection range is within a highlighted code block
1 parent 31a086d commit 6c9c243

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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)