提交 b07b786e 编写于 作者: A Alex Dima

Better usage of editor API

上级 dd460f29
......@@ -99,12 +99,7 @@ class VisualEditorState {
this._zonesMap = {};
// (2) Model decorations
if (this._decorations.length > 0) {
editor.changeDecorations((changeAccessor: IModelDecorationsChangeAccessor) => {
changeAccessor.deltaDecorations(this._decorations, []);
});
}
this._decorations = [];
this._decorations = editor.deltaDecorations(this._decorations, []);
}
public apply(editor: CodeEditor, overviewRuler: editorBrowser.IOverviewRuler, newDecorations: IEditorDiffDecorationsWithZones): void {
......
......@@ -16,6 +16,7 @@ import { ColorProviderRegistry } from 'vs/editor/common/modes';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { getColors, IColorData } from 'vs/editor/contrib/colorPicker/color';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
const MAX_DECORATORS = 500;
......@@ -153,7 +154,7 @@ export class ColorDetector implements IEditorContribution {
endLineNumber: c.colorInfo.range.endLineNumber,
endColumn: c.colorInfo.range.endColumn
},
options: {}
options: ModelDecorationOptions.EMPTY
}));
this._decorationsIds = this._editor.deltaDecorations(this._decorationsIds, decorations);
......
......@@ -173,22 +173,17 @@ export class DragAndDropController implements editorCommon.IEditorContribution {
});
public showAt(position: Position): void {
this._editor.changeDecorations(changeAccessor => {
let newDecorations: IModelDeltaDecoration[] = [];
newDecorations.push({
range: new Range(position.lineNumber, position.column, position.lineNumber, position.column),
options: DragAndDropController._DECORATION_OPTIONS
});
let newDecorations: IModelDeltaDecoration[] = [{
range: new Range(position.lineNumber, position.column, position.lineNumber, position.column),
options: DragAndDropController._DECORATION_OPTIONS
}];
this._dndDecorationIds = changeAccessor.deltaDecorations(this._dndDecorationIds, newDecorations);
});
this._dndDecorationIds = this._editor.deltaDecorations(this._dndDecorationIds, newDecorations);
this._editor.revealPosition(position, editorCommon.ScrollType.Immediate);
}
private _removeDecoration(): void {
this._editor.changeDecorations(changeAccessor => {
changeAccessor.deltaDecorations(this._dndDecorationIds, []);
});
this._dndDecorationIds = this._editor.deltaDecorations(this._dndDecorationIds, []);
}
private _hitContent(target: IMouseTarget): boolean {
......
......@@ -10,18 +10,18 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
export class FoldingDecorationProvider implements IDecorationProvider {
private COLLAPSED_VISUAL_DECORATION = ModelDecorationOptions.register({
private static COLLAPSED_VISUAL_DECORATION = ModelDecorationOptions.register({
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
afterContentClassName: 'inline-folded',
linesDecorationsClassName: 'folding collapsed'
});
private EXPANDED_AUTO_HIDE_VISUAL_DECORATION = ModelDecorationOptions.register({
private static EXPANDED_AUTO_HIDE_VISUAL_DECORATION = ModelDecorationOptions.register({
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
linesDecorationsClassName: 'folding'
});
private EXPANDED_VISUAL_DECORATION = ModelDecorationOptions.register({
private static EXPANDED_VISUAL_DECORATION = ModelDecorationOptions.register({
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
linesDecorationsClassName: 'folding alwaysShowFoldIcons'
});
......@@ -33,11 +33,11 @@ export class FoldingDecorationProvider implements IDecorationProvider {
getDecorationOption(isCollapsed: boolean): ModelDecorationOptions {
if (isCollapsed) {
return this.COLLAPSED_VISUAL_DECORATION;
return FoldingDecorationProvider.COLLAPSED_VISUAL_DECORATION;
} else if (this.autoHideFoldingControls) {
return this.EXPANDED_AUTO_HIDE_VISUAL_DECORATION;
return FoldingDecorationProvider.EXPANDED_AUTO_HIDE_VISUAL_DECORATION;
} else {
return this.EXPANDED_VISUAL_DECORATION;
return FoldingDecorationProvider.EXPANDED_VISUAL_DECORATION;
}
}
......
......@@ -10,7 +10,6 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { IEditorContribution } from 'vs/editor/common/editorCommon';
import { IModelDecorationsChangeAccessor } from 'vs/editor/common/model';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { registerEditorAction, ServicesAccessor, EditorAction, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { IInplaceReplaceSupportResult } from 'vs/editor/common/modes';
......@@ -131,9 +130,7 @@ class InPlaceReplaceController implements IEditorContribution {
this.decorationRemover.cancel();
this.decorationRemover = TPromise.timeout(350);
this.decorationRemover.then(() => {
this.editor.changeDecorations((accessor: IModelDecorationsChangeAccessor) => {
this.decorationIds = accessor.deltaDecorations(this.decorationIds, []);
});
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, []);
});
});
}
......
......@@ -251,32 +251,30 @@ class LinkDetector implements editorCommon.IEditorContribution {
private updateDecorations(links: Link[]): void {
const useMetaKey = (this.editor.getConfiguration().multiCursorModifier === 'altKey');
this.editor.changeDecorations((changeAccessor: IModelDecorationsChangeAccessor) => {
var oldDecorations: string[] = [];
let keys = Object.keys(this.currentOccurrences);
for (let i = 0, len = keys.length; i < len; i++) {
let decorationId = keys[i];
let occurance = this.currentOccurrences[decorationId];
oldDecorations.push(occurance.decorationId);
}
let oldDecorations: string[] = [];
let keys = Object.keys(this.currentOccurrences);
for (let i = 0, len = keys.length; i < len; i++) {
let decorationId = keys[i];
let occurance = this.currentOccurrences[decorationId];
oldDecorations.push(occurance.decorationId);
}
var newDecorations: IModelDeltaDecoration[] = [];
if (links) {
// Not sure why this is sometimes null
for (var i = 0; i < links.length; i++) {
newDecorations.push(LinkOccurrence.decoration(links[i], useMetaKey));
}
let newDecorations: IModelDeltaDecoration[] = [];
if (links) {
// Not sure why this is sometimes null
for (let i = 0; i < links.length; i++) {
newDecorations.push(LinkOccurrence.decoration(links[i], useMetaKey));
}
}
var decorations = changeAccessor.deltaDecorations(oldDecorations, newDecorations);
let decorations = this.editor.deltaDecorations(oldDecorations, newDecorations);
this.currentOccurrences = {};
this.activeLinkDecorationId = null;
for (let i = 0, len = decorations.length; i < len; i++) {
var occurance = new LinkOccurrence(links[i], decorations[i]);
this.currentOccurrences[occurance.decorationId] = occurance;
}
});
this.currentOccurrences = {};
this.activeLinkDecorationId = null;
for (let i = 0, len = decorations.length; i < len; i++) {
let occurance = new LinkOccurrence(links[i], decorations[i]);
this.currentOccurrences[occurance.decorationId] = occurance;
}
}
private _onEditorMouseMove(mouseEvent: ClickLinkMouseEvent, withKey?: ClickLinkKeyboardEvent): void {
......
......@@ -803,9 +803,7 @@ export class SelectionHighlighter extends Disposable implements IEditorContribut
this.state = state;
if (!this.state) {
if (this.decorations.length > 0) {
this.decorations = this.editor.deltaDecorations(this.decorations, []);
}
this.decorations = this.editor.deltaDecorations(this.decorations, []);
return;
}
......
......@@ -84,28 +84,25 @@ class DecorationsManager implements IDisposable {
private _addDecorations(reference: FileReferences): void {
this._callOnModelChange.push(this._editor.getModel().onDidChangeDecorations((event) => this._onDecorationChanged()));
this._editor.changeDecorations(accessor => {
const newDecorations: IModelDeltaDecoration[] = [];
const newDecorationsActualIndex: number[] = [];
const newDecorations: IModelDeltaDecoration[] = [];
const newDecorationsActualIndex: number[] = [];
for (let i = 0, len = reference.children.length; i < len; i++) {
let oneReference = reference.children[i];
if (this._decorationIgnoreSet.has(oneReference.id)) {
continue;
}
newDecorations.push({
range: oneReference.range,
options: DecorationsManager.DecorationOptions
});
newDecorationsActualIndex.push(i);
for (let i = 0, len = reference.children.length; i < len; i++) {
let oneReference = reference.children[i];
if (this._decorationIgnoreSet.has(oneReference.id)) {
continue;
}
newDecorations.push({
range: oneReference.range,
options: DecorationsManager.DecorationOptions
});
newDecorationsActualIndex.push(i);
}
const decorations = accessor.deltaDecorations([], newDecorations);
for (let i = 0; i < decorations.length; i++) {
this._decorations.set(decorations[i], reference.children[newDecorationsActualIndex[i]]);
}
});
const decorations = this._editor.deltaDecorations([], newDecorations);
for (let i = 0; i < decorations.length; i++) {
this._decorations.set(decorations[i], reference.children[newDecorationsActualIndex[i]]);
}
}
private _onDecorationChanged(): void {
......@@ -143,21 +140,19 @@ class DecorationsManager implements IDisposable {
}
});
this._editor.changeDecorations((accessor) => {
for (let i = 0, len = toRemove.length; i < len; i++) {
this._decorations.delete(toRemove[i]);
}
accessor.deltaDecorations(toRemove, []);
});
for (let i = 0, len = toRemove.length; i < len; i++) {
this._decorations.delete(toRemove[i]);
}
this._editor.deltaDecorations(toRemove, []);
}
public removeDecorations(): void {
this._editor.changeDecorations(accessor => {
this._decorations.forEach((value, key) => {
accessor.removeDecoration(key);
});
this._decorations.clear();
let toRemove: string[] = [];
this._decorations.forEach((value, key) => {
toRemove.push(key);
});
this._editor.deltaDecorations(toRemove, []);
this._decorations.clear();
}
}
......
......@@ -50,7 +50,9 @@ export class OneSnippet {
dispose(): void {
if (this._placeholderDecorations) {
this._editor.changeDecorations(accessor => this._placeholderDecorations.forEach(handle => accessor.removeDecoration(handle)));
let toRemove: string[] = [];
this._placeholderDecorations.forEach(handle => toRemove.push(handle));
this._editor.deltaDecorations(toRemove, []);
}
this._placeholderGroups.length = 0;
}
......
......@@ -14,7 +14,7 @@ import { registerEditorContribution, IActionOptions, EditorAction } from 'vs/edi
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { Range } from 'vs/editor/common/core/range';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { IModelDecorationsChangeAccessor, IModelDeltaDecoration } from 'vs/editor/common/model';
import { IModelDeltaDecoration } from 'vs/editor/common/model';
export interface IQuickOpenControllerOpts {
inputAriaLabel: string;
......@@ -100,31 +100,27 @@ export class QuickOpenController implements editorCommon.IEditorContribution, ID
});
public decorateLine(range: Range, editor: ICodeEditor): void {
editor.changeDecorations((changeAccessor: IModelDecorationsChangeAccessor) => {
const oldDecorations: string[] = [];
if (this.rangeHighlightDecorationId) {
oldDecorations.push(this.rangeHighlightDecorationId);
this.rangeHighlightDecorationId = null;
}
const oldDecorations: string[] = [];
if (this.rangeHighlightDecorationId) {
oldDecorations.push(this.rangeHighlightDecorationId);
this.rangeHighlightDecorationId = null;
}
const newDecorations: IModelDeltaDecoration[] = [
{
range: range,
options: QuickOpenController._RANGE_HIGHLIGHT_DECORATION
}
];
const newDecorations: IModelDeltaDecoration[] = [
{
range: range,
options: QuickOpenController._RANGE_HIGHLIGHT_DECORATION
}
];
const decorations = changeAccessor.deltaDecorations(oldDecorations, newDecorations);
this.rangeHighlightDecorationId = decorations[0];
});
const decorations = editor.deltaDecorations(oldDecorations, newDecorations);
this.rangeHighlightDecorationId = decorations[0];
}
public clearDecorations(): void {
if (this.rangeHighlightDecorationId) {
this.editor.changeDecorations((changeAccessor: IModelDecorationsChangeAccessor) => {
changeAccessor.deltaDecorations([this.rangeHighlightDecorationId], []);
this.rangeHighlightDecorationId = null;
});
this.editor.deltaDecorations([this.rangeHighlightDecorationId], []);
this.rangeHighlightDecorationId = null;
}
}
}
......
......@@ -27,6 +27,7 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import { editorHoverBackground, editorHoverBorder } from 'vs/platform/theme/common/colorRegistry';
import { WorkbenchTree, WorkbenchTreeController } from 'vs/platform/list/browser/listService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
const $ = dom.$;
const MAX_ELEMENTS_SHOWN = 18;
......@@ -208,15 +209,17 @@ export class DebugHoverWidget implements IContentWidget {
this.highlightDecorations = this.editor.deltaDecorations(this.highlightDecorations, [{
range: new Range(pos.lineNumber, expressionRange.startColumn, pos.lineNumber, expressionRange.startColumn + matchingExpression.length),
options: {
className: 'hoverHighlight'
}
options: DebugHoverWidget._HOVER_HIGHLIGHT_DECORATION_OPTIONS
}]);
return this.doShow(pos, expression, focus);
});
}
private static _HOVER_HIGHLIGHT_DECORATION_OPTIONS = ModelDecorationOptions.register({
className: 'hoverHighlight'
});
private doFindExpression(container: IExpressionContainer, namesToFind: string[]): TPromise<IExpression> {
if (!container) {
return TPromise.as(null);
......
......@@ -890,13 +890,15 @@ export class FilteredMatchesRenderer extends Disposable implements HiddenAreasPr
private createDecoration(range: IRange, model: ITextModel): IModelDeltaDecoration {
return {
range,
options: {
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
className: 'findMatch'
}
options: FilteredMatchesRenderer._FIND_MATCH
};
}
private static readonly _FIND_MATCH = ModelDecorationOptions.register({
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
className: 'findMatch'
});
private computeHiddenRanges(filteredGroups: ISettingsGroup[], allSettingsGroups: ISettingsGroup[], model: ITextModel): IRange[] {
// Hide the contents of hidden groups
const notMatchesRanges: IRange[] = [];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册