Skip to content

Commit 61767a0

Browse files
authored
docs(ui5-ai-textarea): add docs and correct samples (#12776)
* fix(ui5-ai-textarea): add docs and correct samples adjust samples and test pages to reflect the changes made in #12638
1 parent 634621d commit 61767a0

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

packages/ai/test/pages/TextArea.html

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ <h1 class="demo-title">AI TextArea Component</h1>
193193
textarea.value = versionHistory[versionIndex].value;
194194
}
195195

196-
textarea.currentVersion = currentIndexHistory;
196+
textarea.currentVersion = currentIndexHistory + 1;
197197
textarea.totalVersions = versionHistory.length;
198198

199199
if (versionHistory[currentIndexHistory]) {
@@ -366,13 +366,27 @@ <h1 class="demo-title">AI TextArea Component</h1>
366366
stopTypingAnimation();
367367
currentGenerationIndex += 1;
368368

369-
// Restore the previous content instead of saving the cancelled action
370-
textarea.value = contentBeforeGeneration;
369+
const stoppedValue = textarea.value;
370+
if (stoppedValue.trim()) {
371+
const menuItem = findMenuItemByAction(currentActionInProgress);
372+
const completedLabel = (menuItem && menuItem.dataset.completedLabel)
373+
? menuItem.dataset.completedLabel + " (stopped)"
374+
: "Generation stopped";
375+
376+
versionHistory.push({
377+
value: stoppedValue,
378+
action: currentActionInProgress,
379+
endAction: completedLabel,
380+
timestamp: new Date().toISOString()
381+
});
382+
383+
currentIndexHistory = versionHistory.length - 1;
384+
buildMenuFromConfig();
385+
updateComponentState();
386+
}
387+
371388
currentActionInProgress = null;
372389
textarea.loading = false;
373-
textarea.promptDescription = "";
374-
375-
updateComponentState();
376390
}
377391

378392
function handleVersionChange(event) {

packages/website/docs/_samples/ai/TextArea/Extended/main.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ let currentIndexHistory = 0;
7272
let currentActionInProgress = null;
7373
let typingInterval = null;
7474
let currentGenerationIndex = 0;
75+
let contentBeforeGeneration = "";
7576

7677
const textarea = document.getElementById('ai-textarea');
7778
const menu = document.getElementById('ai-menu');
@@ -95,7 +96,7 @@ function updateComponentState(versionIndex = null) {
9596
textarea.value = versionHistory[versionIndex].value;
9697
}
9798

98-
textarea.currentVersion = currentIndexHistory;
99+
textarea.currentVersion = currentIndexHistory + 1;
99100
textarea.totalVersions = versionHistory.length;
100101

101102
if (versionHistory[currentIndexHistory]) {
@@ -242,6 +243,7 @@ async function executeAction(action) {
242243
const textKey = menuItem.dataset.textKey || 'en';
243244

244245
saveCurrentVersion();
246+
contentBeforeGeneration = textarea.value;
245247
currentActionInProgress = action;
246248
currentGenerationIndex += 1;
247249
const generationIdForThisRun = currentGenerationIndex;
@@ -267,22 +269,26 @@ function stopGeneration() {
267269

268270
stopTypingAnimation();
269271
currentGenerationIndex += 1;
270-
const action = currentActionInProgress || 'generate';
271-
const menuItem = findMenuItemByAction(action);
272-
const completedLabel = (menuItem && menuItem.dataset.completedLabel) ? menuItem.dataset.completedLabel : 'Action completed';
273-
274-
versionHistory.push({
275-
value: textarea.value,
276-
action,
277-
endAction: completedLabel + " (stopped)",
278-
timestamp: new Date().toISOString()
279-
});
272+
273+
const stoppedValue = textarea.value;
274+
if (stoppedValue.trim()) {
275+
const action = currentActionInProgress || 'generate';
276+
const menuItem = findMenuItemByAction(action);
277+
const completedLabel = (menuItem && menuItem.dataset.completedLabel) ? menuItem.dataset.completedLabel : 'Action completed';
278+
279+
versionHistory.push({
280+
value: stoppedValue,
281+
action,
282+
endAction: completedLabel + " (stopped)",
283+
timestamp: new Date().toISOString()
284+
});
285+
286+
currentIndexHistory = versionHistory.length - 1;
287+
buildMenuFromConfig();
288+
updateComponentState();
289+
}
280290

281-
currentIndexHistory = versionHistory.length - 1;
282291
currentActionInProgress = null;
283-
284-
buildMenuFromConfig();
285-
updateComponentState();
286292
textarea.loading = false;
287293
}
288294

0 commit comments

Comments
 (0)