当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript TextEdit.delete方法代码示例

本文整理汇总了TypeScript中vscode.TextEdit.delete方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextEdit.delete方法的具体用法?TypeScript TextEdit.delete怎么用?TypeScript TextEdit.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vscode.TextEdit的用法示例。


在下文中一共展示了TextEdit.delete方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: provideEdits

    provideEdits(document: TextDocument, position: Position, ch: string, options: FormattingOptions, line: TextLine): TextEdit[] {
        // We can have else for the following blocks:
        // if:
        // elif x:
        // for x in y:
        // while x:

        // We need to find a block statement that is less than or equal to this statement block (but not greater)
        for (let lineNumber = position.line - 1; lineNumber >= 0; lineNumber--) {
            const prevLine = document.lineAt(lineNumber);
            const prevLineText = prevLine.text;

            // Oops, we've reached a boundary (like the function or class definition)
            // Get out of here
            if (this.boundaryRegExps.some(value => value.test(prevLineText))) {
                return [];
            }

            const blockRegEx = this.previousBlockRegExps.find(value => value.test(prevLineText));
            if (!blockRegEx) {
                continue;
            }

            const startOfBlockInLine = prevLine.firstNonWhitespaceCharacterIndex;
            if (startOfBlockInLine > line.firstNonWhitespaceCharacterIndex) {
                continue;
            }

            const startPosition = new Position(position.line, 0);
            const endPosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex - startOfBlockInLine);

            if (startPosition.isEqual(endPosition)) {
                // current block cannot be at the same level as a preivous block
                continue;
            }
            if (options.insertSpaces) {
                return [
                    TextEdit.delete(new Range(startPosition, endPosition))
                ];
            }
            else {
                // Delete everything before the block and insert the same characters we have in the previous block
                const prefixOfPreviousBlock = prevLineText.substring(0, startOfBlockInLine);

                const startDeletePosition = new Position(position.line, 0);
                const endDeletePosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex);

                return [
                    TextEdit.delete(new Range(startDeletePosition, endDeletePosition)),
                    TextEdit.insert(startDeletePosition, prefixOfPreviousBlock)
                ];
            }
        }

        return [];
    }
开发者ID:walkoncross,项目名称:pythonVSCode,代码行数:56,代码来源:codeBlockFormatProvider.ts

示例2: getEditsForDeletingTralingSpaces

 /**
  * Returns the edits required to delete the trailings spaces from a document
  *
  * @param {vscode.TextDocument} document The document in which the trailing spaces should be found
  * @returns {vscode.TextEdit[]} An array of edits required to delete the trailings spaces from the document
  */
 public getEditsForDeletingTralingSpaces(document: vscode.TextDocument): vscode.TextEdit[] {
     let ranges: vscode.Range[] = this.getRangesToDelete(document);
     let edits: vscode.TextEdit[] = new Array<vscode.TextEdit>(ranges.length);
     for (let i: number = ranges.length - 1; i >= 0; i--) {
         edits[ranges.length - 1 - i] = vscode.TextEdit.delete(ranges[i]);
     }
     this.showStatusBarMessage(document, ranges.length);
     return edits;
 }
开发者ID:shardulm94,项目名称:vscode-trailingspaces,代码行数:15,代码来源:trailing-spaces.ts

示例3: apply

	apply(): TextEdit {
		switch (this.action) {
			case EditTypes.EDIT_INSERT:
				return TextEdit.insert(this.start, this.text);
			case EditTypes.EDIT_DELETE:
				return TextEdit.delete(new Range(this.start, this.end));
			case EditTypes.EDIT_REPLACE:
				return TextEdit.replace(new Range(this.start, this.end), this.text);
		}
	}
开发者ID:oliverkofoed,项目名称:vscode-go,代码行数:10,代码来源:util.ts

示例4:

					return this.sessionStore.activityTypes.map(activity => {
						const item = new vsc.CompletionItem(activity, vsc.CompletionItemKind.TypeParameter);
						item.insertText = `${activity}:`;

						if (word.endsWith(':')) {
							const currentLine = document.lineAt(position.line);

							item.additionalTextEdits = [
								vsc.TextEdit.delete(new vsc.Range(position, position.with(undefined, currentLine.text.length)))
							];
						}

						return item;
					});
开发者ID:ipatalas,项目名称:vscode-sprint-planner,代码行数:14,代码来源:activityCompletionProvider.ts

示例5: trimLineTrailingWhitespace

function trimLineTrailingWhitespace(line: TextLine) {
	const trimmedLine = trimTrailingWhitespace(line.text);

	if (trimmedLine === line.text) {
		return;
	}

	const whitespaceBegin = new Position(
		line.lineNumber,
		trimmedLine.length
	);
	const whitespaceEnd = new Position(
		line.lineNumber,
		line.text.length
	);
	const whitespace = new Range(
		whitespaceBegin,
		whitespaceEnd
	);

	return TextEdit.delete(whitespace);
}
开发者ID:rlugojr,项目名称:editorconfig-vscode,代码行数:22,代码来源:trimTrailingWhitespace.ts

