本文整理汇总了TypeScript中vscode.window.createTextEditorDecorationType方法的典型用法代码示例。如果您正苦于以下问题:TypeScript window.createTextEditorDecorationType方法的具体用法?TypeScript window.createTextEditorDecorationType怎么用?TypeScript window.createTextEditorDecorationType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.window
的用法示例。
在下文中一共展示了window.createTextEditorDecorationType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: registerRangeType
export function registerRangeType(ext: ExtensionState) {
const context = ext.context;
let selTimeout: NodeJS.Timer | null = null;
const decoCurrent = vscode.window.createTextEditorDecorationType({
borderStyle: 'solid',
borderColor: '#66f',
borderWidth: '0px 0px 1px 0px'
});
const decoType = vscode.window.createTextEditorDecorationType({
after: {
color: '#999',
margin: '0px 0px 0px 20px'
},
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed
})
context.subscriptions.push(vscode.window.onDidChangeTextEditorSelection((event) => {
const doc = event.textEditor.document;
if (doc.languageId !== 'haskell' && ! doc.uri.fsPath.endsWith('.hs'))
return;
if (doc.isDirty) {
event.textEditor.setDecorations(decoCurrent, []);
event.textEditor.setDecorations(decoType, []);
} else {
if (selTimeout !== null) {
clearTimeout(selTimeout);
}
const sel = event.selections[0];
selTimeout = setTimeout(async () => {
const session = await startSession(ext, doc);
const res = await getType(session, sel, doc);
if (res !== null) {
const [range, type] = res;
const lineRange = doc.lineAt(range.start.line).range;
event.textEditor.setDecorations(decoCurrent, [{
range,
hoverMessage: type
}]);
event.textEditor.setDecorations(decoType, [{
range: lineRange,
renderOptions: {
after: {
contentText: `:: ${type}`
}
}
}]);
} else {
event.textEditor.setDecorations(decoCurrent, []);
event.textEditor.setDecorations(decoType, []);
}
selTimeout = null;
}, 300);
}
}));
}
示例2: loadConfiguration
function loadConfiguration() {
configuration = Object.assign(configuration, vscode.workspace.getConfiguration("incrementalSearch"));
if(selectionDecoratation)
selectionDecoratation.dispose();
selectionDecoratation = null;
selectionDecoratation = vscode.window.createTextEditorDecorationType(configuration.selectionStyle);
if(matchDecoratation != null)
matchDecoratation.dispose();
matchDecoratation = null;
matchDecoratation = vscode.window.createTextEditorDecorationType(configuration.matchStyle);
if(configuration.inputMode == 'input-box')
decorateSelection = true;
// Do not register the 'type' command unless we have to
// (potential performance issues)
// if(configuration.inputMode == 'inline' && registeredTypeCommand==false) {
// registeredTypeCommand = true;
// registerCommand('type', (event: {text:string}) => {
// const search = searches.get(vscode.window.activeTextEditor);
// if(search && configuration.inputMode == 'inline')
// updateSearch(search,{searchTerm: search.searchTerm + event.text});
// else
// vscode.commands.executeCommand('default:type', event);
// });
// }
}
示例3: activate
export function activate(context: vscode.ExtensionContext) {
console.log("Congratulations, your extension 'highlight-trailing-white-spaces' is now active!");
vscode.window.onDidChangeActiveTextEditor(editor => {
if (!editor) {
return;
}
updateDecorations(editor);
}, null, context.subscriptions);
vscode.window.onDidChangeTextEditorSelection(event => {
if (!event.textEditor) {
console.error("onDidChangeTextEditorSelection(" + event + "): no active text editor.");
return;
}
updateDecorations(event.textEditor);
}, null, context.subscriptions);
vscode.workspace.onDidChangeTextDocument(event => {
if (!vscode.window.activeTextEditor) {
console.error("onDidChangeTextDocument(" + event + "): no active text editor.");
return;
}
updateDecorations(vscode.window.activeTextEditor);
}, null, context.subscriptions);
let trailingSpacesDecorationType = vscode.window.createTextEditorDecorationType({
backgroundColor: "rgba(255,0,0,0.3)"
});
function updateDecorations(activeTextEditor: vscode.TextEditor) {
if (!activeTextEditor) {
console.error("updateDecorations(): no active text editor.");
return;
}
const regEx = /\s+$/g;
const doc = activeTextEditor.document;
const decorationOptions: vscode.DecorationOptions[] = [];
for (let i = 0; i < doc.lineCount; i++) {
let lineText = doc.lineAt(i);
let line = lineText.text;
if (i === activeTextEditor.selection.active.line) {
continue;
}
let match;
while (match = regEx.exec(line)) {
let startPos = new vscode.Position(i, match.index);
let endPos = new vscode.Position(i, match.index + match[0].length);
const decoration = { range: new vscode.Range(startPos, endPos), hoverMessage: "Number **" + match[0] + "**"};
decorationOptions.push(decoration);
}
}
activeTextEditor.setDecorations(trailingSpacesDecorationType, decorationOptions);
}
updateDecorations(vscode.window.activeTextEditor);
}
示例4: initialiseSnakeTrail
function initialiseSnakeTrail() {
try {
let snakeOptionsOverrides = vscode.workspace.getConfiguration('snakeTrail');
snakeOptions = _.clone(snakeOptionsOverrides);
opacities = [];
let snakeFade = snakeOptions.fadeStart;
while (snakeFade >= snakeOptions.fadeEnd) {
opacities.push(snakeFade.toString());
snakeFade -= snakeOptions.fadeStep;
snakeFade = dpRounder(snakeFade);
}
opacities.reverse();
// Create the decorators
let newSnakeDecorations = [];
for (let i = 0; i < opacities.length; ++i) {
newSnakeDecorations.push(
vscode.window.createTextEditorDecorationType({
light: {
backgroundColor: 'rgba('+ (snakeOptions.colorLight || snakeOptions.color) + ',' + opacities[i] + ')'
},
dark: {
backgroundColor: 'rgba('+ (snakeOptions.colorDark || snakeOptions.color) + ',' + opacities[i] + ')'
}
})
);
}
snakeDecorations = newSnakeDecorations;
} catch(err) {
console.log(err);
}
}
示例5: makePrettyDecoration_noHide
export function makePrettyDecoration_noHide(prettySubst: Substitution) {
const showAttachmentStyling = '';
let styling : vscode.DecorationRenderOptions = {
after: {},
dark: {after: {}},
light: {after: {}},
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
};
if(prettySubst.style) {
assignStyleProperties(styling.after, prettySubst.style);
if(prettySubst.style.dark)
assignStyleProperties(styling.dark.after, prettySubst.style.dark);
if(prettySubst.style.light)
assignStyleProperties(styling.light.after, prettySubst.style.light);
}
styling.after.contentText = prettySubst.pretty;
// Use a dirty hack to change the font size (code injection)
styling.after.textDecoration = (styling.after.textDecoration || 'none') + showAttachmentStyling;
// and make sure the user's textDecoration does not break our hack
if(styling.light.after.textDecoration)
styling.light.after.textDecoration = styling.light.after.textDecoration + showAttachmentStyling;
if(styling.dark.after.textDecoration)
styling.dark.after.textDecoration = styling.dark.after.textDecoration + showAttachmentStyling;
return vscode.window.createTextEditorDecorationType(styling);
}
示例6: activate
export function activate(context: vscode.ExtensionContext) {
const conf = vscode.workspace.getConfiguration('emptyIndent');
const removeIndent = conf.get<boolean>('removeIndent');
const highlightIndent = conf.get<boolean>('highlightIndent');
const highlightColor = conf.get<string>('highlightColor');
const exclude = conf.get<Array<string>>('exclude');
let activeEditor = vscode.window.activeTextEditor;
if (removeIndent) {
vscode.workspace.onDidSaveTextDocument(event => {
if (checkExclude(event.fileName, exclude)) {
return;
}
vscode.commands.executeCommand('editor.action.trimTrailingWhitespace');
vscode.window.activeTextEditor.document.save();
});
}
if (highlightIndent) {
let decoration = vscode.window.createTextEditorDecorationType({
backgroundColor: highlightColor
});
vscode.window.onDidChangeActiveTextEditor(editor => {
activeEditor = editor;
if (editor && !checkExclude(activeEditor.document.fileName, exclude)) {
updateDecorations(editor, decoration);
}
}, null, context.subscriptions);
vscode.workspace.onDidChangeTextDocument(event => {
if (
activeEditor &&
event.document === activeEditor.document &&
!checkExclude(activeEditor.document.fileName, exclude)
) {
updateDecorations(activeEditor, decoration);
}
}, null, context.subscriptions);
vscode.window.onDidChangeTextEditorSelection(event => {
const line = event.selections.length === 1 ? event.selections[0].active : null;
if (activeEditor && !checkExclude(activeEditor.document.fileName, exclude)) {
updateDecorations(activeEditor, decoration, line);
}
}, null, context.subscriptions);
}
}
示例7: activate
export function activate(context: vscode.ExtensionContext) {
var markbookmarkDecorationType = vscode.window.createTextEditorDecorationType({
gutterIconPath: context.asAbsolutePath("images\\mark.png"),
overviewRulerLane: vscode.OverviewRulerLane.Full,
});
Lines.MarkDecorationType = markbookmarkDecorationType;
let linesRemove = vscode.commands.registerCommand('extension.linesRemove', variable => {
vscode.window.showInputBox({prompt : "Enter search string. Matching lines will be removed."})
.then(pattern => {
Lines.Remove(pattern);
});
});
context.subscriptions.push(linesRemove);
let linesRemoveInverse = vscode.commands.registerCommand('extension.linesRemoveInverse', variable => {
vscode.window.showInputBox({prompt : "Enter search string. Non-matching lines will be removed."})
.then(pattern => {
Lines.RemoveInverse(pattern);
});
});
context.subscriptions.push(linesRemoveInverse);
let linesMark = vscode.commands.registerCommand('extension.linesMark', variable => {
vscode.window.showInputBox({prompt : "Enter search string. Matching lines will be marked."})
.then(pattern => {
Lines.Mark(pattern);
});
});
context.subscriptions.push(linesMark);
let linesClearMarks = vscode.commands.registerCommand('extension.linesClearMarks', variable => {
Lines.ClearMarks();
});
context.subscriptions.push(linesClearMarks);
let linesRemoveMarked = vscode.commands.registerCommand('extension.linesRemoveMarked', variable => {
Lines.RemoveMarked();
});
context.subscriptions.push(linesRemoveMarked);
let linesRemoveUnmarked = vscode.commands.registerCommand('extension.linesRemoveUnmarked', variable => {
Lines.RemoveUnmarked();
});
context.subscriptions.push(linesRemoveUnmarked);
}
示例8: setupDecorators
function setupDecorators(context: ExtensionContext) {
let timeout: NodeJS.Timer | undefined = undefined;
const path = vscode.extensions.getExtension('peterzeller.wurst').extensionPath;
const compiletimeDecorator = vscode.window.createTextEditorDecorationType({
gutterIconPath: `${path}/images/gears.svg`,
gutterIconSize: 'contain',
});
let activeEditor = vscode.window.activeTextEditor;
function updateDecorations() {
if (!activeEditor) {
return;
}
timeout = undefined;
const regEx = /@compiletime\s+(\s*(static|public|private)\s)*function.+/g;
const text = activeEditor.document.getText();
const compiletime: vscode.DecorationOptions[] = [];
let match;
while (match = regEx.exec(text)) {
const startPos = activeEditor.document.positionAt(match.index);
const endPos = activeEditor.document.positionAt(match.index + match[0].length);
const decoration = { range: new vscode.Range(startPos, endPos), hoverMessage: 'This function will be executed at compiletime.' };
compiletime.push(decoration);
}
activeEditor.setDecorations(compiletimeDecorator, compiletime);
}
function triggerUpdateDecorations() {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(updateDecorations, 500);
}
if (activeEditor) {
triggerUpdateDecorations();
}
vscode.window.onDidChangeActiveTextEditor(editor => {
activeEditor = editor;
if (editor) {
triggerUpdateDecorations();
}
}, null, context.subscriptions);
vscode.workspace.onDidChangeTextDocument(event => {
if (activeEditor && event.document === activeEditor.document) {
triggerUpdateDecorations();
}
}, null, context.subscriptions);
}
示例9: makeDecorations_none
export function makeDecorations_none() {
return {
uglyDecoration: vscode.window.createTextEditorDecorationType({
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
}),
revealedUglyDecoration: vscode.window.createTextEditorDecorationType({
textDecoration: 'none; font-size: inherit !important',
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
after: {
textDecoration: 'none; font-size: 0pt',
}
}),
boxedSymbolDecoration: {
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
after: {
border: '0.1em solid',
margin: '-0em -0.05em -0em -0.1em',
}
},
}
}
示例10: makeDecorations_letterSpacing_hack
export function makeDecorations_letterSpacing_hack() {
return {
uglyDecoration: vscode.window.createTextEditorDecorationType({
letterSpacing: "-0.55em; font-size: 0.1em; visibility: hidden",
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
}),
revealedUglyDecoration: vscode.window.createTextEditorDecorationType({
letterSpacing: "normal !important; font-size: inherit !important; visibility: visible !important",
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
after: {
// letterSpacing: '-0.55em; font-size: 0.1pt; visibility: hidden',
textDecoration: 'none !important; font-size: 0.1pt !important; visibility: hidden',
}
}),
boxedSymbolDecoration: {
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
after: {
border: '0.1em solid',
margin: '-0em -0.05em -0em -0.1em',
}
},
}
}