mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Make khoj obsidian keyboard shortcuts toggle voice chat, chat history
Previously hitting voice chat keybinding would just start voice chat, not end it and just open chat history and not close it. This is unintuitive and different from the equivalent button click behaviors. Fix toggles voice chat on/off and shows/hides chat history when hit Ctrl+Alt+V, Ctrl+Alt+O keybindings in khoj obsidian chat view
This commit is contained in:
@@ -72,6 +72,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
keyPressTimeout: NodeJS.Timeout | null = null;
|
keyPressTimeout: NodeJS.Timeout | null = null;
|
||||||
userMessages: string[] = []; // Store user sent messages for input history cycling
|
userMessages: string[] = []; // Store user sent messages for input history cycling
|
||||||
currentMessageIndex: number = -1; // Track current message index in userMessages array
|
currentMessageIndex: number = -1; // Track current message index in userMessages array
|
||||||
|
voiceChatActive: boolean = false; // Flag to track if voice chat is active
|
||||||
private currentUserInput: string = ""; // Stores the current user input that is being typed in chat
|
private currentUserInput: string = ""; // Stores the current user input that is being typed in chat
|
||||||
private startingMessage: string = this.getLearningMoment();
|
private startingMessage: string = this.getLearningMoment();
|
||||||
chatMessageState: ChatMessageState;
|
chatMessageState: ChatMessageState;
|
||||||
@@ -131,7 +132,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
this.scope = new Scope(this.app.scope);
|
this.scope = new Scope(this.app.scope);
|
||||||
this.scope.register(["Ctrl", "Alt"], 'n', (_) => this.createNewConversation(this.currentAgent));
|
this.scope.register(["Ctrl", "Alt"], 'n', (_) => this.createNewConversation(this.currentAgent));
|
||||||
this.scope.register(["Ctrl", "Alt"], 'o', async (_) => await this.toggleChatSessions());
|
this.scope.register(["Ctrl", "Alt"], 'o', async (_) => await this.toggleChatSessions());
|
||||||
this.scope.register(["Ctrl", "Alt"], 'v', (_) => this.speechToText(new KeyboardEvent('keydown')));
|
this.scope.register(["Ctrl", "Alt"], 'v', (_) => this.speechToText(this.voiceChatActive ? new KeyboardEvent('keyup') : new KeyboardEvent('keydown')));
|
||||||
this.scope.register(["Ctrl"], 'f', (_) => new KhojSearchModal(this.app, this.setting).open());
|
this.scope.register(["Ctrl"], 'f', (_) => new KhojSearchModal(this.app, this.setting).open());
|
||||||
this.scope.register(["Ctrl"], 'r', (_) => { this.activateView(KhojView.SIMILAR); });
|
this.scope.register(["Ctrl"], 'r', (_) => { this.activateView(KhojView.SIMILAR); });
|
||||||
}
|
}
|
||||||
@@ -340,7 +341,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
attr: {
|
attr: {
|
||||||
id: "khoj-transcribe",
|
id: "khoj-transcribe",
|
||||||
class: "khoj-transcribe khoj-input-row-button clickable-icon ",
|
class: "khoj-transcribe khoj-input-row-button clickable-icon ",
|
||||||
title: "Start Voice Chat (Ctrl+Alt+V)",
|
title: "Hold to Voice Chat (Ctrl+Alt+V)",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
transcribe.addEventListener('mousedown', (event) => { this.startSpeechToText(event) });
|
transcribe.addEventListener('mousedown', (event) => { this.startSpeechToText(event) });
|
||||||
@@ -1741,6 +1742,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
|
|
||||||
// Toggle recording
|
// Toggle recording
|
||||||
if (!this.mediaRecorder || this.mediaRecorder.state === 'inactive' || event.type === 'touchstart' || event.type === 'mousedown' || event.type === 'keydown') {
|
if (!this.mediaRecorder || this.mediaRecorder.state === 'inactive' || event.type === 'touchstart' || event.type === 'mousedown' || event.type === 'keydown') {
|
||||||
|
this.voiceChatActive = true;
|
||||||
navigator.mediaDevices
|
navigator.mediaDevices
|
||||||
.getUserMedia({ audio: true })
|
.getUserMedia({ audio: true })
|
||||||
?.then(handleRecording)
|
?.then(handleRecording)
|
||||||
@@ -1748,6 +1750,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
this.flashStatusInChatInput("⛔️ Failed to access microphone");
|
this.flashStatusInChatInput("⛔️ Failed to access microphone");
|
||||||
});
|
});
|
||||||
} else if (this.mediaRecorder?.state === 'recording' || event.type === 'touchend' || event.type === 'touchcancel' || event.type === 'mouseup' || event.type === 'keyup') {
|
} else if (this.mediaRecorder?.state === 'recording' || event.type === 'touchend' || event.type === 'touchcancel' || event.type === 'mouseup' || event.type === 'keyup') {
|
||||||
|
this.voiceChatActive = false;
|
||||||
this.mediaRecorder.stop();
|
this.mediaRecorder.stop();
|
||||||
this.mediaRecorder.stream.getTracks().forEach(track => track.stop());
|
this.mediaRecorder.stream.getTracks().forEach(track => track.stop());
|
||||||
this.mediaRecorder = undefined;
|
this.mediaRecorder = undefined;
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export default class Khoj extends Plugin {
|
|||||||
this.activateView(KhojView.CHAT).then(() => {
|
this.activateView(KhojView.CHAT).then(() => {
|
||||||
const chatView = this.app.workspace.getActiveViewOfType(KhojChatView);
|
const chatView = this.app.workspace.getActiveViewOfType(KhojChatView);
|
||||||
if (chatView) {
|
if (chatView) {
|
||||||
chatView.toggleChatSessions(true);
|
chatView.toggleChatSessions();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -88,8 +88,9 @@ export default class Khoj extends Plugin {
|
|||||||
this.activateView(KhojView.CHAT).then(() => {
|
this.activateView(KhojView.CHAT).then(() => {
|
||||||
const chatView = this.app.workspace.getActiveViewOfType(KhojChatView);
|
const chatView = this.app.workspace.getActiveViewOfType(KhojChatView);
|
||||||
if (chatView) {
|
if (chatView) {
|
||||||
// Trigger speech to text functionality
|
// Toggle speech to text functionality
|
||||||
chatView.speechToText(new KeyboardEvent('keydown'));
|
const toggleEvent = chatView.voiceChatActive ? 'keyup' : 'keydown';
|
||||||
|
chatView.speechToText(new KeyboardEvent(toggleEvent));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user