Skip to content

Commit c691d30

Browse files
committed
fix(links): preserve relative URLs in link editor (#359)
Use getAttribute('href') instead of .href property to preserve relative URLs when editing existing links. The .href property returns absolute URL with hostname, while getAttribute preserves the original relative path. Also removed debug console.log statement from focus() method (#324). Fixes #359 Fixes #324
1 parent 774a97d commit c691d30

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

projects/angular-editor/src/lib/ae-toolbar/ae-toolbar.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,10 @@ export class AeToolbarComponent {
260260
const selection = this.editorService.savedSelection;
261261
if (selection && selection.commonAncestorContainer.parentElement.nodeName === 'A') {
262262
const parent = selection.commonAncestorContainer.parentElement as HTMLAnchorElement;
263-
if (parent.href !== '') {
264-
url = parent.href;
263+
// Use getAttribute to preserve relative URLs instead of href which returns absolute URL
264+
const href = parent.getAttribute('href');
265+
if (href !== '' && href !== null) {
266+
url = href;
265267
}
266268
}
267269
url = prompt('Insert URL link', url);
@@ -380,6 +382,5 @@ export class AeToolbarComponent {
380382

381383
focus() {
382384
this.execute.emit('focus');
383-
console.log('focused');
384385
}
385386
}

0 commit comments

Comments
 (0)