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

make undo and redo buttons work #109

Merged
merged 10 commits into from
Apr 16, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions public/app/components/codeEditor/codeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ angular.module('kibibitCodeEditor')
// initialize the editor session
vm.aceLoaded = function(_editor) {
vm.aceSession = _editor.getSession();
vm.undoManager = _editor.getSession().getUndoManager();
SettingsService.setSettings({
currentUndoManager: vm.undoManager,
currentEditor: _editor
});
// save cursor position
_editor.on('changeSelection', function() {
$timeout(function() {
Expand Down
20 changes: 19 additions & 1 deletion public/app/components/menuBar/menuBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ angular.module('kibibitCodeEditor')
};
})

.controller('menuBarController', function(ngDialog) {
.controller('menuBarController', function(SettingsService, ngDialog) {
var vm = this;
vm.settings = {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this initial vm.settings if we overwrite it in line 48:
vm.settings = SettingsService.getSettings();

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a left over from the original code. removed

printLayout: true,
Expand All @@ -40,4 +40,22 @@ angular.module('kibibitCodeEditor')
plain: true
});
};

vm.settings = SettingsService.getSettings();

vm.hasUndo = function() {
if (vm.settings.currentUndoManager && vm.settings.currentUndoManager.hasUndo) {

Choose a reason for hiding this comment

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

Line must be at most 80 characters

return vm.settings.currentUndoManager.hasUndo();
} else {
return false;
}
};

vm.hasRedo = function() {
if (vm.settings.currentUndoManager && vm.settings.currentUndoManager.hasRedo) {

Choose a reason for hiding this comment

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

Line must be at most 80 characters

return vm.settings.currentUndoManager.hasRedo();
} else {
return false;
}
};
});
4 changes: 2 additions & 2 deletions public/app/components/menuBar/menuBarTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ <h2 class="md-toolbar-tools">{{main.projectFolderPath}}</h2>
<md-menu-content>
<md-menu-item class="md-indent">
<md-icon class="material-icons">undo</md-icon>
<md-button ng-click="menuBarCtrl.sampleAction('undo', $event)">
<md-button ng-click="menuBarCtrl.settings.currentUndoManager.undo() && menuBarCtrl.settings.currentEditor.focus()" ng-disabled="!menuBarCtrl.hasUndo()">
Undo
<span class="md-alt-text">{{ 'M-Z' | keyboardShortcut }}</span>
</md-button>
</md-menu-item>
<md-menu-item class="md-indent">
<md-icon class="material-icons">redo</md-icon>
<md-button ng-click="menuBarCtrl.sampleAction('redo', $event)">
<md-button ng-click="menuBarCtrl.settings.currentUndoManager.redo() && menuBarCtrl.settings.currentEditor.focus()" ng-disabled="!menuBarCtrl.hasRedo()">
Redo
<span class="md-alt-text">{{ 'M-Y' | keyboardShortcut }}</span>
</md-button>
Expand Down
4 changes: 3 additions & 1 deletion public/app/services/settingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ angular.module('kibibitCodeEditor')
/* init */
var settings = {
cursor: {row: '0', column: '0'},
isFullscreen: false
isFullscreen: false,
currentUndoManager: undefined,
currentEditor: undefined
};

vm.getSettings = function() {
Expand Down