Fix context picker: fall back to last user message when input is empty

Previously used the hardcoded string "Notiz" as fallback query, which
returns irrelevant or no results mid-conversation. Now uses the last
user message from the active thread so context is relevant to the chat.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
svemagie
2026-03-04 21:24:59 +01:00
parent 363071f291
commit 0e6287c265
2 changed files with 7 additions and 3 deletions
+3 -1
View File
@@ -325,7 +325,9 @@ ${content}`;
this.setStatus("");
}
async openContextPicker() {
const query = this.inputEl.value.trim() || "Notiz";
var _a, _b, _c, _d;
const lastUserMsg = (_d = (_c = [...(_b = (_a = this.activeThread) == null ? void 0 : _a.messages) != null ? _b : []].reverse().find((m) => m.role === "user")) == null ? void 0 : _c.content) != null ? _d : "";
const query = this.inputEl.value.trim() || lastUserMsg;
this.setStatus("Suche Notizen\u2026");
try {
if (!this.plugin.search.isIndexed())
+4 -2
View File
@@ -406,8 +406,10 @@ export class ChatView extends ItemView {
}
private async openContextPicker(): Promise<void> {
// Simple quick switcher-style: search and add to explicit context
const query = this.inputEl.value.trim() || "Notiz";
const lastUserMsg = [...(this.activeThread?.messages ?? [])]
.reverse()
.find((m) => m.role === "user")?.content ?? "";
const query = this.inputEl.value.trim() || lastUserMsg;
this.setStatus("Suche Notizen…");
try {
if (!this.plugin.search.isIndexed()) await this.plugin.search.buildIndex();