Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue with file switching and default Tabs #5827

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions apps/remix-ide/src/app/files/fileManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict'
import { saveAs } from 'file-saver'
import JSZip from 'jszip'
Expand Down Expand Up @@ -747,32 +746,13 @@ export default class FileManager extends Plugin {
if (this.currentFile() === file && !this.editor.isDiff) return

const provider = resolved.provider
// Activate the editor tab before opening the file
await this._components.registry.get('tabs').api.activateByTitle('Editor')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no Editor tab

this._deps.config.set('currentFile', file)

this.openedFiles[file] = file

let content = ''
try {
content = await provider.get(file)
} catch (error) {
console.log(error)
throw error
}
try {
// This make sure dependencies are loaded in the editor context.
// This ensure monaco is aware of deps artifacts, so it can provide basic features like "go to" symbols.
await this.editor.handleTypeScriptDependenciesOf(file, content, path => this.readFile(path), path => this.exists(path))
} catch (e) {
console.log('unable to handle TypeScript dependencies of', file)
}
if (provider.isReadOnly(file)) {
await this.editor.openReadOnly(file, content)
} else {
await this.editor.open(file, content)
}
// TODO: Only keep `this.emit` (issue#2210)
await this.syncEditor(file)
this.emit('currentFileChanged', file)
return true
this.emit('openFile', file)
}
}

Expand Down
12 changes: 11 additions & 1 deletion libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Tab {
export interface TabsUIApi {
activateTab: (name: string) => void
active: () => string
activateByTitle: (title: string) => void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should work only with name as this is a key.

}
interface ITabsState {
selectedIndex: number
Expand Down Expand Up @@ -168,11 +169,20 @@ export const TabsUI = (props: TabsUIProps) => {
event.preventDefault()
}

const activateByTitle = (title: string) => {
const index = tabs.current.findIndex((tab) => tab.title === title)
if (index !== -1) {
currentIndexRef.current = index
dispatch({ type: 'SELECT_INDEX', payload: index, ext: getExt(tabs.current[index].name) })
}
}

useEffect(() => {
props.onReady({
activateTab,
active,
setFileDecorations
setFileDecorations,
activateByTitle
})

return () => {
Expand Down