Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some more cleaning...

  • Loading branch information...
commit 4daf72798d7f107dc49ac747587a082936c65e32 1 parent 3089f4e
Vojta Jina authored
37 app/index.html
View
@@ -76,43 +76,6 @@
<select ng-model="settings.softWrap" ng-options="i.value as i.name for i in SOFT_WRAP" id="settings-soft-wrap"></select>
</div>
</form>
-
- <!--
- <div class="shortcuts">
- <h3>Shortcuts</h3>
- <table>
- <tr>
- <td class="keys">CTRL + O</td>
- <td>Open file</td>
- </tr>
-
- <tr>
- <td class="keys">CTRL + S</td>
- <td>Save current file</td>
- </tr>
-
- <tr>
- <td class="keys">CTRL + N</td>
- <td>Create new file</td>
- </tr>
-
- <tr>
- <td class="keys">CTRL + W</td>
- <td>Close current tab</td>
- </tr>
-
- <tr>
- <td class="keys">CTRL + F</td>
- <td>Filter the document, goto line</td>
- </tr>
-
- <tr>
- <td class="keys">CTRL + ,</td>
- <td>Toggle settings</td>
- </tr>
- </table>
- </div>
- -->
</div>
</div>
</div>
14 app/js/controllers/App.js
View
@@ -23,7 +23,6 @@ TD.controller('App', function($scope, settings, editor, focus) {
$scope.doSearch = function() {
- // TODO(vojta): make this nicer, I/O rush :-D
if (!$scope.search) {
return;
}
@@ -42,28 +41,30 @@ TD.controller('App', function($scope, settings, editor, focus) {
editor.clearFilter();
}
} else {
- editor._editor.find($scope.search);
+ editor.find($scope.search);
}
};
+
$scope.searchPrevious = function() {
if (!$scope.search || $scope.search.charAt(0) === '/' || $scope.search.charAt(0) === ':') {
return;
}
- editor._editor.findPrevious();
+ editor.findPrevious();
};
+
$scope.searchNext = function() {
if (!$scope.search || $scope.search.charAt(0) === '/' || $scope.search.charAt(0) === ':') {
return;
}
- editor._editor.findNext();
+ editor.findNext();
};
+
$scope.enterSearch = function() {
- // TODO(vojta): make this nicer, I/O rush :-D
if (!$scope.search) {
return;
}
@@ -74,7 +75,7 @@ TD.controller('App', function($scope, settings, editor, focus) {
} else if ($scope.search.charAt(0) === ':') {
$scope.toggleSearch(false);
} else {
- editor._editor.findNext();
+ editor.findNext();
}
};
@@ -83,6 +84,7 @@ TD.controller('App', function($scope, settings, editor, focus) {
$scope.toggleSearch();
});
+
$scope.$on('tab_deselected', function() {
$scope.toggleSearch(false);
});
36 app/js/services/chromeFs.js
View
@@ -1,32 +1,6 @@
-TD.value('chromeFs', chrome.fileSystem);
-
-
-
-/*
-Platform Access to native FS
-https://docs.google.com/a/google.com/document/d/1B3Bbns0vP6lx7w8agrIZbSgfMsfQJc5dqv34_z5ARQY/edit?pli=1
-
+/**
+ * Platform Access to native FS
+ * https://docs.google.com/a/google.com/document/d/1B3Bbns0vP6lx7w8agrIZbSgfMsfQJc5dqv34_z5ARQY/edit?pli=1
+ */
-// Returns a path suitable for displaying to the user. Currently
-// this is the full path but will get prettified (e.g. highlight
-// the users' home directory) in future.
-chrome.fileSystem.getDisplayPath(fileEntry, function(path) {...});
-
-// Obtain a read / write FileEntry from a read-only one.
-// The original FileEntry is not changed and remains read-only.
-// This function opens a file picker with the initial path set
-// from the read only entry; a different path can be chosen if
-// the user wants to save into a different file.
-chrome.fileSystem.getWritableFileEntry(readOnlyEntry, function(writableEntry) {...});
-
-// Prompt the user for a read-only FileEntry.
-chrome.fileSystem.chooseFile(function(readOnlyEntry) {...});
-// or
-chrome.fileSystem.chooseFile({type: "openFile"}, function(readOnlyEntry) {...});
-
-// Prompt the use for a read / write entry. If a new file is
-// chosen an empty file will be created before the FileEntry is
-// returned.
-// More options will be added to chooseFile in future.
-chrome.fileSystem.chooseFile({type: "saveFile"}, function(writableEntry) {...});
-*/
+TD.value('chromeFs', chrome.fileSystem);
12 app/js/services/editor.js
View
@@ -105,7 +105,17 @@ TD.factory('editor', function(EditSession, FilterFolding, settings, ace) {
}
},
- _editor: ace
+ find: function(value) {
+ return ace.find(value);
+ },
+
+ findNext: function() {
+ return ace.findNext();
+ },
+
+ findPrevious: function() {
+ return ace.findPrevious();
+ }
};
});
23 app/js/services/settings.js
View
@@ -1,18 +1,18 @@
-TD.service('settings', function($rootScope, storage, log, THEMES, KEY_MODES, SOFT_WRAP, SOFT_TABS) {
- var settings = this;
-
- var findById = function(collection, id) {
- for (var i = 0; i < collection.length; i++) {
- if (collection[i].id === id) {
- return collection[i];
- }
+var findById = function(collection, id) {
+ for (var i = 0; i < collection.length; i++) {
+ if (collection[i].id === id) {
+ return collection[i];
}
- };
+ }
+};
+
+TD.service('settings', function($rootScope, storage, log, THEMES, KEY_MODES, SOFT_WRAP, SOFT_TABS) {
+
+ var settings = this;
var data = {};
var listeners = {};
-
var defineProperty = function(name) {
settings.__defineGetter__(name, function() {
return data[name];
@@ -36,6 +36,7 @@ TD.service('settings', function($rootScope, storage, log, THEMES, KEY_MODES, SOF
defineProperty('softTabs');
defineProperty('softWrap');
+
this.on = function(name, fn) {
if (!listeners[name]) {
listeners[name] = [];
@@ -44,6 +45,7 @@ TD.service('settings', function($rootScope, storage, log, THEMES, KEY_MODES, SOF
listeners[name].push(fn);
};
+
this.store = function() {
storage.set({
settings: {
@@ -57,6 +59,7 @@ TD.service('settings', function($rootScope, storage, log, THEMES, KEY_MODES, SOF
});
};
+
this.load = function() {
storage.get(['settings'], function(data) {
data = data.settings || {};
10 app/js/services/tabs.js
View
@@ -13,6 +13,7 @@ TD.factory('Tab', function(EditSession, $rootScope, log, modeForPath) {
});
};
+
this.setFileEntry = function(fileEntry) {
this.file = fileEntry || null;
this.label = fileEntry && fileEntry.name || '<new file>';
@@ -26,10 +27,12 @@ TD.factory('Tab', function(EditSession, $rootScope, log, modeForPath) {
}
};
+
this.icon = function() {
return this.modified ? 'icon-certificate' : 'icon-remove';
};
+
this.manualMode = false;
// TODO(vojta): pass mode to the constructor to avoid extra parsing
this.session = new EditSession(content || '');
@@ -40,8 +43,10 @@ TD.factory('Tab', function(EditSession, $rootScope, log, modeForPath) {
TD.factory('tabs', function(editor, fs, log, Tab, chromeFs, lru, settings, $rootScope) {
+
var tabs = [];
+
tabs.select = function(tab) {
if (tabs.current) {
$rootScope.$broadcast('tab_deselected');
@@ -59,6 +64,7 @@ TD.factory('tabs', function(editor, fs, log, Tab, chromeFs, lru, settings, $root
}
};
+
tabs.close = function(tab) {
tab = tab || tabs.current;
@@ -98,6 +104,7 @@ TD.factory('tabs', function(editor, fs, log, Tab, chromeFs, lru, settings, $root
}
};
+
tabs.saveCurrent = function() {
var tab = tabs.current;
@@ -123,6 +130,7 @@ TD.factory('tabs', function(editor, fs, log, Tab, chromeFs, lru, settings, $root
}
};
+
tabs.open = function() {
chromeFs.chooseFile({type: 'openWritableFile'}, function(fileEntry) {
if (!fileEntry) {
@@ -148,6 +156,7 @@ TD.factory('tabs', function(editor, fs, log, Tab, chromeFs, lru, settings, $root
});
};
+
tabs.selectByFile = function(file) {
for (var i = 0; i < tabs.length; i++) {
// TODO(vojta): use chromeFs.getDisplayPath() instead
@@ -160,6 +169,7 @@ TD.factory('tabs', function(editor, fs, log, Tab, chromeFs, lru, settings, $root
return false;
};
+
tabs.add = function(fileEntry, content) {
var tab = new Tab(fileEntry, content);
var current = tabs.current;
18 test/unit/controllers/AppSpec.coffee
View
@@ -45,6 +45,11 @@ describe 'controllers App', ->
describe 'doSearch', ->
+ it 'should ignore empty values', ->
+ scope.search = undefined
+ scope.doSearch()
+
+
describe 'goToLine', ->
it 'should goToLine when search starts with ":"', ->
@@ -117,6 +122,11 @@ describe 'controllers App', ->
describe 'enterSearch', ->
+ it 'should ignore empty values', ->
+ scope.search = undefined
+ scope.enterSearch()
+
+
describe 'goToLine', ->
it 'should hide search', ->
@@ -153,3 +163,11 @@ describe 'controllers App', ->
broadcast 'search'
expect(scope.isSearchVisible).toBe false
+
+
+ it 'should handle "tab_deselected"', ->
+ broadcast 'tab_deselected'
+ expect(scope.isSearchVisible).toBe false
+
+ broadcast 'tab_deselected'
+ expect(scope.isSearchVisible).toBe false
9 test/unit/services/settingsSpec.coffee
View
@@ -137,3 +137,12 @@ describe 'services settings', ->
settings.store()
expect(storage._data.settings.softWrap).toBe 0
+
+
+ describe 'findById', ->
+
+ it 'should return first item with given id', ->
+ collection = [{id: 'some'}, {id: 'other'}, {id: 'some'}]
+
+ expect(findById collection, 'some').toBe collection[0]
+ expect(findById collection, 'other').toBe collection[1]
19 test/unit/services/tabsSpec.coffee
View
@@ -113,3 +113,22 @@ describe 'services tabs', ->
expect(tabs[0].session.content).toBe 'a'
expect(tabs[1].session.content).toBe 'c'
+
+
+ describe 'Tab', ->
+
+ it 'should update modified and $digest if changed', inject (Tab, $rootScope) ->
+ tab = new Tab
+ spy = jasmine.createSpy 'on digest'
+
+ $rootScope.$watch(spy)
+ expect(tab.modified).toBe false
+
+ tab._onSessionChange()
+ expect(spy).toHaveBeenCalled()
+ expect(tab.modified).toBe true
+ spy.reset()
+
+ tab._onSessionChange()
+ expect(spy).not.toHaveBeenCalled()
+ expect(tab.modified).toBe true
23 testacular.js → testacular.conf.js
View
@@ -1,11 +1,5 @@
-// Sample Testacular configuration file, that contain pretty much all the available options
-// It's used for running client tests on Travis (http://travis-ci.org/#!/vojtajina/testacular)
-// Most of the options can be overriden by cli arguments (see testacular --help)
-
-
-
// base path, that will be used to resolve files and exclude
-//basePath = '../..'
+basePath = '';
// list of files / patterns to load in the browser
files = [
@@ -26,26 +20,13 @@ exclude = [];
// possible values: 'dots' || 'progress'
reporter = 'progress';
-
-// web server port
-port = 8080;
-
-// cli runner port
-runnerPort = 9100;
-
-// enable / disable colors in the output (reporters and logs)
-colors = true;
-
// level of logging
-// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
+// LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_INFO;
// enable / disable watching file and executing tests whenever any file changes
autoWatch = true;
-// polling interval in ms (ignored on OS that support inotify)
-autoWatchInterval = 10;
-
browsers = ['ChromeCanary'];
singleRun = false;
Please sign in to comment.
Something went wrong with that request. Please try again.