Skip to content

Commit

Permalink
Patch continue and Cmd+k fix (#348)
Browse files Browse the repository at this point in the history
* maybe patches the continue infinite loop bug

* Fixes cmd+k issue

* Ran prettier
  • Loading branch information
Sanger2000 committed Mar 28, 2023
1 parent f613693 commit c4bfac8
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 42 deletions.
21 changes: 12 additions & 9 deletions src/components/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function Tab({ tid }: { tid: number }) {
function revertTabsChildrenEvents() {
if (tabDiv.current) {
tabDiv.current.style.background = ''
const tabs = tabDiv.current.parentElement?.getElementsByClassName('tab')
const tabs =
tabDiv.current.parentElement?.getElementsByClassName('tab')
for (const tab of tabs || []) {
tab.childNodes.forEach((child) => {
const childElement = child as HTMLElement
Expand Down Expand Up @@ -113,7 +114,6 @@ function Tab({ tid }: { tid: number }) {
)
}


function TabPath({ tid }: { tid: number }) {
const tab = useAppSelector(getTab(tid))
const filePath = useAppSelector(getRelativeFilePath(tab.fileId))
Expand Down Expand Up @@ -144,12 +144,15 @@ function TabPath({ tid }: { tid: number }) {
)
}

function TabRemainder({children}: {children: React.ReactNode}) {
function TabRemainder({ children }: { children: React.ReactNode }) {
const containerDiv = useRef<HTMLDivElement>(null)
function revertTabsChildrenEvents() {
if (containerDiv.current) {
containerDiv.current.style.background = ''
const tabs = containerDiv.current.parentElement?.getElementsByClassName('tab')
const tabs =
containerDiv.current.parentElement?.getElementsByClassName(
'tab'
)
for (const tab of tabs || []) {
tab.childNodes.forEach((child) => {
const childElement = child as HTMLElement
Expand All @@ -159,13 +162,14 @@ function TabRemainder({children}: {children: React.ReactNode}) {
}
}
return (
<div
className='w-full'
<div
className="w-full"
ref={containerDiv}
onDragOver={(event) => {
event.preventDefault()
if (containerDiv.current) {
containerDiv.current.style.background = 'rgba(255, 255, 255, 0.3)'
containerDiv.current.style.background =
'rgba(255, 255, 255, 0.3)'
containerDiv.current.childNodes.forEach((child) => {
const childElement = child as HTMLElement
childElement.style.pointerEvents = 'none' // we don't want onDragLeave event for tab children while reordering
Expand All @@ -182,7 +186,7 @@ function TabRemainder({children}: {children: React.ReactNode}) {
event.preventDefault()
revertTabsChildrenEvents() // revert for new pane
}}
>
>
{children}
</div>
)
Expand Down Expand Up @@ -274,7 +278,6 @@ export function TabBar({
)}
</TabRemainder>
</div>

</div>

{activeTabId != null ? <TabPath tid={activeTabId} /> : null}
Expand Down
11 changes: 5 additions & 6 deletions src/components/terminal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useRef } from 'react'
import { Terminal } from 'xterm'
import { FitAddon } from 'xterm-addon-fit'
import { WebLinksAddon } from 'xterm-addon-web-links';
import { WebLinksAddon } from 'xterm-addon-web-links'
import 'xterm/css/xterm.css'
import { useAppSelector, useAppDispatch } from '../app/hooks'
import { FullState } from '../features/window/state'
Expand All @@ -14,12 +14,12 @@ export function XTermComponent({ height }: { height: number }) {
const terminalRef = useRef<HTMLDivElement>(null)
const terminal = useRef<Terminal | null>(null)
const fitAddon = useRef<FitAddon>(new FitAddon())
const webLinksAddon = useRef<WebLinksAddon>(new WebLinksAddon(
(event: MouseEvent, url: string) => {
const webLinksAddon = useRef<WebLinksAddon>(
new WebLinksAddon((event: MouseEvent, url: string) => {
event.preventDefault()
connector.terminalClickLink(url)
},
))
})
)

const handleIncomingData = (e: any, data: any) => {
terminal.current!.write(data)
Expand Down Expand Up @@ -52,7 +52,6 @@ export function XTermComponent({ height }: { height: number }) {
terminal.current.onData((e) => {
connector.terminalInto(e)
})


connector.registerIncData(handleIncomingData)

Expand Down
18 changes: 16 additions & 2 deletions src/features/chat/chatSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export const chatSlice = createSlice({
newResponse(
chatState: ChatState,
action: PayloadAction<{
type: BotMessageType,
useDiagnostics?: boolean | number,
type: BotMessageType
useDiagnostics?: boolean | number
}>
) {
if (action.payload.type === 'markdown') {
Expand Down Expand Up @@ -491,6 +491,19 @@ export const chatSlice = createSlice({
// Bad - I added lots of tech debt today and will fix later
lastBotMessage.maxOrigLine = action.payload
},
setHitTokenLimit(
chatState: ChatState,
action: PayloadAction<{
conversationId: string
hitTokenLimit: boolean
}>
) {
const lastBotMessage = getLastBotMessage(
chatState,
action.payload.conversationId
)!
lastBotMessage.hitTokenLimit = action.payload.hitTokenLimit
},
moveCommandBarHistory(
chatState: ChatState,
action: PayloadAction<'up' | 'down'>
Expand Down Expand Up @@ -560,6 +573,7 @@ export const {
startNewMessage,
doSetMessages,
doSetChatState,
setHitTokenLimit,
_submitCommandBar: dummySubmitCommandBar,
// Bad - I added tech debt and will fix later
setMaxOrigLine,
Expand Down
23 changes: 15 additions & 8 deletions src/features/chat/chatThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
setChatOpen,
setCurrentDraftMessage,
setGenerating,
setHitTokenLimit,
startNewMessage,
toggleChatHistory,
tokenLimitInterrupt,
Expand Down Expand Up @@ -519,6 +520,7 @@ export const continueGeneration = createAsyncThunk(
dispatch(openError(null))
dispatch(interruptGeneration(null))
}
dispatch(setHitTokenLimit({ conversationId, hitTokenLimit: false }))
}
}
)
Expand Down Expand Up @@ -799,7 +801,12 @@ export const streamResponse = createAsyncThunk(
const processResponse = async () => {
let { value, buffer } = await getVariable('', 'type')
checkSend()
dispatch(newResponse({ type: value.trim() as BotMessageType, useDiagnostics }))
dispatch(
newResponse({
type: value.trim() as BotMessageType,
useDiagnostics,
})
)
await sendBody(''!, value.trim())
if (value.trim() == 'location') {
const state = <FullState>getState()
Expand Down Expand Up @@ -1322,13 +1329,13 @@ export const pressAICommand = createAsyncThunk(
}
return
case 'k':
if (chatState.chatIsOpen && lastBotMessage?.finished) {
if (editorView) {
// When there is an editorView, we dispatch something
dispatch(changeMsgType('chat_edit'))
dispatch(changeDraftMsgType('chat_edit'))
}
} else if (editorView) {
// if (chatState.chatIsOpen && lastBotMessage?.finished) {
// if (editorView) {
// // When there is an editorView, we dispatch something
// dispatch(changeMsgType('chat_edit'))
// dispatch(changeDraftMsgType('chat_edit'))
// }
if (editorView) {
const selPos = getSelectedPos(editorView)
const selection = editorView.state.selection.main
editorView.dispatch({
Expand Down
6 changes: 5 additions & 1 deletion src/features/globalSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,11 @@ const globalSlice = createSlice({
},
moveDraggingTabToPane(
stobj: Object,
action: PayloadAction<{ paneId: number; hoverState: HoverState, tabPosition: number }>
action: PayloadAction<{
paneId: number
hoverState: HoverState
tabPosition: number
}>
) {
const state = <State>stobj
const { paneId, hoverState, tabPosition } = action.payload
Expand Down
35 changes: 21 additions & 14 deletions src/features/window/paneUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,25 @@ export function insertFirstPane(state: State) {
return paneId
}

export function doMoveTabToPane(state: State, tabId: number, paneId: number, tabPosition?: number) {
export function doMoveTabToPane(
state: State,
tabId: number,
paneId: number,
tabPosition?: number
) {
const oldPaneId = state.tabs[tabId].paneId
if (oldPaneId == null) return
const newPane = state.paneState.byIds[paneId]
const newPane = state.paneState.byIds[paneId]
const tab = state.tabs[tabId]

const isNewPane = oldPaneId !== paneId;
const maybeTabId = newPane.tabIds.find(tabId => state.tabs[tabId].fileId === tab.fileId)
if ((maybeTabId != null) && isNewPane) {
deleteTab(state, tabId);
setActiveTab(state, maybeTabId);
return;
const isNewPane = oldPaneId !== paneId
const maybeTabId = newPane.tabIds.find(
(tabId) => state.tabs[tabId].fileId === tab.fileId
)
if (maybeTabId != null && isNewPane) {
deleteTab(state, tabId)
setActiveTab(state, maybeTabId)
return
}

const oldPane = state.paneState.byIds[oldPaneId]
Expand All @@ -268,14 +275,14 @@ export function doMoveTabToPane(state: State, tabId: number, paneId: number, tab
setActiveTab(state, oldPane.tabIds[newIndex])
}
oldPane.tabIds.splice(oldPane.tabIds.indexOf(tabId), 1)

if (tabPosition !== undefined) {
if (isNewPane) {
tabPosition += 1 // adding to new pane the tabs count increases along with the position
}
newPane.tabIds.splice(tabPosition, 0, tabId)
if (isNewPane) {
tabPosition += 1 // adding to new pane the tabs count increases along with the position
}
newPane.tabIds.splice(tabPosition, 0, tabId)
} else {
newPane.tabIds.push(tabId)
newPane.tabIds.push(tabId)
}

setPaneActive(state, paneId)
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ const createWindow = () => {

// click on the terminal link
ipcMain.handle('terminal-click-link', (event, data) => {
shell.openExternal(data);
shell.openExternal(data)
})

setupLSPs(store)
Expand Down
3 changes: 2 additions & 1 deletion src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ const electronConnector = {
ipcRenderer.removeListener('terminal-incData', callback)
},
terminalInto: (data: any) => ipcRenderer.invoke('terminal-into', data),
terminalClickLink: (data: any) => ipcRenderer.invoke('terminal-click-link', data),
terminalClickLink: (data: any) =>
ipcRenderer.invoke('terminal-click-link', data),
terminalResize: (data: any) => ipcRenderer.invoke('terminal-resize', data),

registerFileWasAdded: (callback: Callback) =>
Expand Down

0 comments on commit c4bfac8

Please sign in to comment.