Skip to content

Commit 422ffd6

Browse files
fix(core): insert column var at caret position
GH-9
1 parent 0500568 commit 422ffd6

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

projects/workflows-creator/src/lib/builder/group/group.component.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
emailInput: emailInput,
145145
appendEmailBody: appendEmailBody,
146146
setFocusKey: setFocusKey,
147-
hide: hidePopper()
147+
hide: hidePopper(),
148+
setFocusOutPos: setFocusOutPos
148149
}
149150
"
150151
></ng-container>
@@ -284,6 +285,7 @@
284285
let-appendEmailBody="appendEmailBody"
285286
let-setFocusKey="setFocusKey"
286287
let-hide="hide"
288+
let-setFocusOutPos="setFocusOutPos"
287289
>
288290
<div class="email-template" (document:click)="hide()">
289291
<input
@@ -292,14 +294,15 @@
292294
id="email-subject"
293295
autofocus
294296
(focus)="setFocusKey(emailInput, 'subject')"
297+
(focusout)="setFocusOutPos(emailInput, $event.target.selectionStart)"
295298
[placeholder]="typeSubjectPlaceholder"
296299
[(ngModel)]="emailInput.subject"
297300
/>
298301
<textarea
299302
[placeholder]="typeEmailPlaceholder"
300303
id="email-body"
301304
class="email-input email-body-input"
302-
(focus)="setFocusKey(emailInput, 'body')"
305+
(focusout)="setFocusOutPos(emailInput, $event.target.selectionStart)"
303306
[(ngModel)]="emailInput.body"
304307
></textarea>
305308
<div class="auto-populate">
@@ -315,7 +318,7 @@
315318
(click)="callback(emailInput)"
316319
[disabled]="!emailInput.subject || !emailInput.body"
317320
>
318-
{{ localizedStringKeys.SetLbl | localization }}
321+
{{ setLbl }}
319322
</button>
320323
</div>
321324
</div>

projects/workflows-creator/src/lib/builder/group/group.component.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
103103
subject: '',
104104
body: '',
105105
focusKey: '',
106+
caretPos: 0,
106107
};
107108
dropdownSettings: IDropdownSettings = {
108109
singleSelection: false,
@@ -134,6 +135,9 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
134135

135136
typeSubjectPlaceholder = '';
136137
typeEmailPlaceholder = '';
138+
doThisLbl = '';
139+
whenThisHappensLbl = '';
140+
setLbl = '';
137141

138142
localizedStringKeys = LocalizedStringKeys;
139143

@@ -261,11 +265,21 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
261265
*/
262266
appendEmailBody(item: Select, emailInput: EmailInput) {
263267
if (emailInput.focusKey === 'subject') {
264-
emailInput.subject += ` ${item.value}`;
268+
emailInput.subject = [
269+
emailInput.subject.slice(0, emailInput.caretPos),
270+
`${item.value}`,
271+
emailInput.subject.slice(emailInput.caretPos),
272+
].join('');
265273
}
266274
if (emailInput.focusKey === 'body') {
267-
emailInput.body += ` ${item.value}`;
275+
emailInput.body = [
276+
emailInput.body.slice(0, emailInput.caretPos),
277+
`${item.value}`,
278+
emailInput.body.slice(emailInput.caretPos),
279+
].join('');
268280
}
281+
282+
emailInput.caretPos += `${item.value}`.length;
269283
}
270284

271285
/**
@@ -278,6 +292,14 @@ export class GroupComponent<E> implements OnInit, AfterViewInit {
278292
emailInput.focusKey = key;
279293
}
280294

295+
/**
296+
* @emailInput this is the object that contains the email input
297+
* @caretPosition pos caret position
298+
*/
299+
setFocusOutPos(emailInput: EmailInput, caretPosition: number) {
300+
emailInput.caretPos = caretPosition;
301+
}
302+
281303
/**
282304
* If the type is an action, set the node list to the actions, otherwise if the type is an event, set
283305
* the node list to the trigger events if there is only one event group and no children, otherwise

projects/workflows-creator/src/lib/types/base.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export type EmailInput = {
172172
subject: string;
173173
body: string;
174174
focusKey: string;
175+
caretPos: number;
175176
};
176177

177178
/**

0 commit comments

Comments
 (0)