From 59ae66c545db2ad92dc5efc1a069edd16960ebdd Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Mon, 20 Jan 2014 16:59:27 +0100 Subject: [PATCH] Added inline annotation support for language extensions, used by the zed-javascript-ext (https://github.com/zedapp/zed-javascript-ext). --- .../default/command/snippet_completer.js | 4 +-- app/config/default/mode/javascript/check.js | 1 + app/config/default/mode/javascript/jshint.js | 2 +- app/css/editor.css | 16 +++++++++ app/js/boot.js | 2 ++ app/js/editor.js | 1 - app/js/lib/inline_annotation.js | 35 +++++++++++++++++++ app/js/sandbox/impl/zed/session.js | 16 ++++++++- app/manual/projects.md | 16 +++++++++ 9 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 app/js/lib/inline_annotation.js create mode 100644 app/manual/projects.md diff --git a/app/config/default/command/snippet_completer.js b/app/config/default/command/snippet_completer.js index e850feee..801bde58 100644 --- a/app/config/default/command/snippet_completer.js +++ b/app/config/default/command/snippet_completer.js @@ -1,8 +1,6 @@ -/* global _ */ +/* global _, define */ define(function(require, exports, module) { - var session = require("zed/session"); return function(info, callback) { - var path = info.path; var snippets = info.snippets; callback(null, _.map(snippets, function(snippet, name) { return { diff --git a/app/config/default/mode/javascript/check.js b/app/config/default/mode/javascript/check.js index ccdc9dfb..8c9e98a5 100644 --- a/app/config/default/mode/javascript/check.js +++ b/app/config/default/mode/javascript/check.js @@ -120,6 +120,7 @@ define(function(require, exports, module) { errors.push({ row: error.line - 1, column: error.character - 1, + text: error.reason, type: type, raw: raw diff --git a/app/config/default/mode/javascript/jshint.js b/app/config/default/mode/javascript/jshint.js index 29576efc..dc59897e 100644 --- a/app/config/default/mode/javascript/jshint.js +++ b/app/config/default/mode/javascript/jshint.js @@ -1031,7 +1031,7 @@ exports.register = function (linter) { data: [ data.value ] }); } - + if (data.value.substr(data.value.length - 1) === ".") { // Warn about a trailing decimal point. linter.warn("W047", { diff --git a/app/css/editor.css b/app/css/editor.css index c737ee20..9d3eeec3 100644 --- a/app/css/editor.css +++ b/app/css/editor.css @@ -353,4 +353,20 @@ body.non_mac ::-webkit-scrollbar-thumb:horizontal { } body.non_mac ::-webkit-scrollbar-thumb:hover { -webkit-box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.9), inset 0 0 0 4px rgba(128, 128, 128, 0.9); +} +/* Markers */ +.marker-highlight-warning { + position: absolute; + border-bottom: solid 1px #CCCC00; + z-index: 1000; +} +.marker-highlight-error { + position: absolute; + border-bottom: solid 1px red; + z-index: 1000; +} +.marker-highlight-info { + position: absolute; + border-bottom: solid 1px blue; + z-index: 1000; } \ No newline at end of file diff --git a/app/js/boot.js b/app/js/boot.js index 2d030afd..56946b91 100644 --- a/app/js/boot.js +++ b/app/js/boot.js @@ -49,6 +49,8 @@ require(["text!../manual/cheatsheet.md"], function(cheatsheet) { _.each(arguments, function(module) { if (module.hook) module.hook(); }); + + _.each(arguments, function(module) { if (module.init) module.init(); }); diff --git a/app/js/editor.js b/app/js/editor.js index 41e71b83..1b3704dd 100644 --- a/app/js/editor.js +++ b/app/js/editor.js @@ -905,5 +905,4 @@ define(function(require, exports, module) { }); }); - }); diff --git a/app/js/lib/inline_annotation.js b/app/js/lib/inline_annotation.js new file mode 100644 index 00000000..2175a205 --- /dev/null +++ b/app/js/lib/inline_annotation.js @@ -0,0 +1,35 @@ +/* global ace, define*/ +define(function(require, exports, module) { + var Anchor = ace.require("ace/anchor").Anchor; + var Range = ace.require("ace/range").Range; + + function InlineAnnotation(session, info) { + this.session = session; + this.info = info; + this.startAnchor = new Anchor(session.getDocument(), info.row, info.column); + this.endAnchor = new Anchor(session.getDocument(), info.row, info.endColumn); + this.startAnchor.on("change", this.update.bind(this)); + this.endAnchor.on("change", this.update.bind(this)); + this.marker = null; + this.update(); + } + + InlineAnnotation.prototype = { + update: function() { + var range = Range.fromPoints(this.startAnchor.getPosition(), this.endAnchor.getPosition()); + if (this.marker) { + this.session.removeMarker(this.marker); + } + this.marker = this.session.addMarker(range, "marker-highlight-" + this.info.type); + }, + remove: function() { + this.startAnchor.detach(); + this.endAnchor.detach(); + if (this.marker) { + this.session.removeMarker(this.marker); + } + } + }; + + return InlineAnnotation; +}); \ No newline at end of file diff --git a/app/js/sandbox/impl/zed/session.js b/app/js/sandbox/impl/zed/session.js index 3075468a..6914f2d0 100644 --- a/app/js/sandbox/impl/zed/session.js +++ b/app/js/sandbox/impl/zed/session.js @@ -2,6 +2,7 @@ define(function(require, exports, module) { var session_manager = require("../../../session_manager"); var Range = ace.require("ace/range").Range; var editor = require("../../../editor"); + var InlineAnnotation = require("../../../lib/inline_annotation"); function rangify(range) { return Range.fromPoints(range.start, range.end); @@ -22,7 +23,20 @@ define(function(require, exports, module) { }); }, setAnnotations: function(path, annos, callback) { - getSession(path).setAnnotations(annos); + var session = getSession(path); + (session.annotations || []).forEach(function(anno) { + console.log("Removing anno", anno); + anno.remove(); + }); + session.annotations = []; + for(var i = 0; i < annos.length; i++) { + var anno = annos[i]; + // If no endColum, no inline marker is required + if(anno.endColumn) { + session.annotations.push(new InlineAnnotation(session, anno)); + } + } + session.setAnnotations(annos); callback(); }, getText: function(path, callback) { diff --git a/app/manual/projects.md b/app/manual/projects.md new file mode 100644 index 00000000..2418ca0a --- /dev/null +++ b/app/manual/projects.md @@ -0,0 +1,16 @@ +Zed Projects +============ + +Zed is an editor based on projects. When you do a fresh Zed install, a few project-like options will be available, including "Open Local Folder", "Open Dropbox Folder", "Notes", "Configuration", and "Manual". + +Editing Local Files +------------------- +To edit the files in a folder on your local hard drive pick "Open Local Folder". A new Zed window will open allowing you to select the folder to edit. After you switch back to the Zed Project Picker window, you will see that the folder you just opened has been added to your project list. + +Editing Files on Dropbox +------------------------ +To edit files on Dropbox, select "Open Dropbox Folder", login with Dropbox and select the folder to edit. After you opened the folder and switching back to the Project Picker, you'll notice that the folder you just openened has been added to your project list. + +Notes +----- +Notes is a special built-in project that stores its files on Google Drive \ No newline at end of file