提交 b0891a91 编写于 作者: J Johannes Rieken

handle links as commands or openables

上级 b7be456d
......@@ -14,7 +14,8 @@ import Platform = require('vs/base/common/platform');
import ModesContentHover = require('./modesContentHover');
import ModesGlyphHover = require('./modesGlyphHover');
import Keyboard = require('vs/base/browser/keyboardEvent');
import {INullService} from 'vs/platform/instantiation/common/instantiation';
import {IEditorService} from 'vs/platform/editor/common/editor';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {KeyCode} from 'vs/base/common/keyCodes';
class ModesHoverController implements EditorCommon.IEditorContribution {
......@@ -27,7 +28,10 @@ class ModesHoverController implements EditorCommon.IEditorContribution {
private _contentWidget: ModesContentHover.ModesContentHoverWidget;
private _glyphWidget: ModesGlyphHover.ModesGlyphHoverWidget;
constructor(editor:EditorBrowser.ICodeEditor, @INullService ns) {
constructor(editor: EditorBrowser.ICodeEditor,
@IEditorService editorService: IEditorService,
@IKeybindingService keybindingService: IKeybindingService
) {
this._editor = editor;
this._toUnhook = [];
......@@ -41,7 +45,7 @@ class ModesHoverController implements EditorCommon.IEditorContribution {
this._toUnhook.push(this._editor.addListener(EditorCommon.EventType.ModelDecorationsChanged, () => this._onModelDecorationsChanged()));
this._toUnhook.push(this._editor.addListener('scroll', () => this._hideWidgets()));
this._contentWidget = new ModesContentHover.ModesContentHoverWidget(editor);
this._contentWidget = new ModesContentHover.ModesContentHoverWidget(editor, editorService, keybindingService);
this._glyphWidget = new ModesGlyphHover.ModesGlyphHoverWidget(editor);
}
}
......
......@@ -18,7 +18,9 @@ import {renderHtml} from 'vs/base/browser/htmlContentRenderer';
import {tokenizeToString} from 'vs/editor/common/modes/textToHtmlTokenizer';
import {Range} from 'vs/editor/common/core/range';
import {ExtraInfoRegistry, getExtraInfoAtPosition} from '../common/hover';
import {IEditorService} from 'vs/platform/editor/common/editor';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
class ModesContentComputer implements HoverOperation.IHoverComputer<Modes.IComputeExtraInfoResult[]> {
......@@ -122,13 +124,17 @@ export class ModesContentHoverWidget extends HoverWidget.ContentHoverWidget {
private _hoverOperation: HoverOperation.HoverOperation<Modes.IComputeExtraInfoResult[]>;
private _highlightDecorations:string[];
private _isChangingDecorations: boolean;
private _editorService: IEditorService;
private _keybindingService: IKeybindingService;
constructor(editor: EditorBrowser.ICodeEditor) {
constructor(editor: EditorBrowser.ICodeEditor, editorService: IEditorService, keybindingService: IKeybindingService) {
super(ModesContentHoverWidget.ID, editor);
this._computer = new ModesContentComputer(this._editor);
this._highlightDecorations = [];
this._isChangingDecorations = false;
this._editorService = editorService;
this._keybindingService = keybindingService;
this._hoverOperation = new HoverOperation.HoverOperation(
this._computer,
......@@ -238,14 +244,23 @@ export class ModesContentHoverWidget extends HoverWidget.ContentHoverWidget {
if(msg.htmlContent && msg.htmlContent.length > 0) {
msg.htmlContent.forEach((content) => {
container.appendChild(renderHtml(content, {
// actionCallback: (content) => {
// try {
// let resource = URI.parse(content);
// this.editorService.openEditor({resource});
// } catch (e) {
// // ignore
// }
// },
actionCallback: (content) => {
let promise: TPromise<any>;
if (KeybindingsRegistry.getCommands()[content]) {
promise = this._keybindingService.executeCommand(content);
} else {
try {
let resource = URI.parse(content);
promise = this._editorService.openEditor({resource});
} catch (e) {
// ignore
}
}
if (promise) {
promise.then(undefined, err => console.log(err));
}
},
codeBlockRenderer: (modeId, value) => {
let mode: Modes.IMode;
let model = this._editor.getModel();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册