Skip to content

Commit 04b26dd

Browse files
authored
fix: sanitize the description of the keymap (#2352)
* fix: sanitize the description of the keymap Also fixes the immutability of the state * fix: remove br conversion * fix: keep new lines
1 parent c8a650b commit 04b26dd

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

packages/uhk-web/src/app/components/editable-text/editable-text.component.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
<span *ngIf="showText"
88
class="editable">
99
<span (click)="editText()"
10-
[innerHtml]="displayText"></span>
10+
>
11+
<ng-container *ngFor="let line of displayLines">{{line}}<br></ng-container>
12+
</span>
1113
</span>
1214
</div>
1315

packages/uhk-web/src/app/components/editable-text/editable-text.component.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ export class EditableTextComponent implements ControlValueAccessor {
2121
return !this.text || this.text.trim().length === 0;
2222
}
2323

24-
get displayText(): string {
25-
return this.text && this.text.replace(/\n/g, '<br>');
24+
get displayLines(): string[] {
25+
if (!this.text) {
26+
return [];
27+
}
28+
29+
return this.text.split('\n');
2630
}
2731

2832
constructor(private cdr: ChangeDetectorRef) {

packages/uhk-web/src/app/store/reducers/user-configuration.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,12 @@ export function reducer(
893893
const userConfiguration: UserConfiguration = Object.assign(new UserConfiguration(), state.userConfiguration);
894894
userConfiguration.keymaps = state.userConfiguration.keymaps.map(keymap => {
895895
if (keymap.abbreviation === data.abbr) {
896-
keymap.description = data.description;
896+
const newKeymap = new Keymap(keymap);
897+
newKeymap.description = data.description;
898+
899+
return newKeymap;
897900
}
901+
898902
return keymap;
899903
});
900904

0 commit comments

Comments
 (0)