mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-07-03 14:09:06 +02:00
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
@@ -188,6 +188,7 @@ export class AgentChat extends Model {
|
||||
this.sessionTotalDuration = session.totalDuration || 0;
|
||||
if (this.composer) {
|
||||
this.composer.restoreHistory(session.messageHistory || []);
|
||||
console.log("[AgentChat] loaded history:", (session.messageHistory || []).length, "items, composer has:", this.composer.getHistory().length);
|
||||
}
|
||||
this.titleElement.textContent = session.title;
|
||||
this.updateTokenDisplay();
|
||||
@@ -504,6 +505,7 @@ export class AgentChat extends Model {
|
||||
this.messages.push({role: "user", content: text});
|
||||
this.appendUserMessage(text);
|
||||
if (this.composer) { this.composer.pushHistory(text); }
|
||||
this.saveSession().catch(function (e) { console.error(e); });
|
||||
|
||||
this.requestStartTime = Date.now();
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ export function mountComposer(host: HTMLElement, onSend: () => void): ComposerHa
|
||||
|
||||
const history: string[] = [];
|
||||
let historyIdx = -1;
|
||||
let savedDraft = "";
|
||||
|
||||
const updateHighlight = () => {
|
||||
if (!suggestionMenu) { return; }
|
||||
@@ -212,12 +213,15 @@ export function mountComposer(host: HTMLElement, onSend: () => void): ComposerHa
|
||||
return true;
|
||||
}
|
||||
if (event.key === "ArrowUp" && !suggestionMenu) {
|
||||
const navigating = historyIdx >= 0;
|
||||
const isEmpty = _view.state.doc.childCount === 1 &&
|
||||
_view.state.doc.firstChild?.childCount === 0;
|
||||
if (isEmpty && history.length > 0) {
|
||||
if ((navigating || isEmpty) && history.length > 0) {
|
||||
event.preventDefault();
|
||||
if (historyIdx === -1) { historyIdx = history.length - 1; }
|
||||
else if (historyIdx > 0) { historyIdx--; }
|
||||
if (historyIdx === -1) {
|
||||
savedDraft = editor.state.doc.textContent;
|
||||
historyIdx = history.length - 1;
|
||||
} else if (historyIdx > 0) { historyIdx--; }
|
||||
if (historyIdx >= 0) {
|
||||
editor.commands.setContent(history[historyIdx]);
|
||||
}
|
||||
@@ -229,12 +233,17 @@ export function mountComposer(host: HTMLElement, onSend: () => void): ComposerHa
|
||||
historyIdx++;
|
||||
if (historyIdx >= history.length) {
|
||||
historyIdx = -1;
|
||||
editor.commands.clearContent();
|
||||
editor.commands.setContent(savedDraft || "");
|
||||
savedDraft = "";
|
||||
} else {
|
||||
editor.commands.setContent(history[historyIdx]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (historyIdx >= 0 && event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
|
||||
historyIdx = -1;
|
||||
savedDraft = "";
|
||||
}
|
||||
return false;
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user