Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c8a6051
Command to find current buffer in Explorer and select it (#1567)
feltech Jul 15, 2018
0f9f78c
Only dispatch success action if/when selection changed as expected
feltech Jul 15, 2018
bb93210
Open Explorer if it's not visible when executing Locate Current Buffer.
feltech Jul 15, 2018
5dd510f
Remove duplicated `nodePath` function in favour of `getPathForNode`
feltech Jul 15, 2018
aed2f0d
Fix sidebar hiding when locating file in Explorer
feltech Jul 15, 2018
f2611fb
tslint: alphabetize imports
feltech Jul 15, 2018
14a0539
Fix test conflict
feltech Jul 17, 2018
d6a9ad3
Add `selectFileReducer` tests
feltech Jul 17, 2018
3b87da1
Add `selectFileEpic` tests
feltech Jul 18, 2018
dbf3d86
Minor test tidying
feltech Jul 18, 2018
2ae04ba
Add notificationEpic SELECT_FILE_FAIL test
feltech Jul 18, 2018
d22fc95
Merge remote-tracking branch 'upstream/master' into
feltech Jul 19, 2018
20503f0
Add VimNavigator and ExplorerView tests
feltech Jul 19, 2018
96ddb79
Remove unused imports in test + tidy
feltech Jul 20, 2018
0d296d9
Add ExplorerSplit tests
feltech Jul 20, 2018
d463ecd
Add Locate Buffer integration test
feltech Jul 20, 2018
dd864fe
tslint: alphabetise imports
feltech Jul 20, 2018
79a44a1
Merge remote-tracking branch 'upstream/master' into
feltech Jul 21, 2018
640251b
Possibly fix SELECT_FILE on OSX + add logging to isolate problem
feltech Jul 22, 2018
d8d566f
Fix Explorer.LocateBufferTest for symlinked tempdir (i.e. OSX)
feltech Jul 22, 2018
cae10b1
Resolve symlinks before testing if selection is a descendant of works…
feltech Jul 22, 2018
4347354
Fix ExplorerStore tests
feltech Jul 22, 2018
6eee64f
Put symlink-less file to select in the store (for OSX)
feltech Jul 22, 2018
4651cfd
Use temporary workspace for QuickOpenTest
feltech Jul 22, 2018
11d5821
Fix Neovim.CallOniCommands test
feltech Jul 22, 2018
22a6424
Attempt to fix race in PrettierPluginTest on OSX
feltech Jul 23, 2018
b03fff0
Revert "Attempt to fix race in PrettierPluginTest on OSX"
feltech Jul 23, 2018
f492fea
Use temporary workspace for PrettierPluginTest
feltech Jul 23, 2018
9a72c8f
Move UI elment assertion of PrettierPluginTest to the end
feltech Jul 23, 2018
79644b3
Add logging to isolate issue with PrettierPluginTest on OSX
feltech Jul 24, 2018
4da9305
Fix logging to isolate issue with PrettierPluginTest on OSX
feltech Jul 24, 2018
c8195ad
More logging to isolate issue with PrettierPluginTest on OSX
feltech Jul 24, 2018
97f8ad4
Wait for status bar element in PrettierPluginTest on OSX
feltech Jul 24, 2018
487b630
Allow failure to get window count in test afterEach
feltech Jul 24, 2018
be4b914
Fix waiting for status bar element in PrettierPluginTest on OSX
feltech Jul 24, 2018
2c676b8
Remove before/afterEach from runInProcTest to enable retries
feltech Jul 24, 2018
27305e6
Add some logs when oni is close after test
feltech Jul 24, 2018
778b471
Add a couple of mocha flags that may stabalise tests
feltech Jul 24, 2018
0db437e
Remove debug logs + tidy
feltech Jul 25, 2018
3b2c6f4
Tolerate failure to get window count when stopping Oni
feltech Jul 25, 2018
d6b4a29
Add a retry to WindowsInstallerTests
feltech Jul 25, 2018
7379f18
Revert "Add a retry to WindowsInstallerTests"
feltech Jul 25, 2018
dc045ab
Remove pointless mocha flags
feltech Jul 25, 2018
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
14 changes: 14 additions & 0 deletions browser/src/Services/Explorer/ExplorerSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ export const isPathExpanded = (state: IExplorerState, pathToCheck: string): bool
return !!state.expandedFolders[pathToCheck]
}

/**
Copy link
Member

@akinsho akinsho Jul 15, 2018

Choose a reason for hiding this comment

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

@feltech a version of this same functionality already exists in ExplorerStore.ts maybe you could import that and use it instead

* Extract path component from an ExplorerNode.
*/
export const nodePath = (node: ExplorerNode) => {
switch (node.type) {
case "file":
return (node as IFileNode).filePath
case "folder":
return (node as IFolderNode).folderPath
default:
return node.name
}
}

