Skip to content

Commit

Permalink
Bug 338882 - [client] keyboard annotations navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Li committed Mar 6, 2012
1 parent 0703a90 commit a46fa31
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
/*jslint maxerr:150 browser:true devel:true */

define("orion/editor/editorFeatures", ['i18n!orion/editor/nls/messages', 'orion/textview/undoStack', 'orion/textview/keyBinding',
'orion/textview/rulers', 'orion/textview/annotations', 'orion/textview/textDND', 'orion/editor/regex'],
function(messages, mUndoStack, mKeyBinding, mRulers, mAnnotations, mTextDND, mRegex) {
'orion/textview/rulers', 'orion/textview/annotations', 'orion/textview/tooltip', 'orion/textview/textDND', 'orion/editor/regex'],
function(messages, mUndoStack, mKeyBinding, mRulers, mAnnotations, mTooltip, mTextDND, mRegex) {

function UndoFactory() {
}
Expand Down Expand Up @@ -438,6 +438,100 @@ function(messages, mUndoStack, mKeyBinding, mRulers, mAnnotations, mTextDND, mRe
return true;
}.bind(this));

this.textView.setKeyBinding(new mKeyBinding.KeyBinding(190, true), messages.nextAnnotation);
this.textView.setAction(messages.nextAnnotation, function() {
var editor = this.editor;
var annotationModel = editor.getAnnotationModel();
if(!annotationModel) { return true; }
var model = editor.getModel();
var line = model.getLineAtOffset(editor.getCaretOffset());
var lineEnd = model.getLineEnd(line, true);
var annotations = annotationModel.getAnnotations(lineEnd, model.getCharCount());
while(annotations.hasNext()) {
var annotation = annotations.next();
if(annotation.type === "orion.annotation.folding") { continue; }
var nextLine = model.getLineAtOffset(annotation.start);
if(nextLine) {
annotations = annotationModel.getAnnotations(model.getLineStart(nextLine), model.getLineEnd(nextLine));
var nextAnnotations = [];
while(annotations.hasNext()) {
nextAnnotations.push(annotations.next());
}
var tooltip = mTooltip.Tooltip.getTooltip(this.textView);
if (!tooltip) { return true; }
var view = this.textView;
var rect = view.getClientArea();
var cb = function() {
setTimeout( function() {
tooltip.setTarget({
y: view.getLinePixel(nextLine),
getTooltipInfo: function() {
return { contents: nextAnnotations,
x: view.convert({x: rect.x}, "document", "page").x,
y: view.convert({y: view.getLocationAtOffset(model.getLineStart(nextLine)).y}, "document", "page").y,
maxWidth: rect.width,
maxHeight: rect.height
};
}
}, 0);
}, 0);
};
editor.moveSelection(annotation.start, annotation.start, cb);
}
break;
}
return true;
}.bind(this));

this.textView.setKeyBinding(new mKeyBinding.KeyBinding(188, true), messages.prevAnnotation);
this.textView.setAction(messages.prevAnnotation, function() {
var editor = this.editor;
var annotationModel = editor.getAnnotationModel();
if(!annotationModel) { return true; }
var model = editor.getModel();
var line = model.getLineAtOffset(editor.getCaretOffset());
var lineStart = model.getLineEnd(line - 1);
var annotations = annotationModel.getAnnotations(0, lineStart);
var prevAnnotations = [];
while(annotations.hasNext()) {
var annotation = annotations.next();
if(annotation.type === "orion.annotation.folding") { continue; }
prevAnnotations.push(annotation);
}
if(prevAnnotations.length) {
var previousAnnotation = prevAnnotations[prevAnnotations.length - 1];
var nextLine = model.getLineAtOffset(previousAnnotation.start);
if(nextLine) {
annotations = annotationModel.getAnnotations(model.getLineStart(nextLine), model.getLineEnd(nextLine));
var nextAnnotations = [];
while(annotations.hasNext()) {
nextAnnotations.push(annotations.next());
}
var tooltip = mTooltip.Tooltip.getTooltip(this.textView);
if (!tooltip) { return true; }
var view = this.textView;
var rect = view.getClientArea();
var cb = function() {
setTimeout( function() {
tooltip.setTarget({
y: view.getLinePixel(nextLine),
getTooltipInfo: function() {
return { contents: nextAnnotations,
x: view.convert({x: rect.x}, "document", "page").x,
y: view.convert({y: view.getLocationAtOffset(model.getLineStart(nextLine)).y}, "document", "page").y,
maxWidth: rect.width,
maxHeight: rect.height
};
}
}, 0);
}, 0);
};
editor.moveSelection(previousAnnotation.start, previousAnnotation.start, cb);
}
}
return true;
}.bind(this));

var isMac = navigator.platform.indexOf("Mac") !== -1;
this.textView.setKeyBinding(new mKeyBinding.KeyBinding("q", !isMac, false, false, isMac), messages.lastEdit);
this.textView.setAction(messages.lastEdit, function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"toggleLineComment": "Toggle Line Comment",
"addBlockComment": "Add Block Comment",
"removeBlockComment": "Remove Block Comment",
"nextAnnotation": "Next Annotation",
"prevAnnotation": "Previous Annotation",
"linkedModeEntered": "Linked Mode entered",
"linkedModeExited": "Linked Mode exited",
"syntaxError": "Syntax Error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ define("orion/textview/tooltip", ['i18n!orion/textview/nls/messages', 'orion/tex
this._document = document;
var domNode = this._domNode = document.createElement("DIV");
domNode.className = "viewTooltip";
domNode.setAttribute("aria-live", "assertive");
domNode.setAttribute("aria-atomic", "true");
var viewParent = this._viewParent = document.createElement("DIV");
domNode.appendChild(viewParent);
var htmlParent = this._htmlParent = document.createElement("DIV");
Expand Down Expand Up @@ -84,15 +86,20 @@ define("orion/textview/tooltip", ['i18n!orion/textview/nls/messages', 'orion/tex
isVisible: function() {
return this._domNode && this._domNode.style.visibility === "visible";
},
setTarget: function(target) {
setTarget: function(target, delay) {
if (this.target === target) { return; }
this._target = target;
this.hide();
if (target) {
var self = this;
self._showTimeout = setTimeout(function() {
if(delay === 0) {
self.show(true);
}, 1000);
}
else {
self._showTimeout = setTimeout(function() {
self.show(true);
}, delay ? delay : 1000);
}
}
},
show: function(autoHide) {
Expand Down

0 comments on commit a46fa31

Please sign in to comment.