Skip to content

Commit 08e1dde

Browse files
committed
fix(ui5-ai-textarea): add docs and correct samples
adjust samples and test pages to reflect the changes made in #12638
1 parent c9288ff commit 08e1dde

2 files changed

Lines changed: 47 additions & 21 deletions

File tree

packages/ai/test/pages/TextArea.html

Lines changed: 23 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,30 @@ <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+
// Save the stopped generation if there is content
370+
const stoppedValue = textarea.value;
371+
if (stoppedValue.trim()) {
372+
const menuItem = findMenuItemByAction(currentActionInProgress);
373+
const completedLabel = (menuItem && menuItem.dataset.completedLabel)
374+
? menuItem.dataset.completedLabel + " (stopped)"
375+
: "Generation stopped";
376+
377+
versionHistory.push({
378+
value: stoppedValue,
379+
action: currentActionInProgress,
380+
endAction: completedLabel,
381+
timestamp: new Date().toISOString()
382+
});
383+
384+
// Restore the previous content
385+
textarea.value = contentBeforeGeneration;
386+
currentIndexHistory = versionHistory.length - 1;
387+
buildMenuFromConfig();
388+
updateComponentState();
389+
}
390+
371391
currentActionInProgress = null;
372392
textarea.loading = false;
373-
textarea.promptDescription = "";
374-
375-
updateComponentState();
376393
}
377394

378395
function handleVersionChange(event) {

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

Lines changed: 24 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,29 @@ 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+
// Save the stopped generation if there is content
274+
const stoppedValue = textarea.value;
275+
if (stoppedValue.trim()) {
276+
const action = currentActionInProgress || 'generate';
277+
const menuItem = findMenuItemByAction(action);
278+
const completedLabel = (menuItem && menuItem.dataset.completedLabel) ? menuItem.dataset.completedLabel : 'Action completed';
279+
280+
versionHistory.push({
281+
value: stoppedValue,
282+
action,
283+
endAction: completedLabel + " (stopped)",
284+
timestamp: new Date().toISOString()
285+
});
286+
287+
// Restore the previous content
288+
textarea.value = contentBeforeGeneration;
289+
currentIndexHistory = versionHistory.length - 1;
290+
buildMenuFromConfig();
291+
updateComponentState();
292+
}
280293

281-
currentIndexHistory = versionHistory.length - 1;
282294
currentActionInProgress = null;
283-
284-
buildMenuFromConfig();
285-
updateComponentState();
286295
textarea.loading = false;
287296
}
288297

0 commit comments

Comments
 (0)