export const mapStateToNodeList = (state: IExplorerState): ExplorerNode[] => {
let ret: ExplorerNode[] = []

Expand Down
21 changes: 21 additions & 0 deletions browser/src/Services/Explorer/ExplorerSplit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ export class ExplorerSplit {
rootPath: this._workspace.activeWorkspace,
})
}

this._commandManager.registerCommand(
new CallbackCommand(
"explorer.locate.buffer",
"Explorer: Locate Current Buffer",
"Locate current buffer in file tree",
() => this._locateFile(this._editorManager.activeEditor.activeBuffer.filePath),
),
)
}

public enter(): void {
Expand Down Expand Up @@ -223,6 +232,14 @@ export class ExplorerSplit {

private _onSelectionChanged(id: string): void {
this._selectedId = id
// If we are trying to select a file, check if it's now selected, and if so trigger success.
const fileToSelect: string = this._store.getState().fileToSelect
if (fileToSelect) {
const selectedPath: string = ExplorerSelectors.nodePath(this._getSelectedItem())
if (selectedPath === fileToSelect) {
this._store.dispatch({ type: "SELECT_FILE_SUCCESS" })
}
}
}

private _onOpenItem(id?: string): void {
Expand Down Expand Up @@ -282,6 +299,10 @@ export class ExplorerSplit {
return parentNode
}

private _locateFile = (filePath: string) => {
this._store.dispatch({ type: "SELECT_FILE", filePath })
}

private _renameItem = () => {
const selected = this._getSelectedItem()
if (!selected) {
Expand Down
73 changes: 72 additions & 1 deletion browser/src/Services/Explorer/ExplorerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ export interface IExplorerState {
rootFolder: IFolderState

expandedFolders: ExpandedFolders

fileToSelect: string
hasFocus: boolean
register: IRegisterState
}

export const DefaultExplorerState: IExplorerState = {
rootFolder: null,
expandedFolders: {},
fileToSelect: null,
hasFocus: false,
register: DefaultRegisterState,
}
Expand Down Expand Up @@ -192,6 +193,25 @@ export interface IExpandDirectoryResult {
children: FolderOrFile[]
}

export interface ISelectFileAction {
type: "SELECT_FILE"
filePath: string
}

export interface ISelectFilePendingAction {
type: "SELECT_FILE_PENDING"
filePath: string
}

export interface ISelectFileSuccessAction {
type: "SELECT_FILE_SUCCESS"
}

export interface ISelectFileFailAction {
type: "SELECT_FILE_FAIL"
reason: string
}

export interface IEnterAction {
type: "ENTER"
}
Expand Down Expand Up @@ -308,6 +328,10 @@ export type ExplorerAction =
| ICreateNodeCommitAction
| ICreateNodeSuccessAction
| INotificationSentAction
| ISelectFileAction
| ISelectFilePendingAction
| ISelectFileSuccessAction
| ISelectFileFailAction

// Helper functions for Updating state ========================================================
export const removePastedNode = (nodeArray: ExplorerNode[], ids: string[]): ExplorerNode[] =>
Expand Down Expand Up @@ -613,6 +637,20 @@ export const hasFocusReducer: Reducer<boolean> = (
}
}

export const selectFileReducer: Reducer<string> = (
state: string = null,
action: ExplorerAction,
) => {
switch (action.type) {
case "SELECT_FILE_PENDING":
return action.filePath
case "SELECT_FILE_SUCCESS":
return null
default:
return state
}
}

export const reducer: Reducer<IExplorerState> = (
state: IExplorerState = DefaultExplorerState,
action: ExplorerAction,
Expand All @@ -622,6 +660,7 @@ export const reducer: Reducer<IExplorerState> = (
hasFocus: hasFocusReducer(state.hasFocus, action),
rootFolder: rootFolderReducer(state.rootFolder, action),
expandedFolders: expandedFolderReducer(state.expandedFolders, action),
fileToSelect: selectFileReducer(state.fileToSelect, action),
register: yankRegisterReducer(state.register, action),
}
}
Expand Down Expand Up @@ -920,6 +959,35 @@ const expandDirectoryEpic: ExplorerEpic = (action$, store, { fileSystem }) =>
return Actions.expandDirectoryResult(pathToExpand, sortedFilesAndFolders)
})

export const selectFileEpic: ExplorerEpic = (action$, store, { fileSystem }) =>
action$.ofType("SELECT_FILE").mergeMap(({ filePath }: ISelectFileAction): ExplorerAction[] => {
const rootPath = store.getState().rootFolder.fullPath
// Normalize, e.g. to remove trailing slash so that subsequent string comparisons work.
filePath = path.format(path.parse(path.normalize(filePath)))
// Can only select files in the workspace.
if (!filePath.startsWith(rootPath)) {
const failure: ISelectFileFailAction = {
type: "SELECT_FILE_FAIL",
reason: `File is not in workspace: ${filePath}`,
}
return [failure]
}
const relDirectoryPath = path.relative(rootPath, path.dirname(filePath))
const directories = relDirectoryPath.split(path.sep)
const actions = []

// Expand each directory in turn from the project root down to the file we want.
for (let dirNum = 1; dirNum <= directories.length; dirNum++) {
const relParentDirectoryPath = directories.slice(0, dirNum).join(path.sep)
const parentDirectoryPath = path.join(rootPath, relParentDirectoryPath)
actions.push(Actions.expandDirectory(parentDirectoryPath))
}
// Update the state with the file path we want the VimNaviator to select.
const pending: ISelectFilePendingAction = { type: "SELECT_FILE_PENDING", filePath }
actions.push(pending)
return actions
})

export const createNodeEpic: ExplorerEpic = (action$, store, { fileSystem }) =>
action$.ofType("CREATE_NODE_COMMIT").mergeMap(({ name }: ICreateNodeCommitAction) => {
const {
Expand All @@ -946,6 +1014,7 @@ export const notificationEpic: ExplorerEpic = (action$, store, { notifications }
"PASTE_FAIL",
"DELETE_FAIL",
"CREATE_NODE_FAIL",
"SELECT_FILE_FAIL",
)
.map(action => {
switch (action.type) {
Expand Down Expand Up @@ -985,6 +1054,7 @@ export const notificationEpic: ExplorerEpic = (action$, store, { notifications }
case "DELETE_FAIL":
case "RENAME_FAIL":
case "CREATE_NODE_FAIL":
case "SELECT_FILE_FAIL":
const [type] = action.type.split("_")
errorNotification({
type,
Expand Down Expand Up @@ -1019,6 +1089,7 @@ export const createStore = ({
undoEpic,
deleteEpic,
expandDirectoryEpic,
selectFileEpic,
notificationEpic,
),
{ dependencies: { fileSystem, notifications } },
Expand Down
21 changes: 20 additions & 1 deletion browser/src/Services/Explorer/ExplorerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export interface IExplorerViewProps extends IExplorerViewContainerProps {
nodes: ExplorerSelectors.ExplorerNode[]
isActive: boolean
updated: string[]
idToSelect: string
}

import { SidebarEmptyPaneView } from "./../../UI/components/SidebarEmptyPaneView"
Expand All @@ -293,6 +294,7 @@ export class ExplorerView extends React.PureComponent<IExplorerViewProps, {}> {
<VimNavigator
ids={ids}
active={this.props.isActive && !this.props.isRenaming && !this.props.isCreating}
idToSelect={this.props.idToSelect}
onSelectionChanged={this.props.onSelectionChanged}
onSelected={id => this.props.onClick(id)}
render={(selectedId: string) => {
Expand Down Expand Up @@ -334,13 +336,30 @@ const mapStateToProps = (
const yanked = state.register.yank.map(node => node.id)
const {
register: { updated, rename },
fileToSelect,
} = state

const nodes: ExplorerSelectors.ExplorerNode[] = ExplorerSelectors.mapStateToNodeList(state)

let idToSelect: string = null
// If parent has told us to select a file, attempt to convert the file path into a node ID.
if (fileToSelect) {
const [nodeToSelect] = nodes.filter((node: ExplorerSelectors.ExplorerNode) => {
const nodePath: string = ExplorerSelectors.nodePath(node)
return nodePath === fileToSelect
})
if (nodeToSelect) {
idToSelect = nodeToSelect.id
}
}

return {
...containerProps,
isActive: state.hasFocus,
nodes: ExplorerSelectors.mapStateToNodeList(state),
nodes,
updated,
yanked,
idToSelect,
isCreating: state.register.create.active,
isRenaming: rename.active && rename.target,
}
Expand Down
26 changes: 16 additions & 10 deletions browser/src/UI/components/VimNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface IVimNavigatorProps {
render: (selectedId: string) => JSX.Element

style?: React.CSSProperties
idToSelect?: string
}

export interface IVimNavigatorState {
Expand Down Expand Up @@ -127,16 +128,7 @@ export class VimNavigator extends React.PureComponent<IVimNavigatorProps, IVimNa

this._activeBinding.onCursorMoved.subscribe(newValue => {
Log.info("[VimNavigator::onCursorMoved] - " + newValue)

if (newValue !== this.state.selectedId) {
this.setState({
selectedId: newValue,
})

if (this.props.onSelectionChanged) {
this.props.onSelectionChanged(newValue)
}
}
this._maybeUpdateSelection(newValue)
})

await this._activeBinding.setItems(this.props.ids, this.state.selectedId)
Expand All @@ -146,5 +138,19 @@ export class VimNavigator extends React.PureComponent<IVimNavigatorProps, IVimNa
} else if (!props.active && this._activeBinding) {
this._releaseBinding()
}

if (props.idToSelect) {
this._maybeUpdateSelection(props.idToSelect)
}
}

private _maybeUpdateSelection(id: string) {
if (id !== this.state.selectedId) {
this.setState({ selectedId: id })

if (this.props.onSelectionChanged) {
this.props.onSelectionChanged(id)
}
}
}
}