mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
improve selections
This commit is contained in:
parent
cf9eca0564
commit
29f8fa6e1d
1 changed files with 29 additions and 17 deletions
|
|
@ -122,15 +122,21 @@ export type ThreadStreamState = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultThreadAttributes = () => {
|
||||||
const newThreadObject = () => {
|
|
||||||
const now = new Date().toISOString()
|
const now = new Date().toISOString()
|
||||||
return {
|
return {
|
||||||
id: generateUuid(),
|
|
||||||
createdAt: now,
|
createdAt: now,
|
||||||
lastModified: now,
|
lastModified: now,
|
||||||
messages: [],
|
messages: [],
|
||||||
state: defaultThreadState,
|
state: defaultThreadState,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newThreadObject = () => {
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: generateUuid(),
|
||||||
|
...defaultThreadAttributes()
|
||||||
|
|
||||||
} satisfies ChatThreads[string]
|
} satisfies ChatThreads[string]
|
||||||
}
|
}
|
||||||
|
|
@ -240,13 +246,13 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
|
|
||||||
|
|
||||||
// add the current file to the thread being edited
|
// add the current file to the thread being edited
|
||||||
const model = this._codeEditorService.getActiveCodeEditor()?.getModel() ?? null
|
const newModel = this._codeEditorService.getActiveCodeEditor()?.getModel() ?? null
|
||||||
if (!model) { return; }
|
if (!newModel) { return; }
|
||||||
|
|
||||||
const newSelection: StagingSelectionItem = {
|
const newStagingSelection: StagingSelectionItem = {
|
||||||
type: 'File',
|
type: 'File',
|
||||||
fileURI: model.uri,
|
fileURI: newModel.uri,
|
||||||
language: model.getLanguageId(),
|
language: newModel.getLanguageId(),
|
||||||
selectionStr: null,
|
selectionStr: null,
|
||||||
range: null,
|
range: null,
|
||||||
state: { isOpened: false, wasAddedAsCurrentFile: true }
|
state: { isOpened: false, wasAddedAsCurrentFile: true }
|
||||||
|
|
@ -259,15 +265,18 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
|
|
||||||
const oldStagingSelections = this.getCurrentThreadState().stagingSelections || [];
|
const oldStagingSelections = this.getCurrentThreadState().stagingSelections || [];
|
||||||
|
|
||||||
// if the file already exists, do nothing
|
// remove all old selectons that are marked as `wasAddedAsCurrentFile`
|
||||||
const alreadyHasFile = oldStagingSelections.some(s => s.type === 'File' && s.fileURI.toString() === newSelection.fileURI.toString())
|
const newStagingSelections: StagingSelectionItem[] = oldStagingSelections.filter(s => !s.state?.wasAddedAsCurrentFile);
|
||||||
if (alreadyHasFile) { return; }
|
|
||||||
|
|
||||||
// add the file
|
// add the new file if it doesn't exist
|
||||||
const filteredStagingSelections = oldStagingSelections.filter(s => !s.state?.wasAddedAsCurrentFile); // remove all old selectons that were added during a file change
|
const fileIsAdded = oldStagingSelections.some(s => s.type === 'File' && s.fileURI.toString() === newStagingSelection.fileURI.toString())
|
||||||
const newSelections = [...filteredStagingSelections, newSelection];
|
if (!fileIsAdded) {
|
||||||
|
newStagingSelections.push(newStagingSelection)
|
||||||
|
}
|
||||||
|
|
||||||
|
// update thread state with new selections
|
||||||
|
this.setCurrentThreadState({ stagingSelections: newStagingSelections });
|
||||||
|
|
||||||
this.setCurrentThreadState({ stagingSelections: newSelections });
|
|
||||||
|
|
||||||
|
|
||||||
} else { // user is editing a message
|
} else { // user is editing a message
|
||||||
|
|
@ -275,14 +284,14 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
// do nothing. I don't think it feels good to auto-add the current file when you're editing a message.
|
// do nothing. I don't think it feels good to auto-add the current file when you're editing a message.
|
||||||
|
|
||||||
// const oldStagingSelections = this.getCurrentMessageState(focusedMessageIdx).stagingSelections || [];
|
// const oldStagingSelections = this.getCurrentMessageState(focusedMessageIdx).stagingSelections || [];
|
||||||
|
// const newStagingSelections = [...filteredStagingSelections, newSelection];
|
||||||
|
// this.setCurrentMessageState(focusedMessageIdx, { stagingSelections: newSelections });
|
||||||
|
|
||||||
// // if the file already exists, do nothing
|
// // if the file already exists, do nothing
|
||||||
// const alreadyHasFile = oldStagingSelections.some(s => s.type === 'File' && s.fileURI.toString() === newSelection.fileURI.toString())
|
// const alreadyHasFile = oldStagingSelections.some(s => s.type === 'File' && s.fileURI.toString() === newSelection.fileURI.toString())
|
||||||
// if (alreadyHasFile) { return; }
|
// if (alreadyHasFile) { return; }
|
||||||
|
|
||||||
// const filteredStagingSelections = oldStagingSelections.filter(s => !s.state?.wasAddedDuringFileChange); // remove all old selectons that were added during a file change
|
// const filteredStagingSelections = oldStagingSelections.filter(s => !s.state?.wasAddedDuringFileChange); // remove all old selectons that were added during a file change
|
||||||
// const newSelections = [...filteredStagingSelections, newSelection];
|
|
||||||
// this.setCurrentMessageState(focusedMessageIdx, { stagingSelections: newSelections });
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1244,6 +1253,9 @@ class ChatThreadService extends Disposable implements IChatThreadService {
|
||||||
const { allThreads: currentThreads } = this.state
|
const { allThreads: currentThreads } = this.state
|
||||||
for (const threadId in currentThreads) {
|
for (const threadId in currentThreads) {
|
||||||
if (currentThreads[threadId]!.messages.length === 0) {
|
if (currentThreads[threadId]!.messages.length === 0) {
|
||||||
|
// clear the thread
|
||||||
|
currentThreads[threadId]! = { id: currentThreads[threadId]!.id, ...defaultThreadAttributes() }
|
||||||
|
// switch to the thread
|
||||||
this.switchToThread(threadId)
|
this.switchToThread(threadId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue