diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/text/macro-text.component.html b/packages/uhk-web/src/app/components/macro/action-editor/tab/text/macro-text.component.html
index 7f771ba0..a6afd304 100644
--- a/packages/uhk-web/src/app/components/macro/action-editor/tab/text/macro-text.component.html
+++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/text/macro-text.component.html
@@ -1,5 +1,10 @@
Type text
-
+
diff --git a/packages/uhk-web/src/app/components/macro/action-editor/tab/text/macro-text.component.ts b/packages/uhk-web/src/app/components/macro/action-editor/tab/text/macro-text.component.ts
index c8e1d6e5..367ec223 100644
--- a/packages/uhk-web/src/app/components/macro/action-editor/tab/text/macro-text.component.ts
+++ b/packages/uhk-web/src/app/components/macro/action-editor/tab/text/macro-text.component.ts
@@ -11,6 +11,8 @@ import { TextMacroAction } from 'uhk-common';
import { MacroBaseComponent } from '../macro-base.component';
+const NON_ASCII_REGEXP = /[^\x00-\x7F]/g;
+
@Component({
selector: 'macro-text-tab',
templateUrl: './macro-text.component.html',
@@ -36,6 +38,41 @@ export class MacroTextTabComponent extends MacroBaseComponent implements OnInit,
this.macroAction.text = this.input.nativeElement.value;
}
+ /**
+ * Not allow non ascii character
+ * @param $event
+ */
+ onKeydown($event: KeyboardEvent): void {
+ if (new RegExp(NON_ASCII_REGEXP).test($event.key)) {
+ $event.preventDefault();
+ $event.stopPropagation();
+ }
+ }
+
+ /**
+ * Remove non ascii character from clipboard data
+ * @param $event
+ */
+ onPaste($event: ClipboardEvent): void {
+ $event.preventDefault();
+
+ const textarea: HTMLTextAreaElement = this.input.nativeElement;
+ const data = $event.clipboardData.getData('text/plain');
+ const text = data && data.replace(NON_ASCII_REGEXP, '') || '';
+ if (text.length === 0) {
+ return;
+ }
+
+ const value = textarea.value || '';
+ const prefix = value.substr(0, textarea.selectionStart);
+ const end = textarea.selectionEnd;
+ const suffix = value.substr(textarea.selectionEnd);
+ textarea.value = prefix + text + suffix;
+ const correction = end === 0 ? 0 : 1;
+ textarea.selectionStart = textarea.selectionEnd = end + text.length - correction;
+ this.macroAction.text = textarea.value;
+ }
+
isMacroValid = () => !!this.input.nativeElement.value;
private init = () => {