示例6: suite

suite('Else blocks with indentation of Tab', () => {
    suiteSetup(async () => {
        await initialize();
        fs.ensureDirSync(path.dirname(outPythoFilesPath));

        ['elseBlocksTab.py'].forEach(file => {
            const targetFile = path.join(outPythoFilesPath, file);
            if (fs.existsSync(targetFile)) { fs.unlinkSync(targetFile); }
            fs.copySync(path.join(srcPythoFilesPath, file), targetFile);
        });
    });
    suiteTeardown(() => closeActiveWindows());
    teardown(() => closeActiveWindows());

    interface TestCase {
        title: string;
        line: number;
        column: number;
        expectedEdits: vscode.TextEdit[];
    }
    const testCases: TestCase[] = [
        {
            title: 'elif off by tab',
            line: 4, column: 18,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(4, 0, 4, 1))
            ]
        },
        {
            title: 'elif off by tab',
            line: 7, column: 18,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(7, 0, 7, 1))
            ]
        },
        {
            title: 'elif off by tab again',
            line: 21, column: 18,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(21, 0, 21, 1))
            ]
        },
        {
            title: 'else off by tab',
            line: 38, column: 7,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(38, 0, 38, 1))
            ]
        },
        {
            title: 'else: off by tab inside a for loop',
            line: 47, column: 13,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(47, 0, 47, 1))
            ]
        },
        {
            title: 'else: off by tab inside a try',
            line: 57, column: 9,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(57, 0, 57, 1))
            ]
        },
        {
            title: 'elif off by a tab inside a function',
            line: 66, column: 20,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(66, 0, 66, 1))
            ]
        },
        {
            title: 'elif off by a tab inside a function should not format',
            line: 69, column: 20,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(69, 0, 69, 1))
            ]
        },
        {
            title: 'elif off by a tab inside a function',
            line: 83, column: 20,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(83, 0, 83, 1))
            ]
        },
        {
            title: 'else: off by tab inside if of a for and for in a function',
            line: 109, column: 15,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(109, 0, 109, 1))
            ]
        },
        {
            title: 'else: off by tab inside try in a function',
            line: 119, column: 11,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(119, 0, 119, 1))
            ]
        },
        {
            title: 'else: off by tab inside while in a function',
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例7: suite

suite('Try blocks with indentation of 4 spaces', () => {
    suiteSetup(done => {
        initialize().then(() => {
            pythonSettings.pythonPath = PYTHON_PATH;
            fs.ensureDirSync(path.dirname(outPythoFilesPath));

            ['tryBlocks4.py'].forEach(file => {
                const targetFile = path.join(outPythoFilesPath, file);
                if (fs.existsSync(targetFile)) { fs.unlinkSync(targetFile); }
                fs.copySync(path.join(srcPythoFilesPath, file), targetFile);
            });
        }).then(done).catch(done);
    });
    suiteTeardown(done => {
        closeActiveWindows().then(done, done);
    });
    teardown(done => {
        closeActiveWindows().then(done, done);
    });

    interface TestCase {
        title: string;
        line: number;
        column: number;
        expectedEdits: vscode.TextEdit[];
    }
    const testCases: TestCase[] = [
        {
            title: 'except off by tab',
            line: 6, column: 22,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(6, 0, 6, 4))
            ]
        },
        {
            title: 'except off by one should not be formatted',
            line: 15, column: 21,
            expectedEdits: []
        },
        {
            title: 'except off by tab inside a for loop',
            line: 35, column: 13,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(35, 0, 35, 4))
            ]
        },
        {
            title: 'except off by one inside a for loop should not be formatted',
            line: 47, column: 12,
            expectedEdits: [
            ]
        },
        {
            title: 'except IOError: off by tab inside a for loop',
            line: 54, column: 19,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(54, 0, 54, 4))
            ]
        },
        {
            title: 'else: off by tab inside a for loop',
            line: 76, column: 9,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(76, 0, 76, 4))
            ]
        },
        {
            title: 'except ValueError:: off by tab inside a function',
            line: 143, column: 22,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(143, 0, 143, 4))
            ]
        },
        {
            title: 'except ValueError as err: off by one inside a function should not be formatted',
            line: 157, column: 25,
            expectedEdits: [
            ]
        },
        {
            title: 'else: off by tab inside function',
            line: 172, column: 11,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(172, 0, 172, 4))
            ]
        },
        {
            title: 'finally: off by tab inside function',
            line: 195, column: 12,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(195, 0, 195, 4))
            ]
        }
    ];

    const formatOptions: vscode.FormattingOptions = {
        insertSpaces: true, tabSize: 4
    };

    testCases.forEach((testCase, index) => {
//.........这里部分代码省略.........
开发者ID:walkoncross,项目名称:pythonVSCode,代码行数:101,代码来源:extension.onTypeFormat.test.ts


注:本文中的vscode.TextEdit.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。