Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Open multiple files in tabs/splits. (#526)
Browse files Browse the repository at this point in the history
* Swapped split and tab open to allow multiple file selections at once.

* Swaps launch.json to use the .cmd file when in a Windows enviroment.

Based on the code from https://code.visualstudio.com/updates/v1_6#_launch-configuration-supports-npm-and-other-tools.

* Started moving code over to the renderer process, to add robust file checks.

* Add more thorough check to opening of multiple files.

* Reverted changes for splits.

* Move VimL logic into the Oni Core plugin.
  • Loading branch information
CrossR authored and extr0py committed Jul 12, 2017
1 parent b241475 commit 2daad92
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/main.js",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"runtimeArgs": [
"--enable-logging"
],
Expand All @@ -21,6 +24,9 @@
"type": "chrome", // <-- requires Extension "Debugger for Chrome"
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"runtimeArgs": [
"--enable-logging",
"${workspaceRoot}/main.js"
Expand Down
8 changes: 5 additions & 3 deletions Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const buildMenu = (mainWindow, loadInit) => {

const executeVimCommand = (command) => mainWindow.webContents.send("menu-item-click", command)

const executeVimCommandForMultipleFiles = (command, files) => mainWindow.webContents.send("open-files", command, files)

const executeOniCommand = (command) => mainWindow.webContents.send("execute-command", command)

const executeVimCommandForFiles = (command, files) => {
Expand Down Expand Up @@ -57,16 +59,16 @@ const buildMenu = (mainWindow, loadInit) => {
{
label: 'Split Open...',
click: (item, focusedWindow) => {
dialog.showOpenDialog(mainWindow, ['openFile'], (files) => {
dialog.showOpenDialog(mainWindow, 'openFile', (files) => {
executeVimCommandForFiles(":sp", files)
})
}
},
{
label: 'Tab Open...',
click: (item, focusedWindow) => {
dialog.showOpenDialog(mainWindow, ['openFile'], (files) => {
executeVimCommandForFiles(":tabnew", files)
dialog.showOpenDialog(mainWindow, {properties: ['openFile', 'multiSelections']}, (files) => {
executeVimCommandForMultipleFiles(":tabnew ", files)
})
}
},
Expand Down
19 changes: 17 additions & 2 deletions browser/src/Editor/NeovimEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,21 @@ export class NeovimEditor implements IEditor {
}
})

const normalizePath = (fileName: string) => fileName.split("\\").join("/")

const openFiles = async (files: string[], action: string) => {

await this._neovimInstance.callFunction("OniOpenFile", [action, files[0]])

for (let i = 1; i < files.length; i++) {
this._neovimInstance.command("exec \"" + action + " " + normalizePath(files[i]) + "\"")
}
}

ipcRenderer.on("open-files", (_evt: any, message: string, files: string[]) => {
openFiles(files, message)
})

// enable opening a file via drag-drop
document.ondragover = (ev) => {
ev.preventDefault()
Expand All @@ -292,10 +307,10 @@ export class NeovimEditor implements IEditor {

let files = ev.dataTransfer.files
// open first file in current editor
this._neovimInstance.open(files[0].path.split("\\").join("/"))
this._neovimInstance.open(normalizePath(files[0].path))
// open any subsequent files in new tabs
for (let i = 1; i < files.length; i++) {
this._neovimInstance.command("exec \":tabe " + files.item(i).path.split("\\").join("/") + "\"")
this._neovimInstance.command("exec \":tabe " + normalizePath(files.item(i).path) + "\"")
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions vim/core/oni-core-interop/plugin/init.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ function OniNotifyEvent(eventName)
call OniNotify(["event", a:eventName, context])
endfunction

function OniOpenFile(strategy, file)
if bufname('%') != ''
exec a:strategy . a:file
elseif &modified
exec a:strategy . a:file
else
exec ":e " . a:file
endif
endfunction

augroup OniNotifyBufferUpdates
autocmd!
autocmd! CursorMovedI * :call OniNotifyBufferUpdate()
Expand Down

0 comments on commit 2daad92

Please sign in to comment.