diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 97cd6e1..c204ed7 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -264,6 +264,13 @@ export class AppComponent { const openTag = tag.replace(/<\/[a-z]+>.*$/, ''); // const closeTag = tag.match(/<\/[a-z]+>/)?.[0] ?? ''; // newValue = before + openTag + selected + closeTag + after; + } else if (tag.length > 1 && tag.length % 2 === 0) { + const middle = tag.length / 2; + const openTag = tag.slice(0, middle); + const closeTag = tag.slice(middle); + newValue = before + openTag + selected + closeTag + after; + } else { + newValue = before + tag + selected + after; } break; } diff --git a/tests/app/app.component.spec.ts b/tests/app/app.component.spec.ts index bcbed47..7ef2795 100644 --- a/tests/app/app.component.spec.ts +++ b/tests/app/app.component.spec.ts @@ -75,6 +75,23 @@ describe('AppComponent', () => { expect(component.inputValue()).toBe('hello'); }); + it('should wrap selected text with inline code markers', () => { + component.inputValue.set('hello'); + component.selectedText.set('ell'); + + fixture.detectChanges(); + + const textarea = fixture.nativeElement.querySelector('textarea') as HTMLTextAreaElement; + + textarea.value = 'hello'; + textarea.selectionStart = 1; + textarea.selectionEnd = 4; + + component.addElement('``', 'between'); + + expect(component.inputValue()).toBe('h`ell`o'); + }); + it('should wrap selected text to uppercase', () => { component.inputValue.set('hello'); component.selectedText.set('hello');