Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Dec 5, 2024
1 parent 579ab49 commit 0e45b0c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions assets/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@
this.showModal = 'list-sessions'
} else if (event.shiftKey && event.key === "Escape") {
event.preventDefault();
this.$refs?.input?.focus();
this.focusInput();
} else if (this.showModal && event.key === "Escape") {
event.preventDefault();
this.showModal = "";
Expand Down Expand Up @@ -1122,7 +1122,8 @@
Object.assign(session, sessionData);
} else {
this.sessions.unshift({
id: this.sessions.length,
id: randomUUID(),
createdAt: Date.now(),
...sessionData,
});
}
Expand All @@ -1137,12 +1138,15 @@
this.sessionMode = false;
this.sessionTitle = "";
this.selectSessionId = null;

this.focusInput();
},

handleSelectSession(id) {
const session = this.sessions.find(v => v.id === id);
if (!session || id === this.selectSessionId) {
this.showModal = "";
this.focusInput();
return;
}
this.handleNewChat();
Expand Down Expand Up @@ -1180,6 +1184,10 @@
$input.style.height = $input.scrollHeight + 'px';
},

focusInput() {
this.$refs?.input?.focus();
},

async ask() {
this.askAbortController = new AbortController();
this.shouldScrollChatBodyToBottom = true;
Expand Down Expand Up @@ -1507,6 +1515,14 @@
return chunks;
}

function randomUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}

function renderMarkdown(text, error = '') {
return marked.marked(text) + (error ? `<pre class="error">${error}</pre>` : '');
}
Expand Down

0 comments on commit 0e45b0c

Please sign in to comment.