Skip to content

Commit

Permalink
Fix splitting implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jord7580 committed Nov 13, 2014
1 parent 8e0a818 commit aae9878
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
13 changes: 8 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ define(function (require, exports, module) {
require('src/commands');

var CodeMirror = brackets.getModule('thirdparty/CodeMirror2/lib/codemirror'),
Commands = brackets.getModule('command/Commands'),
CommandManager = brackets.getModule('command/CommandManager'),
Dialogs = brackets.getModule('widgets/Dialogs'),
DocumentManager = brackets.getModule('document/DocumentManager'),
EditorManager = brackets.getModule('editor/EditorManager'),
ExtensionUtils = brackets.getModule('utils/ExtensionUtils'),
KeyBindingManager = brackets.getModule('command/KeyBindingManager'),
MainViewManager = brackets.getModule('view/MainViewManager'),
Menus = brackets.getModule('command/Menus'),
ProjectManager = brackets.getModule('project/ProjectManager'),
StatusBar = brackets.getModule('widgets/StatusBar'),
Expand Down Expand Up @@ -64,16 +66,17 @@ define(function (require, exports, module) {

$(ProjectManager).on('projectOpen', function (jqEvent, directory) {
// Ensure that at most one file is working when the project opens.
var workingSet = DocumentManager.getWorkingSet();
var workingSet = MainViewManager.getWorkingSet();
if (workingSet.length > 1) {
DocumentManager.removeListFromWorkingSet(workingSet.slice(1));
CommandManager.execute(Commands.FILE_CLOSE_LIST, {
PaneId: MainViewManager.ALL_PANES,
fileList: workingSet.slice(1)
});
} else if (workingSet.length === 0) {
return;
}

DocumentManager.getDocumentForPath(workingSet[0]._path).done(function (doc) {
DocumentManager.setCurrentDocument(doc);
});
CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, {fullPath: workingSet[0]._path});
});

$(DocumentManager).on('currentDocumentChange', updateEditorMode);
Expand Down
40 changes: 16 additions & 24 deletions src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ define(function (require, exports, module) {
'use strict';

var CodeMirror = brackets.getModule('thirdparty/CodeMirror2/lib/codemirror'),
Commands = brackets.getModule('command/Commands'),
CommandManager = brackets.getModule('command/CommandManager'),
DocumentManager = brackets.getModule('document/DocumentManager'),
FileSystem = brackets.getModule('filesystem/FileSystem'),
Expand All @@ -10,7 +11,7 @@ define(function (require, exports, module) {
utils = require('src/utils');

function closeActiveFile() {
return CommandManager.execute('file.close').fail(function () {
return CommandManager.execute(Commands.FILE_CLOSE).fail(function () {
//TODO: implement warning in vim command bar
});
}
Expand Down Expand Up @@ -45,7 +46,7 @@ define(function (require, exports, module) {
deferred = $.Deferred();

function open() {
CommandManager.execute('file.addToWorkingSet', {fullPath: fullPath})
CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, {fullPath: fullPath})
.done(deferred.resolve);
}

Expand All @@ -66,31 +67,24 @@ define(function (require, exports, module) {
return deferred;
}

function prepareNewPane(filePath) {
$(MainViewManager).one('paneLayoutChange', function (jqEvent, orientation) {
if (orientation !== null) {
var file = FileSystem.getFileForPath(filePath);
MainViewManager.open('second-pane', file);
}
function prepareNewPane(fullPath) {
$(MainViewManager).one('paneCreate', function (jqEvent, paneId) {
CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, { fullPath: fullPath, paneId: paneId })
});
}

function splitHorizontally() {
CommandManager.execute('cmd.splitHorizontally');
function splitHorizontally(fullPath) {
prepareNewPane(fullPath);
CommandManager.execute(Commands.CMD_SPLITVIEW_HORIZONTAL);
}

function splitVertically() {
CommandManager.execute('cmd.splitVertically');
function splitVertically(fullPath) {
prepareNewPane(fullPath);
CommandManager.execute(Commands.CMD_SPLITVIEW_VERTICAL);
}

function unsplit() {
var layout = MainViewManager.getLayoutScheme();
if (layout.rows === 2) {
splitHorizontally();
}
if (layout.columns === 2 ) {
splitVertically();
}
CommandManager.execute(Commands.CMD_SPLITVIEW_NONE);
}

// Define all custom ex commands after the vim module is loaded.
Expand All @@ -101,7 +95,7 @@ define(function (require, exports, module) {
// preventing the first file in the dialog list from being immediately opened.
setTimeout(function () {
closeActiveFile().done(function () {
CommandManager.execute('navigate.quickOpen');
CommandManager.execute(Commands.NAVIGATE_QUICK_OPEN);
});
}, 200);
} else {
Expand Down Expand Up @@ -129,8 +123,7 @@ define(function (require, exports, module) {
return;
}

prepareNewPane(utils.resolvePath(params.args[0]));
splitVertically();
splitVertically(utils.resolvePath(params.args[0]));
});

CodeMirror.Vim.defineEx('split', 'sp', function (cm, params) {
Expand All @@ -139,8 +132,7 @@ define(function (require, exports, module) {
return;
}

prepareNewPane(utils.resolvePath(params.args[0]));
splitHorizontally();
splitHorizontally(utils.resolvePath(params.args[0]));
});
});

Expand Down

0 comments on commit aae9878

Please sign in to comment.